1<?php
2
3use dokuwiki\Extension\SyntaxPlugin;
4
5/**
6 * BBCode plugin: allows BBCode markup familiar from forum software
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @author     Esther Brunner <esther@kaffeehaus.ch>
10 */
11class syntax_plugin_bbcode_ulist extends SyntaxPlugin
12{
13    /** @inheritdoc */
14    public function getType()
15    {
16        return 'container';
17    }
18    /** @inheritdoc */
19    public function getPType()
20    {
21        return 'block';
22    }
23    /** @inheritdoc */
24    public function getAllowedTypes()
25    {
26        return ['formatting', 'substition', 'disabled', 'protected'];
27    }
28    /** @inheritdoc */
29    public function getSort()
30    {
31        return 105;
32    }
33    /** @inheritdoc */
34    public function connectTo($mode)
35    {
36        $this->Lexer->addEntryPattern('\[list\]\s*?\[\*\](?=.*?\x5B/list\x5D)', $mode, 'plugin_bbcode_ulist');
37    }
38    /** @inheritdoc */
39    public function postConnect()
40    {
41        $this->Lexer->addExitPattern('\[/list\]', 'plugin_bbcode_ulist');
42    }
43
44    /** @inheritdoc */
45    public function handle($match, $state, $pos, Doku_Handler $handler)
46    {
47        switch ($state) {
48            case DOKU_LEXER_ENTER:
49            case DOKU_LEXER_EXIT:
50                return [$state, ''];
51            case DOKU_LEXER_UNMATCHED:
52                return [$state, $match];
53        }
54        return [];
55    }
56
57    /** @inheritdoc */
58    public function render($format, Doku_Renderer $renderer, $data)
59    {
60        if ($format == 'xhtml') {
61            [$state, $match] = $data;
62            switch ($state) {
63                case DOKU_LEXER_ENTER:
64                    $renderer->doc .= '<ul><li class="level1"><div class="li">';
65                    break;
66
67                case DOKU_LEXER_UNMATCHED:
68                    $match = $renderer->_xmlEntities($match);
69                    $renderer->doc .= str_replace('[*]', '</div></li><li class="level1"><div class="li">', $match);
70                    break;
71
72                case DOKU_LEXER_EXIT:
73                    $renderer->doc .= '</div></li></ul>';
74                    break;
75            }
76            return true;
77        }
78        return false;
79    }
80}
81