1<?php 2 3 4// must be run within Dokuwiki 5use ComboStrap\PluginUtility; 6 7if (!defined('DOKU_INC')) die(); 8 9/** 10 * Class syntax_plugin_combo_itext 11 * Setting text attributes on words 12 * 13 */ 14class syntax_plugin_combo_comment extends DokuWiki_Syntax_Plugin 15{ 16 17 const TAG = "comment"; 18 19 /** 20 * If yes, the comment are in the rendering 21 */ 22 const CONF_OUTPUT_COMMENT = "outputComment"; 23 const CANONICAL = "comment"; 24 25 /** 26 * Syntax Type. 27 * 28 * Needs to return one of the mode types defined in {@link $PARSER_MODES} in parser.php 29 * @see DokuWiki_Syntax_Plugin::getType() 30 */ 31 function getType() 32 { 33 return 'formatting'; 34 } 35 36 /** 37 * How Dokuwiki will add P element 38 * 39 * * 'normal' - The plugin can be used inside paragraphs 40 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 41 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 42 * 43 * @see DokuWiki_Syntax_Plugin::getPType() 44 */ 45 function getPType() 46 { 47 return 'normal'; 48 } 49 50 /** 51 * @return array 52 * Allow which kind of plugin inside 53 * 54 * No one of array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 55 * because we manage self the content and we call self the parser 56 * 57 * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php 58 */ 59 function getAllowedTypes() 60 { 61 return array(); 62 } 63 64 65 function getSort() 66 { 67 return 201; 68 } 69 70 71 function connectTo($mode) 72 { 73 74 75 $this->Lexer->addEntryPattern("<!--", $mode, PluginUtility::getModeFromTag($this->getPluginComponent())); 76 77 } 78 79 80 function postConnect() 81 { 82 83 $this->Lexer->addExitPattern("-->", PluginUtility::getModeFromTag($this->getPluginComponent())); 84 85 86 } 87 88 function handle($match, $state, $pos, Doku_Handler $handler) 89 { 90 91 switch ($state) { 92 93 case DOKU_LEXER_ENTER : 94 case DOKU_LEXER_EXIT : 95 return array( 96 PluginUtility::STATE => $state 97 ); 98 99 case DOKU_LEXER_UNMATCHED : 100 return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); 101 102 } 103 return array(); 104 105 } 106 107 /** 108 * Render the output 109 * @param string $format 110 * @param Doku_Renderer $renderer 111 * @param array $data - what the function handle() return'ed 112 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 113 * @see DokuWiki_Syntax_Plugin::render() 114 * 115 * 116 */ 117 function render($format, Doku_Renderer $renderer, $data) 118 { 119 if(PluginUtility::getConfValue(self::CONF_OUTPUT_COMMENT,0)) { 120 if ($format === "xhtml") { 121 if ($data[PluginUtility::STATE] === DOKU_LEXER_UNMATCHED) { 122 $renderer->doc .= "<!--" . PluginUtility::renderUnmatched($data) . "-->"; 123 } 124 } 125 } 126 // unsupported $mode 127 return false; 128 129 } 130 131 132} 133 134