xref: /plugin/combo/syntax/iteratordata.php (revision c3437056399326d621a01da73b649707fbb0ae69)
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        /**
81         * For whatever reason, we get the {@link \dokuwiki\Parsing\ParserMode\Quotes `_doublequoteclosing`}
82         * mode
83         */
84        return false;
85    }
86
87
88    function connectTo($mode)
89    {
90        /**
91         * Only in iterator
92         */
93        if ($mode == PluginUtility::getModeFromTag(syntax_plugin_combo_iterator::TAG)) {
94
95            $pattern = PluginUtility::getContainerTagPattern(self::MARKI_PAGE_TAG);
96            $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent()));
97
98        }
99
100    }
101
102
103    public function postConnect()
104    {
105
106        $this->Lexer->addExitPattern('</' . self::MARKI_PAGE_TAG . '>', PluginUtility::getModeFromTag($this->getPluginComponent()));
107
108
109    }
110
111
112    /**
113     *
114     * The handle function goal is to parse the matched syntax through the pattern function
115     * and to return the result for use in the renderer
116     * This result is always cached until the page is modified.
117     * @param string $match
118     * @param int $state
119     * @param int $pos - byte position in the original source file
120     * @param Doku_Handler $handler
121     * @return array|bool
122     * @throws Exception
123     * @see DokuWiki_Syntax_Plugin::handle()
124     *
125     */
126    function handle($match, $state, $pos, Doku_Handler $handler)
127    {
128
129        switch ($state) {
130
131            case DOKU_LEXER_ENTER :
132                $attributes = PluginUtility::getTagAttributes($match);
133                return array(
134                    PluginUtility::STATE => $state,
135                    PluginUtility::ATTRIBUTES => $attributes
136                );
137
138            case DOKU_LEXER_UNMATCHED :
139
140                return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler);
141
142
143            case DOKU_LEXER_EXIT :
144
145
146                return array(
147                    PluginUtility::STATE => $state,
148                );
149
150
151        }
152        return array();
153
154    }
155
156    /**
157     * Render the output
158     * @param string $format
159     * @param Doku_Renderer $renderer
160     * @param array $data - what the function handle() return'ed
161     * @return boolean - rendered correctly? (however, returned value is not used at the moment)
162     * @see DokuWiki_Syntax_Plugin::render()
163     *
164     *
165     */
166    function render($format, Doku_Renderer $renderer, $data)
167    {
168
169        /**
170         * No render, the data is used by {@link syntax_plugin_combo_iterator::handle()}
171         * at the {@link DOKU_LEXER_EXIT}
172         */
173        return true;
174
175    }
176
177
178}
179
180