xref: /plugin/ebnf/syntax.php (revision 5c02957ea7451be3c7bdda9541005ea4ed18bbc6)
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.1
10 */
11
12if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14require_once(DOKU_PLUGIN.'syntax.php');
15
16class syntax_plugin_ebnf extends DokuWiki_Syntax_Plugin {
17
18    function getType(){
19        return 'substition';
20    }
21
22    function getSort(){
23        return 999;
24    }
25
26    function connectTo($mode) {
27      $this->Lexer->addSpecialPattern('<ebnf>.*?</ebnf>',$mode,'plugin_ebnf');
28    }
29
30    function handle($match, $state, $pos, Doku_Handler $handler){
31       switch ($state) {
32          case DOKU_LEXER_ENTER :
33            break;
34          case DOKU_LEXER_MATCHED :
35            break;
36          case DOKU_LEXER_UNMATCHED :
37            break;
38          case DOKU_LEXER_EXIT :
39            break;
40          case DOKU_LEXER_SPECIAL :
41            break;
42        }
43        return array($match);
44    }
45
46    function render($mode, Doku_Renderer $renderer, $data) {
47        if($mode == 'xhtml'){
48            try {
49             $text = substr($data[0], 6, strlen($data[0])-13);
50             $text = preg_replace( "/[<>]+/", "", $text);
51             $text = preg_replace( "/[\\n\\r\\t ]+/", " ", $text);
52             $text = urlencode($text);
53             $renderer->doc .= "<img src='".DOKU_URL."lib/plugins/ebnf/ebnf.php?syntax=$text' alt='$text'/>";            // ptype = 'normal'
54            } catch (Exception $e) {
55              $renderer->doc .= "<pre>".htmlentities($text)."\n".$e."</pre>";
56            }
57            return true;
58        }
59        return false;
60    }
61}
62?>