1<?php 2/** 3 * Plugin Webcode: Show webcode (Css, HTML) in a iframe 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Nicolas GERARD 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11require_once(__DIR__ . '/../webcomponent.php'); 12 13/** 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 * 17 * Format 18 * 19 * syntax_plugin_PluginName_PluginComponent 20 */ 21class syntax_plugin_webcomponent_console extends DokuWiki_Syntax_Plugin 22{ 23 24 25 /* 26 * What is the type of this plugin ? 27 * This a plugin categorization 28 * This is only important for other plugin 29 * See @getAllowedTypes 30 */ 31 public function getType() 32 { 33 return 'formatting'; 34 } 35 36 37 // Sort order in which the plugin are applied 38 public function getSort() 39 { 40 return 168; 41 } 42 43 /** 44 * 45 * @return array 46 * The plugin type that are allowed inside 47 * this node (ie nested) 48 * Otherwise the node that are in the matched content are not processed 49 */ 50 function getAllowedTypes() { 51 return array(); 52 53 } 54 55 /** 56 * Handle the node 57 * @return string 58 * See 59 * https://www.dokuwiki.org/devel:syntax_plugins#ptype 60 */ 61 function getPType(){ return 'block';} 62 63 // This where the addEntryPattern must bed defined 64 public function connectTo($mode) 65 { 66 // This define the DOKU_LEXER_ENTER state 67 $pattern = webcomponent::getLookAheadPattern(self::getElementName()); 68 $this->Lexer->addEntryPattern($pattern, $mode, 'plugin_' . webcomponent::PLUGIN_NAME . '_' . $this->getPluginComponent()); 69 70 } 71 72 public function postConnect() 73 { 74 // We define the DOKU_LEXER_EXIT state 75 $this->Lexer->addExitPattern('</' . self::getElementName() . '>', 'plugin_' . webcomponent::PLUGIN_NAME . '_' . $this->getPluginComponent()); 76 } 77 78 79 /** 80 * Handle the match 81 * You get the match for each pattern in the $match variable 82 * $state says if it's an entry, exit or match pattern 83 * 84 * This is an instruction block and is cached apart from the rendering output 85 * There is two caches levels 86 * This cache may be suppressed with the url parameters ?purge=true 87 */ 88 public function handle($match, $state, $pos, Doku_Handler $handler) 89 { 90 switch ($state) { 91 92 case DOKU_LEXER_ENTER : 93 94 break; 95 96 case DOKU_LEXER_UNMATCHED: 97 return array($state,$match); 98 break; 99 100 case DOKU_LEXER_EXIT: 101 102 break; 103 104 } 105 106 } 107 108 /** 109 * Create output 110 * The rendering process 111 */ 112 public function render($mode, Doku_Renderer $renderer, $data) 113 { 114 // The $data variable comes from the handle() function 115 // 116 // $mode = 'xhtml' means that we output html 117 // There is other mode such as metadata, odt 118 if ($mode == 'xhtml') { 119 120 $state = $data[0]; 121 // No Unmatched because it's handled in the handle function 122 switch ($state) { 123 124 case DOKU_LEXER_UNMATCHED: 125 $text=$data[1]; 126 /** 127 * @var Doku_Renderer_xhtml 128 * See code in Doku_Renderer_xhtml 129 * with lang, filename, highlight,... parameters 130 */ 131 $renderer->code($text); 132 break; 133 134 } 135 return true; 136 } 137 return false; 138 } 139 140 public static function getElementName() 141 { 142 return webcomponent::getTagName(get_called_class()); 143 } 144 145} 146