1<?php 2 3/** 4 * Mediasyntax Plugin, preformatted block component: Mediawiki style preformatted text 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Esther Brunner <wikidesign@gmail.com> 8 */ 9class syntax_plugin_mediasyntax_codeblock extends DokuWiki_Syntax_Plugin 10{ 11 12 function getType() 13 { 14 return 'formatting'; 15 } 16 17 function getSort() 18 { 19 /* 20 This must be higher prioritized than e.g. listblock. 21 If it is not, then the listblock will "steal" the \n at its end-of-line. 22 Then, a codeblock directly under a listblock will not trigger the \n .* regex. 23 */ 24 return 9; 25 } 26 27 function connectTo($mode) 28 { 29 $this->Lexer->addEntryPattern( 30 '\n(?= .*?)', 31 $mode, 32 'plugin_mediasyntax_codeblock' 33 ); 34 } 35 36 function postConnect() 37 { 38 $this->Lexer->addExitPattern( 39 '(?=\n[^ ].*?)', 40 'plugin_mediasyntax_codeblock' 41 ); 42 } 43 44 function handle($match, $state, $pos, Doku_Handler $handler) 45 { 46 // $match2 = $match, but cut one blank at the beginning of every line. 47 $match2 = ""; 48 for ($i = 1; $i < strlen($match); $i++) { 49 if ($match[$i - 1] == "\n" && $match[$i] == " ") {; 50 } else $match2 .= $match[$i]; 51 } 52 switch ($state) { 53 case DOKU_LEXER_ENTER: 54 return false; 55 case DOKU_LEXER_MATCHED: 56 return array($state, $match2); 57 case DOKU_LEXER_UNMATCHED: 58 return array($state, $match2); 59 case DOKU_LEXER_EXIT: 60 return array($state, $match2); 61 case DOKU_LEXER_SPECIAL: 62 //break; 63 } 64 return false; 65 /* if ($state == DOKU_LEXER_UNMATCHED) 66 { 67 return array($state, $match2); 68 } 69 return false; 70*/ 71 } 72 73 function render($mode, Doku_Renderer $renderer, $data) 74 { 75 if ($mode == 'xhtml') { 76 list($state, $match) = $data; 77 $match = $data[1]; 78 $state = $data[0]; 79 switch ($state) { 80 case DOKU_LEXER_ENTER: 81 //$renderer->doc .= "enter$match"; 82 case DOKU_LEXER_UNMATCHED: 83 //$renderer->doc .= "<pre>$match</pre>"; 84 case DOKU_LEXER_EXIT: 85 if ($match != "") $renderer->doc .= "<pre>$match</pre>"; 86 } 87 } 88 return true; 89 } 90} 91 92//Setup VIM: ex: et ts=4 enc=utf-8 : 93