1<?php 2/** 3 * prespan Plugin: for output of text spans with preserved spaces 4 * Syntax: <prespan>text</prespan> or ![text]! 5 * 6 * @author LarsDW223 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 */ 9 10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(DOKU_PLUGIN.'syntax.php'); 13 14/** 15 * All DokuWiki plugins to extend the parser/rendering mechanism 16 * need to inherit from this class 17 */ 18class syntax_plugin_prespan extends DokuWiki_Syntax_Plugin { 19 20 /** 21 * What kind of syntax are we? 22 */ 23 function getType(){ 24 return 'formatting'; 25 } 26 27 /** 28 * What about paragraphs? (optional) 29 */ 30 function getPType(){ 31 return 'normal'; 32 } 33 34 /** 35 * Where to sort in? 36 */ 37 function getSort(){ 38 return 195; 39 } 40 41 /** 42 * Return allowed nested types. 43 */ 44 function getAllowedTypes(){ 45 return array('formatting', 'substition', 'disabled'); 46 } 47 48 /** 49 * Connect pattern to lexer 50 */ 51 function connectTo($mode) { 52 $this->Lexer->addEntryPattern('<prespan>(?=.*</prespan>)', $mode, 'plugin_prespan'); 53 $this->Lexer->addEntryPattern('\!\[(?=.*\]\!)', $mode, 'plugin_prespan'); 54 } 55 56 function postConnect() { 57 $this->Lexer->addExitPattern('</prespan>', 'plugin_prespan'); 58 $this->Lexer->addExitPattern('\]\!', 'plugin_prespan'); 59 } 60 61 /** 62 * Handle the match 63 */ 64 function handle($match, $state, $pos, Doku_Handler $handler) { 65 switch ($state) { 66 case DOKU_LEXER_ENTER : 67 break; 68 case DOKU_LEXER_MATCHED : 69 break; 70 case DOKU_LEXER_UNMATCHED : 71 break; 72 case DOKU_LEXER_EXIT : 73 break; 74 case DOKU_LEXER_SPECIAL : 75 break; 76 } 77 return array($match, $state); 78 } 79 80 /** 81 * Create output 82 */ 83 function render($mode, Doku_Renderer $renderer, $data) { 84 if($mode == 'xhtml'){ 85 if ($data[1] == DOKU_LEXER_ENTER){ 86 $renderer->doc .= '<span class="prespan">'; 87 } else if ($data[1] == DOKU_LEXER_UNMATCHED){ 88 $renderer->doc .= $renderer->_xmlEntities($data[0]); 89 } else if ($data[1] == DOKU_LEXER_EXIT){ 90 $renderer->doc .= '</span>'; 91 } 92 return true; 93 } 94 return false; 95 } 96} 97 98//Setup VIM: ex: et ts=4 enc=utf-8 : 99