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