xref: /plugin/ebnf/syntax.php (revision a345322f371276bcfd4aeaa4bdf2eab46577754e)
1*a345322fSVincent.Tscherter<?php
2*a345322fSVincent.Tscherter/**
3*a345322fSVincent.Tscherter * Dokuwiki Plugin EBNF: Displays Syntax Diagrams
4*a345322fSVincent.Tscherter *
5*a345322fSVincent.Tscherter * Syntax: <ebnf> ebnf syntax </ebnf>
6*a345322fSVincent.Tscherter *
7*a345322fSVincent.Tscherter * @license    GPL3
8*a345322fSVincent.Tscherter * @author     Vincent Tscherter <vinent.tscherter@karmin.ch>
9*a345322fSVincent.Tscherter * @version    0.1
10*a345322fSVincent.Tscherter */
11*a345322fSVincent.Tscherter
12*a345322fSVincent.Tscherterif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
13*a345322fSVincent.Tscherterif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14*a345322fSVincent.Tscherterrequire_once(DOKU_PLUGIN.'syntax.php');
15*a345322fSVincent.Tscherter
16*a345322fSVincent.Tscherterclass syntax_plugin_ebnf extends DokuWiki_Syntax_Plugin {
17*a345322fSVincent.Tscherter
18*a345322fSVincent.Tscherter    function getInfo(){
19*a345322fSVincent.Tscherter        return array(
20*a345322fSVincent.Tscherter            'author' => 'Vincent Tscherter',
21*a345322fSVincent.Tscherter            'email'  => 'tscherter@karmin.ch',
22*a345322fSVincent.Tscherter            'date'   => '2009-01-18',
23*a345322fSVincent.Tscherter            'name'   => 'EBNF Plugin',
24*a345322fSVincent.Tscherter            'desc'   => 'EBNF Syntax Diagram',
25*a345322fSVincent.Tscherter            'url'    => 'http://wiki.karmin.ch/ebnf/',
26*a345322fSVincent.Tscherter        );
27*a345322fSVincent.Tscherter    }
28*a345322fSVincent.Tscherter
29*a345322fSVincent.Tscherter    function getType(){
30*a345322fSVincent.Tscherter        return 'substition';
31*a345322fSVincent.Tscherter    }
32*a345322fSVincent.Tscherter
33*a345322fSVincent.Tscherter    function getSort(){
34*a345322fSVincent.Tscherter        return 999;
35*a345322fSVincent.Tscherter    }
36*a345322fSVincent.Tscherter
37*a345322fSVincent.Tscherter    function connectTo($mode) {
38*a345322fSVincent.Tscherter      $this->Lexer->addSpecialPattern('<ebnf>.*?</ebnf>',$mode,'plugin_ebnf');
39*a345322fSVincent.Tscherter    }
40*a345322fSVincent.Tscherter
41*a345322fSVincent.Tscherter    function handle($match, $state, $pos, &$handler){
42*a345322fSVincent.Tscherter       switch ($state) {
43*a345322fSVincent.Tscherter          case DOKU_LEXER_ENTER :
44*a345322fSVincent.Tscherter            break;
45*a345322fSVincent.Tscherter          case DOKU_LEXER_MATCHED :
46*a345322fSVincent.Tscherter            break;
47*a345322fSVincent.Tscherter          case DOKU_LEXER_UNMATCHED :
48*a345322fSVincent.Tscherter            break;
49*a345322fSVincent.Tscherter          case DOKU_LEXER_EXIT :
50*a345322fSVincent.Tscherter            break;
51*a345322fSVincent.Tscherter          case DOKU_LEXER_SPECIAL :
52*a345322fSVincent.Tscherter            break;
53*a345322fSVincent.Tscherter        }
54*a345322fSVincent.Tscherter        return array($match);
55*a345322fSVincent.Tscherter    }
56*a345322fSVincent.Tscherter
57*a345322fSVincent.Tscherter    function render($mode, &$renderer, $data) {
58*a345322fSVincent.Tscherter        if($mode == 'xhtml'){
59*a345322fSVincent.Tscherter            try {
60*a345322fSVincent.Tscherter             $text = substr($data[0], 6, strlen($data[0])-13);
61*a345322fSVincent.Tscherter             $text = preg_replace( "/[<>]+/", "", $text);
62*a345322fSVincent.Tscherter             $text = preg_replace( "/[\\n\\r\\t ]+/", " ", $text);
63*a345322fSVincent.Tscherter             $text = urlencode($text);
64*a345322fSVincent.Tscherter             $renderer->doc .= "<img src='".DOKU_URL."lib/plugins/ebnf/ebnf.php?syntax=$text' alt='$text'/>";            // ptype = 'normal'
65*a345322fSVincent.Tscherter            } catch (Exception $e) {
66*a345322fSVincent.Tscherter              $renderer->doc .= "<pre>".htmlentities($text)."\n".$e."</pre>";
67*a345322fSVincent.Tscherter            }
68*a345322fSVincent.Tscherter            return true;
69*a345322fSVincent.Tscherter        }
70*a345322fSVincent.Tscherter        return false;
71*a345322fSVincent.Tscherter    }
72*a345322fSVincent.Tscherter}
73*a345322fSVincent.Tscherter?>