xref: /dokuwiki/inc/Parsing/ParserMode/Eol.php (revision 71096e46fcbfaeaa808667aba794e77fe2780169) !
1be906b56SAndreas Gohr<?php
2be906b56SAndreas Gohr
3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode;
4be906b56SAndreas Gohr
5*71096e46SAndreas Gohruse dokuwiki\Parsing\Handler;
67958e698SAndreas Gohruse dokuwiki\Parsing\ModeRegistry;
77958e698SAndreas Gohr
8be906b56SAndreas Gohrclass Eol extends AbstractMode
9be906b56SAndreas Gohr{
10be906b56SAndreas Gohr    /** @inheritdoc */
11*71096e46SAndreas Gohr    public function getSort()
12*71096e46SAndreas Gohr    {
13*71096e46SAndreas Gohr        return 370;
14*71096e46SAndreas Gohr    }
15*71096e46SAndreas Gohr
16*71096e46SAndreas Gohr    /** @inheritdoc */
17be906b56SAndreas Gohr    public function connectTo($mode)
18be906b56SAndreas Gohr    {
197958e698SAndreas Gohr        if (in_array($mode, ModeRegistry::getInstance()->getBlockEolModes())) {
20be906b56SAndreas Gohr            return;
21be906b56SAndreas Gohr        }
22be906b56SAndreas Gohr        // see FS#1652, pattern extended to swallow preceding whitespace to avoid
23be906b56SAndreas Gohr        // issues with lines that only contain whitespace
24be906b56SAndreas Gohr        $this->Lexer->addSpecialPattern('(?:^[ \t]*)?\n', $mode, 'eol');
25be906b56SAndreas Gohr    }
26be906b56SAndreas Gohr
27be906b56SAndreas Gohr    /** @inheritdoc */
28*71096e46SAndreas Gohr    public function handle($match, $state, $pos, Handler $handler)
29be906b56SAndreas Gohr    {
30*71096e46SAndreas Gohr        $handler->addCall('eol', [], $pos);
31*71096e46SAndreas Gohr        return true;
32be906b56SAndreas Gohr    }
33be906b56SAndreas Gohr}
34