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 getInfo(){ 19 return array( 20 'author' => 'Vincent Tscherter', 21 'email' => 'tscherter@karmin.ch', 22 'date' => '2009-01-18', 23 'name' => 'EBNF Plugin', 24 'desc' => 'EBNF Syntax Diagram', 25 'url' => 'http://wiki.karmin.ch/ebnf/', 26 ); 27 } 28 29 function getType(){ 30 return 'substition'; 31 } 32 33 function getSort(){ 34 return 999; 35 } 36 37 function connectTo($mode) { 38 $this->Lexer->addSpecialPattern('<ebnf>.*?</ebnf>',$mode,'plugin_ebnf'); 39 } 40 41 function handle($match, $state, $pos, &$handler){ 42 switch ($state) { 43 case DOKU_LEXER_ENTER : 44 break; 45 case DOKU_LEXER_MATCHED : 46 break; 47 case DOKU_LEXER_UNMATCHED : 48 break; 49 case DOKU_LEXER_EXIT : 50 break; 51 case DOKU_LEXER_SPECIAL : 52 break; 53 } 54 return array($match); 55 } 56 57 function render($mode, &$renderer, $data) { 58 if($mode == 'xhtml'){ 59 try { 60 $text = substr($data[0], 6, strlen($data[0])-13); 61 $text = preg_replace( "/[<>]+/", "", $text); 62 $text = preg_replace( "/[\\n\\r\\t ]+/", " ", $text); 63 $text = urlencode($text); 64 $renderer->doc .= "<img src='".DOKU_URL."lib/plugins/ebnf/ebnf.php?syntax=$text' alt='$text'/>"; // ptype = 'normal' 65 } catch (Exception $e) { 66 $renderer->doc .= "<pre>".htmlentities($text)."\n".$e."</pre>"; 67 } 68 return true; 69 } 70 return false; 71 } 72} 73?>