xref: /dokuwiki/inc/Parsing/ParserMode/Preformatted.php (revision 7958e69808290099292c0703b95d88708f6ebb96)
1<?php
2
3namespace dokuwiki\Parsing\ParserMode;
4
5use dokuwiki\Parsing\ModeRegistry;
6
7class Preformatted extends AbstractMode
8{
9    /** @inheritdoc */
10    public function connectTo($mode)
11    {
12        $markers = ModeRegistry::getInstance()->getLineStartMarkers();
13        $lookahead = $markers ? '(?![' . implode('', $markers) . '])' : '';
14
15        $this->Lexer->addEntryPattern('\n  ' . $lookahead, $mode, 'preformatted');
16        $this->Lexer->addEntryPattern('\n\t' . $lookahead, $mode, 'preformatted');
17
18        // How to effect a sub pattern with the Lexer!
19        $this->Lexer->addPattern('\n  ', 'preformatted');
20        $this->Lexer->addPattern('\n\t', 'preformatted');
21    }
22
23    /** @inheritdoc */
24    public function postConnect()
25    {
26        $this->Lexer->addExitPattern('\n', 'preformatted');
27    }
28
29    /** @inheritdoc */
30    public function getSort()
31    {
32        return 20;
33    }
34}
35