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