1<?php
2/**
3 * Dokuwiki Plugin EBNF: Displays Syntax Diagrams
4 *
5 * Syntax: <ebnf> ebnf syntax </ebnf>
6 *
7 * @license    GPL3
8 * @author     Vincent Tscherter <vinent.tscherter@karmin.ch>
9 * @version    0.2
10 */
11
12use dokuwiki\Extension\SyntaxPlugin;
13
14class syntax_plugin_ebnf extends DokuWiki_Syntax_Plugin {
15
16    function getType(){
17        return 'substition';
18    }
19
20    function getSort(){
21        return 999;
22    }
23
24    function connectTo($mode) {
25      $this->Lexer->addSpecialPattern('<ebnf>.*?</ebnf>',$mode,'plugin_ebnf');
26    }
27
28    function handle($match, $state, $pos, Doku_Handler $handler){
29       switch ($state) {
30          case DOKU_LEXER_ENTER :
31            break;
32          case DOKU_LEXER_MATCHED :
33            break;
34          case DOKU_LEXER_UNMATCHED :
35            break;
36          case DOKU_LEXER_EXIT :
37            break;
38          case DOKU_LEXER_SPECIAL :
39            break;
40        }
41        return array($match);
42    }
43
44    function render($mode, Doku_Renderer $renderer, $data) {
45        if($mode == 'xhtml'){
46            try {
47             $text = substr($data[0], 6, strlen($data[0])-13);
48             $text = preg_replace( "/[<>]+/", "", $text);
49             $text = preg_replace( "/[\\n\\r\\t ]+/", " ", $text);
50             $text = urlencode($text);
51             $renderer->doc .= "<img src='".DOKU_URL."lib/plugins/ebnf/ebnf.php?syntax=$text' alt='$text'/>";            // ptype = 'normal'
52            } catch (Exception $e) {
53              $renderer->doc .= "<pre>".htmlentities($text)."\n".$e."</pre>";
54            }
55            return true;
56        }
57        return false;
58    }
59}
60?>