1<?php 2/** 3 * Multiline List Plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Adrian Sai-wah Tam <adrian.sw.tam@gmail.com> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13require_once(DOKU_PLUGIN.'syntax.php'); 14 15use dokuwiki\Parsing\Handler\Lists; 16 17/** 18 * All DokuWiki plugins to extend the parser/rendering mechanism 19 * need to inherit from this class 20 */ 21class syntax_plugin_mllist extends DokuWiki_Syntax_Plugin { 22 23 function getInfo(){ 24 return array( 25 'author' => 'Adrian Sai-wah Tam', 26 'email' => 'adrian.sw.tam@gmail.com', 27 'date' => '2007-06-06', 28 'name' => 'Multiline list plugin', 29 'desc' => 'Allows a list item to break into multiple lines with indentation on non-bullet lines', 30 'url' => 'http://aipl.ie.cuhk.edu.hk/~adrian/doku.php/software/mllist' 31 ); 32 } 33 34 function getType(){ return 'container'; } 35 function getPType(){ return 'block'; } 36 function getSort(){ return 9; } 37 38 function getAllowedTypes(){ 39 return array('formatting', 'substition', 'disabled', 'protected'); 40 } 41 42 function connectTo($mode){ 43 $this->Lexer->addEntryPattern('\n {2,}[\-\*]',$mode,'plugin_mllist'); 44 $this->Lexer->addEntryPattern('\n\t{1,}[\-\*]',$mode,'plugin_mllist'); 45 $this->Lexer->addPattern('\n {2,}[\-\*]','plugin_mllist'); 46 $this->Lexer->addPattern('\n\t{1,}[\-\*]','plugin_mllist'); 47 // Continuation lines need at least three spaces for indentation 48 $this->Lexer->addPattern('\n {2,}(?=\s)','plugin_mllist'); 49 $this->Lexer->addPattern('\n\t{1,}(?=\s)','plugin_mllist'); 50 } 51 52 function postConnect(){ 53 $this->Lexer->addExitPattern('\n','plugin_mllist'); 54 } 55 56 function handle($match, $state, $pos, $handler){ 57 switch ($state){ 58 case DOKU_LEXER_ENTER: 59 $ReWriter = new Lists($handler->getCallWriter()); 60 $handler->setCallWriter($ReWriter); 61 $handler->_addCall('list_open', array($match), $pos); 62 break; 63 case DOKU_LEXER_EXIT: 64 $handler->_addCall('list_close', array(), $pos); 65 $handler->getCallWriter()->process(); 66 $ReWriter = & $handler->getCallWriter(); 67 $handler->setCallWriter($ReWriter->getCallWriter()); 68 break; 69 case DOKU_LEXER_MATCHED: 70 if (preg_match("/^\s+$/",$match)) break; 71 // Captures the continuation case 72 $handler->_addCall('list_item', array($match), $pos); 73 break; 74 case DOKU_LEXER_UNMATCHED: 75 $handler->_addCall('cdata', array($match), $pos); 76 break; 77 } 78 return true; 79 } 80 81 function render($mode, $renderer, $data){ 82 return true; 83 } 84} 85