1<?php 2/** 3 * wpre Plugin: for output using word wrapped preformatted text 4 * Syntax: <wpre> text </wpre> 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Max Binshtok (max.binshtok@gmail.com) 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_wpre extends DokuWiki_Syntax_Plugin { 19 20 /** 21 * return some info 22 */ 23 function getInfo(){ 24 return array( 25 'author' => 'Max Binshtok', 26 'email' => 'max.binshtok@gmail.com', 27 'date' => '2010-02-12', 28 'name' => 'wpre Plugin', 29 'desc' => 'for output using word wrapped preformatted text', 30 'url' => 'http://www.dokuwiki.org/plugin:wpre', 31 ); 32 } 33 34 /** 35 * What kind of syntax are we? 36 */ 37 function getType(){ 38 return 'formatting'; 39 } 40 41 42 /** 43 * What about paragraphs? (optional) 44 */ 45 function getPType(){ 46 return 'normal'; 47 } 48 49 /** 50 * Where to sort in? 51 */ 52 function getSort(){ 53 return 195; 54 } 55 56 57 /** 58 * Connect pattern to lexer 59 */ 60 function connectTo($mode) { 61 $this->Lexer->addEntryPattern('\x3Cwpre\x3E(?=.*\x3C/wpre\x3E)',$mode,'plugin_wpre'); 62/* $this->Lexer->addEntryPattern('(?i)<wpre(?: .+?)?>(?=.+</wpre>)',$mode,'plugin_wpre'); */ 63 } 64 65 function postConnect() { 66 $this->Lexer->addExitPattern('\x3C/wpre\x3E', 'plugin_wpre'); 67/* $this->Lexer->addExitPattern('(?i)</wpre>','plugin_wpre'); */ 68 } 69 70 71 /** 72 * Handle the match 73 */ 74 function handle($match, $state, $pos, &$handler){ 75 switch ($state) { 76 case DOKU_LEXER_ENTER : 77 break; 78 case DOKU_LEXER_MATCHED : 79 break; 80 case DOKU_LEXER_UNMATCHED : 81 break; 82 case DOKU_LEXER_EXIT : 83 break; 84 case DOKU_LEXER_SPECIAL : 85 break; 86 } 87 return array($match, $state); 88 } 89 90 /** 91 * Create output 92 */ 93 function render($mode, &$renderer, $data) { 94 if($mode == 'xhtml'){ 95 if ($data[1] == DOKU_LEXER_ENTER){ 96 $renderer->doc .= '<pre class="wpre">'; # <pre><font size=+0>'; 97 } else if ($data[1] == DOKU_LEXER_UNMATCHED){ 98 $renderer->doc .= $renderer->_xmlEntities($data[0]); 99 } else if ($data[1] == DOKU_LEXER_EXIT){ 100 $renderer->doc .= '</pre>'; # '</font></pre>'; 101 } 102 return true; 103 } 104 return false; 105 } 106} 107 108//Setup VIM: ex: et ts=4 enc=utf-8 : 109 110?>