1<?php 2 3 4use ComboStrap\PluginUtility; 5use ComboStrap\TagAttributes; 6use ComboStrap\XmlTagProcessing; 7 8 9/** 10 * This syntax is not a classic syntax plugin 11 * 12 * The instructions are captured at the {@link DOKU_LEXER_END} 13 * state of {@link syntax_plugin_combo_iterator::handle()} 14 * to create the data 15 * 16 * 17 */ 18class syntax_plugin_combo_iteratordata extends DokuWiki_Syntax_Plugin 19{ 20 21 /** 22 * Tag in Dokuwiki cannot have a `-` 23 * This is the last part of the class 24 */ 25 const TAG = "iteratordata"; 26 27 /** 28 * The pattern 29 */ 30 const MARKI_PAGE_TAG = "data"; 31 32 33 /** 34 * Syntax Type. 35 * 36 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 37 * @see https://www.dokuwiki.org/devel:syntax_plugins#syntax_types 38 * @see DokuWiki_Syntax_Plugin::getType() 39 */ 40 function getType() 41 { 42 return 'protected'; 43 } 44 45 /** 46 * How Dokuwiki will add P element 47 * 48 * * 'normal' - Inline 49 * * 'block' - Block (p are not created inside) 50 * * 'stack' - Block (p can be created inside) 51 * 52 * @see DokuWiki_Syntax_Plugin::getPType() 53 * @see https://www.dokuwiki.org/devel:syntax_plugins#ptype 54 */ 55 function getPType() 56 { 57 return 'normal'; 58 } 59 60 /** 61 * @return array 62 * Allow which kind of plugin inside 63 * 64 * No one of array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 65 * because we manage self the content and we call self the parser 66 * 67 * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php 68 */ 69 function getAllowedTypes() 70 { 71 return array(); 72 } 73 74 function getSort() 75 { 76 return 201; 77 } 78 79 public function accepts($mode) 80 { 81 /** 82 * For whatever reason, we get the {@link \dokuwiki\Parsing\ParserMode\Quotes `_doublequoteclosing`} 83 * mode 84 */ 85 return false; 86 } 87 88 89 function connectTo($mode) 90 { 91 /** 92 * Only in iterator 93 */ 94 if ($mode == PluginUtility::getModeFromTag(syntax_plugin_combo_iterator::TAG)) { 95 96 $pattern = XmlTagProcessing::getContainerTagPattern(self::MARKI_PAGE_TAG); 97 $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent())); 98 99 } 100 101 } 102 103 104 public function postConnect() 105 { 106 107 $this->Lexer->addExitPattern('</' . self::MARKI_PAGE_TAG . '>', PluginUtility::getModeFromTag($this->getPluginComponent())); 108 109 110 } 111 112 113 /** 114 * 115 * The handle function goal is to parse the matched syntax through the pattern function 116 * and to return the result for use in the renderer 117 * This result is always cached until the page is modified. 118 * @param string $match 119 * @param int $state 120 * @param int $pos - byte position in the original source file 121 * @param Doku_Handler $handler 122 * @return array|bool 123 * @throws Exception 124 * @see DokuWiki_Syntax_Plugin::handle() 125 * 126 */ 127 function handle($match, $state, $pos, Doku_Handler $handler) 128 { 129 130 switch ($state) { 131 132 case DOKU_LEXER_ENTER : 133 $attributes = PluginUtility::getTagAttributes($match); 134 return array( 135 PluginUtility::STATE => $state, 136 PluginUtility::ATTRIBUTES => $attributes 137 ); 138 139 case DOKU_LEXER_UNMATCHED : 140 141 return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); 142 143 144 case DOKU_LEXER_EXIT : 145 146 147 return array( 148 PluginUtility::STATE => $state, 149 ); 150 151 152 } 153 return array(); 154 155 } 156 157 /** 158 * Render the output 159 * @param string $format 160 * @param Doku_Renderer $renderer 161 * @param array $data - what the function handle() return'ed 162 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 163 * @see DokuWiki_Syntax_Plugin::render() 164 * 165 * 166 */ 167 function render($format, Doku_Renderer $renderer, $data) 168 { 169 170 /** 171 * No render, the data is used by {@link syntax_plugin_combo_iterator::handle()} 172 * at the {@link DOKU_LEXER_EXIT} 173 */ 174 return true; 175 176 } 177 178 179} 180 181