1<?php 2/** 3 * Creole Plugin, listblock component: Creole style ordered and unordered lists 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\Lists; 10 11/** 12 * All DokuWiki plugins to extend the parser/rendering mechanism 13 * need to inherit from this class 14 */ 15class syntax_plugin_creole_listblock extends DokuWiki_Syntax_Plugin { 16 var $eventhandler = NULL; 17 18 function getType() { return 'container'; } 19 function getPType() { return 'block'; } 20 function getSort() { return 9; } 21 22 function getAllowedTypes() { 23 return array('formatting', 'substition', 'disabled', 'protected'); 24 } 25 26 function connectTo($mode) { 27 $this->Lexer->addEntryPattern( 28 '\n[ \t]*[\#\*](?!\*)', 29 $mode, 30 'plugin_creole_listblock' 31 ); 32 $this->Lexer->addPattern( 33 '\n[ \t]*[\#\*\-]+', 34 'plugin_creole_listblock' 35 ); 36 } 37 38 function postConnect() { 39 $this->Lexer->addExitPattern( 40 '\n', 41 'plugin_creole_listblock' 42 ); 43 } 44 45 /** 46 * Constructor. 47 */ 48 public function __construct() { 49 $this->eventhandler = plugin_load('helper', 'creole_eventhandler'); 50 } 51 52 function handle($match, $state, $pos, Doku_Handler $handler) { 53 switch ($state) { 54 case DOKU_LEXER_ENTER: 55 $this->eventhandler->notifyEvent('open', 'list', NULL, $pos, $match, $handler); 56 $ReWriter = new Doku_Handler_Creole_List($handler->getCallWriter()); 57 $handler->setCallWriter($ReWriter); 58 $handler->addCall('list_open', array($match), $pos); 59 break; 60 case DOKU_LEXER_EXIT: 61 $this->eventhandler->notifyEvent('close', 'list', NULL, $pos, $match, $handler); 62 $handler->addCall('list_close', array(), $pos); 63 $ReWriter = $handler->getCallWriter(); 64 $ReWriter->process(); 65 $handler->setCallWriter($ReWriter->getCallWriter()); 66 break; 67 case DOKU_LEXER_MATCHED: 68 $handler->addCall('list_item', array($match), $pos); 69 break; 70 case DOKU_LEXER_UNMATCHED: 71 $handler->addCall('cdata', array($match), $pos); 72 break; 73 } 74 return true; 75 } 76 77 function render($mode, Doku_Renderer $renderer, $data) { 78 return true; 79 } 80} 81 82/* ----- Creole List Call Writer ----- */ 83 84class Doku_Handler_Creole_List extends Lists { 85 86 function interpretSyntax($match, &$type) { 87 if (substr($match,-1) == '*') $type = 'u'; 88 else $type = 'o'; 89 $level = strlen(trim($match)); // Creole 90 if ($level <= 1) { 91 $c = count(explode(' ',str_replace("\t",' ',$match))); 92 if ($c > $level) $level = $c; // DokuWiki 93 } 94 return $level; 95 } 96} 97// vim:ts=4:sw=4:et:enc=utf-8: 98