forked from tscherter/dokuwiki-plugin-ebnf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax.php
62 lines (55 loc) · 1.74 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
<?php
/**
* Dokuwiki Plugin EBNF: Displays Syntax Diagrams
*
* Syntax: <ebnf> ebnf syntax </ebnf>
*
* @license GPL3
* @author Vincent Tscherter <[email protected]>
* @version 0.1
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_ebnf extends DokuWiki_Syntax_Plugin {
function getType(){
return 'substition';
}
function getSort(){
return 999;
}
function connectTo($mode) {
$this->Lexer->addSpecialPattern('<ebnf>.*?</ebnf>',$mode,'plugin_ebnf');
}
function handle($match, $state, $pos, Doku_Handler $handler){
switch ($state) {
case DOKU_LEXER_ENTER :
break;
case DOKU_LEXER_MATCHED :
break;
case DOKU_LEXER_UNMATCHED :
break;
case DOKU_LEXER_EXIT :
break;
case DOKU_LEXER_SPECIAL :
break;
}
return array($match);
}
function render($mode, Doku_Renderer $renderer, $data) {
if($mode == 'xhtml'){
try {
$text = substr($data[0], 6, strlen($data[0])-13);
$text = preg_replace( "/[<>]+/", "", $text);
$text = preg_replace( "/[\\n\\r\\t ]+/", " ", $text);
$text = urlencode($text);
$renderer->doc .= "<img src='".DOKU_URL."lib/plugins/ebnf/ebnf.php?syntax=$text' alt='$text'/>"; // ptype = 'normal'
} catch (Exception $e) {
$renderer->doc .= "<pre>".htmlentities($text)."\n".$e."</pre>";
}
return true;
}
return false;
}
}
?>