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