1<?php 2/** 3 * Creole Plugin, monospace component: Creole style monospaced text 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author LarsDW223 7 */ 8 9/** 10 * All DokuWiki plugins to extend the parser/rendering mechanism 11 * need to inherit from this class 12 */ 13class syntax_plugin_creole_monospace extends DokuWiki_Syntax_Plugin { 14 var $eventhandler = NULL; 15 16 function getType() { return 'protected'; } 17 function getSort() { return 102; } 18 19 function connectTo($mode) { 20 $this->Lexer->addSpecialPattern( 21 '##', 22 $mode, 23 'plugin_creole_monospace' 24 ); 25 } 26 27 /** 28 * Constructor. 29 */ 30 public function __construct() { 31 $this->eventhandler = plugin_load('helper', 'creole_eventhandler'); 32 $this->eventhandler->addOnNotify('insert', 'header', 'header', 33 'open', 'monospace', NULL, 34 array($this, 'onHeaderCallback')); 35 $this->eventhandler->addOnNotify('found', 'emptyline', NULL, 36 'open', 'monospace', NULL, 37 array($this, 'onHeaderCallback')); 38 $this->eventhandler->addOnNotify('open', 'list', NULL, 39 'open', 'monospace', NULL, 40 array($this, 'onHeaderCallback')); 41 $this->eventhandler->addOnNotify('open', 'table', NULL, 42 'open', 'monospace', NULL, 43 array($this, 'onHeaderCallback')); 44 } 45 46 function handle($match, $state, $pos, Doku_Handler $handler) { 47 global $conf; 48 49 if ( $this->eventhandler->queuedEventExists ('open', 'monospace', NULL) == false ) { 50 $state = DOKU_LEXER_ENTER; 51 } else { 52 $state = DOKU_LEXER_EXIT; 53 } 54 55 switch ($state) { 56 case DOKU_LEXER_ENTER: 57 if ( $this->getConf('monospace') == 'DokuWiki' ) { 58 $this->eventhandler->notifyEvent('open', 'monospace', 'dw-monospace', $pos, $match, $handler); 59 $handler->addCall('monospace_open', array(), $pos); 60 } else { 61 $this->eventhandler->notifyEvent('open', 'monospace', 'creole-monospace', $pos, $match, $handler); 62 return array($state); 63 } 64 break; 65 case DOKU_LEXER_UNMATCHED: 66 $handler->addCall('cdata', array($match), $pos); 67 break; 68 case DOKU_LEXER_EXIT: 69 if ( $this->getConf('monospace') == 'DokuWiki' ) { 70 $this->eventhandler->notifyEvent('close', 'monospace', 'dw-monospace', $pos, $match, $handler); 71 $handler->addCall('monospace_close', array(), $pos); 72 } else { 73 $this->eventhandler->notifyEvent('close', 'monospace', 'creole-monospace', $pos, $match, $handler); 74 return array($state); 75 } 76 break; 77 } 78 return true; 79 } 80 81 function render($mode, Doku_Renderer $renderer, $data) { 82 list($state) = $data; 83 switch ($state) { 84 case DOKU_LEXER_ENTER : 85 $renderer->doc .= '<tt>'; 86 break; 87 case DOKU_LEXER_EXIT : 88 $renderer->doc .= '</tt>'; 89 break; 90 } 91 return true; 92 } 93 94 public function onHeaderCallback (creole_syntax_event $myEvent, $pos, $match, $handler) { 95 $this->eventhandler->notifyEvent('close', 'monospace', 'dw-monospace', $pos, $match, $handler); 96 switch ($myEvent->getTag() == 'dw-monospace') { 97 case 'dw-monospace': 98 $handler->addCall('monospace_close', array(), $pos); 99 break; 100 case 'creole-monospace': 101 $this->eventhandler->writeCall('creole_monospace', DOKU_LEXER_EXIT, NULL, NULL, $pos, $match, $handler); 102 break; 103 } 104 } 105} 106// vim:ts=4:sw=4:et:enc=utf-8: 107