1<?php 2/** 3 * Creole Plugin, preformatted block component: Creole style preformatted text 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Esther Brunner <wikidesign@gmail.com> 7 */ 8 9use dokuwiki\Parsing\Handler\Table; 10 11/** 12 * All DokuWiki plugins to extend the parser/rendering mechanism 13 * need to inherit from this class 14 */ 15class syntax_plugin_creole_table extends DokuWiki_Syntax_Plugin { 16 17 function getType() { return 'container'; } 18 function getSort() { return 59; } 19 20 function getAllowedTypes(){ 21 return array('formatting', 'substition', 'disabled', 'protected'); 22 } 23 24 function connectTo($mode) { 25 $this->Lexer->addEntryPattern('\n\|=',$mode,'plugin_creole_table'); 26 $this->Lexer->addEntryPattern('\n\|',$mode,'plugin_creole_table'); 27 } 28 29 function postConnect() { 30 $this->Lexer->addPattern('\n\|=','plugin_creole_table'); 31 $this->Lexer->addPattern('\n\|','plugin_creole_table'); 32 $this->Lexer->addPattern('[\t ]+','plugin_creole_table'); 33 $this->Lexer->addPattern('\|=','plugin_creole_table'); 34 $this->Lexer->addPattern('\|','plugin_creole_table'); 35 $this->Lexer->addExitPattern('\n','plugin_creole_table'); 36 } 37 38 /** 39 * Constructor. 40 */ 41 public function __construct() { 42 $this->eventhandler = plugin_load('helper', 'creole_eventhandler'); 43 } 44 45 function handle($match, $state, $pos, Doku_Handler $handler) { 46 switch ( $state ) { 47 case DOKU_LEXER_ENTER: 48 $this->eventhandler->notifyEvent('open', 'table', NULL, $pos, $match, $handler); 49 $ReWriter = new Table($handler->getCallWriter()); 50 $handler->setCallWriter($ReWriter); 51 52 $handler->addCall('table_start', array(), $pos); 53 if ( trim($match) == '|=' ) { 54 $handler->addCall('tableheader', array(), $pos); 55 } else { 56 $handler->addCall('tablecell', array(), $pos); 57 } 58 break; 59 60 case DOKU_LEXER_EXIT: 61 $this->eventhandler->notifyEvent('close', 'table', NULL, $pos, $match, $handler); 62 $handler->addCall('table_end', array(), $pos); 63 $handler->getCallWriter()->process(); 64 $ReWriter = $handler->getCallWriter(); 65 $handler->setCallWriter($ReWriter->getCallWriter()); 66 break; 67 68 case DOKU_LEXER_UNMATCHED: 69 if ( trim($match) != '' ) { 70 $handler->addCall('cdata',array($match), $pos); 71 } 72 break; 73 74 case DOKU_LEXER_MATCHED: 75 if ( $match == ' ' ){ 76 $handler->addCall('cdata', array($match), $pos); 77 } else if ( preg_match('/\t+/',$match) ) { 78 $handler->addCall('table_align', array($match), $pos); 79 } else if ( preg_match('/ {2,}/',$match) ) { 80 $handler->addCall('table_align', array($match), $pos); 81 } else if ( $match == "\n|" ) { 82 $handler->addCall('table_row', array(), $pos); 83 $handler->addCall('tablecell', array(), $pos); 84 } else if ( $match == "\n|=" ) { 85 $handler->addCall('table_row', array(), $pos); 86 $handler->addCall('tableheader', array(), $pos); 87 } else if ( $match == '|' ) { 88 $handler->addCall('tablecell', array(), $pos); 89 } else if ( $match == '|=' ) { 90 $handler->addCall('tableheader', array(), $pos); 91 } 92 break; 93 } 94 return true; 95 } 96 97 function render($mode, Doku_Renderer $renderer, $data){ 98 return true; 99 } 100} 101