xref: /dokuwiki/inc/Parsing/ParserMode/Listblock.php (revision 7958e69808290099292c0703b95d88708f6ebb96)
1<?php
2
3namespace dokuwiki\Parsing\ParserMode;
4
5use dokuwiki\Parsing\ModeRegistry;
6
7class Listblock extends AbstractMode
8{
9    /**
10     * Listblock constructor.
11     */
12    public function __construct()
13    {
14        $this->allowedModes = ModeRegistry::getInstance()->getModesForCategories([
15            ModeRegistry::CATEGORY_FORMATTING,
16            ModeRegistry::CATEGORY_SUBSTITION,
17            ModeRegistry::CATEGORY_DISABLED,
18            ModeRegistry::CATEGORY_PROTECTED,
19        ]);
20    }
21
22    /** @inheritdoc */
23    public function preConnect()
24    {
25        $registry = ModeRegistry::getInstance();
26        $registry->registerBlockEolMode('listblock');
27        $registry->registerLineStartMarkers('listblock', ['\\*', '\\-']);
28    }
29
30    /** @inheritdoc */
31    public function connectTo($mode)
32    {
33        $this->Lexer->addEntryPattern('[ \t]*\n {2,}[\-\*]', $mode, 'listblock');
34        $this->Lexer->addEntryPattern('[ \t]*\n\t{1,}[\-\*]', $mode, 'listblock');
35
36        $this->Lexer->addPattern('\n {2,}[\-\*]', 'listblock');
37        $this->Lexer->addPattern('\n\t{1,}[\-\*]', 'listblock');
38    }
39
40    /** @inheritdoc */
41    public function postConnect()
42    {
43        $this->Lexer->addExitPattern('\n', 'listblock');
44    }
45
46    /** @inheritdoc */
47    public function getSort()
48    {
49        return 10;
50    }
51}
52