1<?php 2/** 3 * HTML Comment Plugin: allows HTML comments to be retained in the output 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Christopher Arndt <chris@chrisarndt.de> 7 * Danny Lin <danny0838@gmail.com> 8 */ 9 10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(DOKU_PLUGIN.'syntax.php'); 13 14/** 15 * All DokuWiki plugins to extend the parser/rendering mechanism 16 * need to inherit from this class 17 */ 18class syntax_plugin_htmlcomment extends DokuWiki_Syntax_Plugin { 19 20 function getType() { return 'substition'; } 21 22 function getSort() { return 325; } 23 24 function connectTo($mode) { 25 $this->Lexer->addSpecialPattern("<\!--.*?-->", $mode, 'plugin_htmlcomment'); 26 } 27 28 function handle($match, $state, $pos, Doku_Handler $handler) { 29 if ($state == DOKU_LEXER_SPECIAL) { 30 // strip <!-- from start and --> from end 31 $match = substr($match,4,-3); 32 return array($state, $match); 33 } 34 return array(); 35 } 36 37 function render($mode, Doku_Renderer $renderer, $data) { 38 if ($mode == 'xhtml') { 39 list($state, $match) = $data; 40 if ($state == DOKU_LEXER_SPECIAL) { 41 $renderer->doc .= '<!--'.$match.'-->'; 42 } 43 return true; 44 } 45 return false; 46 } 47} 48 49?> 50