1<?php
2
3/**
4 * DokuWiki plugin Struct Template inlinx syntax
5 *
6 * @author     Iain Hallam <iain@nineworlds.net>
7 * @copyright  © 2022 Iain Hallam
8 * @license    GPL-2.0-only (http://www.gnu.org/licenses/gpl-2.0.html)
9 */
10
11declare(strict_types=1);
12
13use dokuwiki\plugin\structtemplate\meta\StructTemplateSyntax;
14
15/**
16 * Syntax plugin extending common Struct Template base class
17 */
18class syntax_plugin_structtemplate_inline extends StructTemplateSyntax
19{
20    /**
21     * Define the precedence of this plugin to the parser
22     *
23     * @see  https://www.dokuwiki.org/devel:parser:getsort_list
24     */
25    public function getSort()
26    {
27        return 46;
28    }
29
30    /**
31     * Define how this plugin handles paragraphs
32     *
33     * @see  https://www.dokuwiki.org/devel:syntax_plugins#ptype
34     */
35    public function getPType()
36    {
37        return 'normal';
38    }
39
40    /**
41     * Connect lookup patterns to lexer
42     *
43     * @see  https://www.dokuwiki.org/devel:syntax_plugins#patterns
44     *
45     * @param  string  $lmode  Existing lexer mode
46     */
47    public function connectTo($lmode)
48    {
49        // Syntax:
50        // <struct-template inline> OR <struct-template>
51        // ---- data ----
52        // [...]
53        // ----
54        // [...]
55        // </struct-template>
56
57        $re = '<' . self::TAG . ' +inline\b.*?>\n'
58            . '----+ *data *----+\n'
59            . '.*?\n'
60            . '----+\n'
61            . '.*?\n'
62            . '<\/' . self::TAG . '>'
63        ;
64        $this->Lexer->addSpecialPattern(
65            $re,                                  // regex
66            $lmode,                               // lexer mode to use in
67            'plugin_' . self::PLUGIN . '_inline'  // lexer mode to enter
68        );
69
70        $re = '<' . self::TAG . '\b.*?>\n'
71            . '----+ *data *----+\n'
72            . '.*?\n'
73            . '----+\n'
74            . '.*?\n'
75            . '<\/' . self::TAG . '>'
76        ;
77        $this->Lexer->addSpecialPattern(
78            $re,                                  // regex
79            $lmode,                               // lexer mode to use in
80            'plugin_' . self::PLUGIN . '_inline'  // lexer mode to enter
81        );
82    }
83}
84