1<?php 2// must be run within Dokuwiki 3if(!defined('DOKU_INC')) die(); 4if (!defined('DOKU_LF')) define('DOKU_LF',"\n"); 5 6/** Additional Formatting modes. 7 8 This plugin adds more formatting options, covering most of the inline 9 styles of XHTML. A simpler syntax is also available for some of the 10 existing styles. 11 12 Syntax: 13 /+Insert+/ 14 /-Delete-/ 15 <ins desc =cite @date> 16 <del desc =cite @date> 17 /,Subscript,/ 18 /^Superscript^/ 19 ``Keyboard`` 20 ??Variable?? 21 @@Definition@@ 22 !!SmallCaps!! 23 &&Cite&& 24 ""=cite|Quotation"" 25 <quote cite>Blockquote</quote> 26 /!Inverse!/ 27 28 License: GPL 29 */ 30class FormattingPlus_Syntax_Plugin extends DokuWiki_Syntax_Plugin { 31 32 var $formatting = array(); 33 var $pattern = ''; 34 35 function _getName() { 36 return ""; 37 } 38 function _getDesc() { 39 return ""; 40 } 41 function _getConfig() { 42 return ""; 43 } 44 45 /** 46 * Generic Formatting Description 47 * 48 * This method returns an array with formatting information. 49 * 50 * 'open' - Text that begins the formatting. 51 * 'close' - Text that ends the formatting. 52 * 'tag' - Name of the XHTML tag to render. 53 * 'attrs' - Optional attribute string that will be added to the start tag. 54 */ 55 function _getFormatting() { 56 return array(); 57 } 58 59 function _disabledSyntax($type) { 60 static $disabled = null; 61 if (is_null($disabled)) { 62 $disabled = explode(',',$this->getConf('disable_syntax')); 63 $disabled = array_map('trim',$disabled); 64 } 65 if (in_array('all', $disabled)) return true; 66 return in_array($type, $disabled); 67 } 68 69 function getType() { 70 return 'formatting'; 71 } 72 73 function getAllowedTypes() { 74 return array('formatting','substition','disabled'); 75 } 76 77 function preConnect() { 78 if (!empty($this->formatting)) return; 79 80 if ($this->_disabledSyntax($this->_getConfig())) return; 81 82 $this->formatting = $this->_getFormatting(); 83 if (!empty($this->formatting)) { 84 $this->pattern = $this->formatting['open'] . '(?=.*' . $this->formatting['close'] . ')'; 85 } 86 } 87 88 function connectTo($mode) { 89 if (!empty($this->pattern)) 90 $this->Lexer->addEntryPattern($this->pattern, $mode, 'plugin_formatplus_'.$this->getPluginComponent()); 91 } 92 93 function postConnect() { 94 if (!empty($this->pattern)) 95 $this->Lexer->addExitPattern($this->formatting['close'], 'plugin_formatplus_'.$this->getPluginComponent()); 96 } 97 98 function handle($match, $state, $pos, &$handler){ 99 $formatting = $this->_getFormatting(); 100 if (empty($formatting)) return array(DOKU_LEXER_UNMATCHED,$match); 101 if ($state != DOKU_LEXER_UNMATCHED) { 102 $output = $formatting['tag']; 103 if ($state == DOKU_LEXER_ENTER && isset($formatting['attrs'])) 104 $output .= ' '.$formatting['attrs']; 105 } 106 else 107 $output = $match; 108 return array($state,$output); 109 } 110 111 function render($format, &$renderer, $data) { 112 list($state,$output) = $data; 113 if ($format == 'xhtml'){ 114 switch ($state) { 115 case DOKU_LEXER_ENTER: 116 $renderer->doc .= "<$output>"; 117 break; 118 case DOKU_LEXER_EXIT: 119 $renderer->doc .= "</$output>"; 120 break; 121 case DOKU_LEXER_UNMATCHED: 122 $renderer->doc .= $renderer->_xmlEntities($output); 123 break; 124 } 125 return true; 126 } elseif ($format == 'metadata') { 127 if ($renderer->capture) { 128 if ($state == DOKU_LEXER_UNMATCHED) 129 $renderer->doc .= $output; 130 if (strlen($renderer->doc) > 250) 131 $renderer->capture = false; 132 } 133 return true; 134 } 135 return false; 136 } 137} 138