-
Notifications
You must be signed in to change notification settings - Fork 4
/
syntax.php
61 lines (57 loc) · 1.66 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
<?php
/**
* flowchartjs plugin: draw flowcart based on flowcart.js
*
* Syntax: <flowchartjs style>...</flowchartjs> - will draw a flowchart
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Hua Gao <[email protected]>
*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_flowchartjs extends DokuWiki_Syntax_Plugin {
function getType(){ return 'protected'; }
function getPType(){ return 'block'; }
function getSort(){ return 999; }
function connectTo($mode) {
$this->Lexer->addEntryPattern('<flowchartjs.*?>(?=.*?</flowchartjs>)', $mode, 'plugin_flowchartjs');
}
function postConnect() {
$this->Lexer->addExitPattern('</flowchartjs>', 'plugin_flowchartjs');
}
function handle($match, $state, $pos, Doku_Handler $handler){
switch ($state) {
case DOKU_LEXER_ENTER :
$style = trim(substr($match, 12, -1));
return array($state, $style);
case DOKU_LEXER_UNMATCHED :
return array($state, $match);
case DOKU_LEXER_EXIT :
return array($state, '');
}
}
function render($mode, Doku_Renderer $renderer, $data) {
if($mode == 'xhtml'){
list($state, $match) = $data;
switch ($state){
case DOKU_LEXER_ENTER:
$renderer->doc .= "<pre class='flowchartjs $match'>";
break;
case DOKU_LEXER_UNMATCHED:
$renderer->doc .= $match;
break;
case DOKU_LEXER_EXIT:
$renderer->doc .= "</pre>";
break;
}
return true;
}
return false;
}
}
//Setup VIM: ex: et ts=4 :