1<?php
2
3
4use ComboStrap\DateTag;
5use ComboStrap\PipelineTag;
6use ComboStrap\PluginUtility;
7use ComboStrap\PrismTags;
8use ComboStrap\Tag\MermaidTag;
9use ComboStrap\XmlTagProcessing;
10
11
12/**
13 *
14 *
15 */
16class syntax_plugin_combo_xmlprotectedtag extends DokuWiki_Syntax_Plugin
17{
18
19
20    private function getTags(): array
21    {
22        $tags = self::TAGS;
23        if ($this->getConf(PrismTags::CONF_FILE_ENABLE)) {
24            $tags[] = PrismTags::FILE_TAG;
25        }
26        return $tags;
27    }
28
29    function getType(): string
30    {
31        /**
32         * You can't write in a code block
33         */
34        return 'protected';
35    }
36
37    /**
38     * How DokuWiki will add P element
39     *
40     *  * 'normal' - The plugin can be used inside paragraphs
41     *  * 'block'  - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs
42     *  * 'stack'  - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs
43     *
44     * @see DokuWiki_Syntax_Plugin::getPType()
45     */
46    function getPType(): string
47    {
48        return 'block';
49    }
50
51    /**
52     * @return array
53     * Allow which kind of plugin inside
54     *
55     * No one of array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs')
56     * because we manage self the content and we call self the parser
57     *
58     * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php
59     */
60    function getAllowedTypes(): array
61    {
62        return array();
63    }
64
65    function getSort(): int
66    {
67        /**
68         * Should be less than the code syntax plugin
69         * which is 200
70         **/
71        return 199;
72    }
73
74    const TAGS = [
75        PrismTags::CONSOLE_TAG,
76        PipelineTag::TAG, // protected inline deprecated
77        DateTag::TAG, // protected inline deprecated
78        MermaidTag::MARKUP_SEQUENCE_DIAGRAM,
79        MermaidTag::MARKUP_CLASS_DIAGRAM,
80        MermaidTag::MARKUP_FLOWCHART,
81        MermaidTag::MARKUP_GANTT,
82        MermaidTag::MARKUP_ERD,
83        MermaidTag::MARKUP_JOURNEY,
84        MermaidTag::MARKUP_PIECHART,
85        MermaidTag::MARKUP_STATE_DIAGRAM,
86    ];
87
88    function connectTo($mode)
89    {
90
91
92        foreach ($this->getTags() as $tag) {
93            $pattern = XmlTagProcessing::getContainerTagPattern($tag);
94            $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent()));
95        }
96
97
98    }
99
100
101    function postConnect()
102    {
103        foreach ($this->getTags() as $tag) {
104            $this->Lexer->addExitPattern('</' . $tag . '>', PluginUtility::getModeFromTag($this->getPluginComponent()));
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     * @see DokuWiki_Syntax_Plugin::handle()
119     *
120     */
121    function handle($match, $state, $pos, Doku_Handler $handler)
122    {
123
124        return XmlTagProcessing::handleStatic($match, $state, $pos, $handler, $this);
125
126    }
127
128    /**
129     * Render the output
130     * @param string $format
131     * @param Doku_Renderer $renderer
132     * @param array $data - what the function handle() return'ed
133     * @return boolean - rendered correctly? (however, returned value is not used at the moment)
134     * @see DokuWiki_Syntax_Plugin::render()
135     *
136     */
137    function render($format, Doku_Renderer $renderer, $data): bool
138    {
139        return XmlTagProcessing::renderStatic($format, $renderer, $data, $this);
140    }
141
142
143}
144
145