xref: /dokuwiki/inc/Parsing/ParserMode/Quote.php (revision 56c730b56ef2746acf3b1a27c69bada1239535bd)
1be906b56SAndreas Gohr<?php
2be906b56SAndreas Gohr
3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode;
4be906b56SAndreas Gohr
571096e46SAndreas Gohruse dokuwiki\Parsing\Handler;
671096e46SAndreas Gohruse dokuwiki\Parsing\Handler\Quote as QuoteHandler;
7c8dd1b9dSAndreas Gohruse dokuwiki\Parsing\ModeRegistry;
8c8dd1b9dSAndreas Gohr
9be906b56SAndreas Gohrclass Quote extends AbstractMode
10be906b56SAndreas Gohr{
11be906b56SAndreas Gohr    /**
12be906b56SAndreas Gohr     * Quote constructor.
13be906b56SAndreas Gohr     */
14be906b56SAndreas Gohr    public function __construct()
15be906b56SAndreas Gohr    {
16c8dd1b9dSAndreas Gohr        $this->allowedModes = ModeRegistry::getInstance()->getModesForCategories([
17c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_FORMATTING,
18*56c730b5SAndreas Gohr            ModeRegistry::CATEGORY_SUBSTITUTION,
19c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_DISABLED,
20c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_PROTECTED,
21c8dd1b9dSAndreas Gohr        ]);
22be906b56SAndreas Gohr    }
23be906b56SAndreas Gohr
24be906b56SAndreas Gohr    /** @inheritdoc */
2571096e46SAndreas Gohr    public function getSort()
2671096e46SAndreas Gohr    {
2771096e46SAndreas Gohr        return 220;
2871096e46SAndreas Gohr    }
2971096e46SAndreas Gohr
3071096e46SAndreas Gohr    /** @inheritdoc */
31be906b56SAndreas Gohr    public function connectTo($mode)
32be906b56SAndreas Gohr    {
33be906b56SAndreas Gohr        $this->Lexer->addEntryPattern('\n>{1,}', $mode, 'quote');
34be906b56SAndreas Gohr    }
35be906b56SAndreas Gohr
36be906b56SAndreas Gohr    /** @inheritdoc */
37be906b56SAndreas Gohr    public function postConnect()
38be906b56SAndreas Gohr    {
39be906b56SAndreas Gohr        $this->Lexer->addPattern('\n>{1,}', 'quote');
40be906b56SAndreas Gohr        $this->Lexer->addExitPattern('\n', 'quote');
41be906b56SAndreas Gohr    }
42be906b56SAndreas Gohr
43be906b56SAndreas Gohr    /** @inheritdoc */
4471096e46SAndreas Gohr    public function handle($match, $state, $pos, Handler $handler)
45be906b56SAndreas Gohr    {
4671096e46SAndreas Gohr        switch ($state) {
4771096e46SAndreas Gohr            case DOKU_LEXER_ENTER:
4871096e46SAndreas Gohr                $handler->setCallWriter(new QuoteHandler($handler->getCallWriter()));
4971096e46SAndreas Gohr                $handler->addCall('quote_start', [$match], $pos);
5071096e46SAndreas Gohr                break;
5171096e46SAndreas Gohr
5271096e46SAndreas Gohr            case DOKU_LEXER_EXIT:
5371096e46SAndreas Gohr                $handler->addCall('quote_end', [], $pos);
5471096e46SAndreas Gohr                /** @var QuoteHandler $reWriter */
5571096e46SAndreas Gohr                $reWriter = $handler->getCallWriter();
5671096e46SAndreas Gohr                $handler->setCallWriter($reWriter->process());
5771096e46SAndreas Gohr                break;
5871096e46SAndreas Gohr
5971096e46SAndreas Gohr            case DOKU_LEXER_MATCHED:
6071096e46SAndreas Gohr                $handler->addCall('quote_newline', [$match], $pos);
6171096e46SAndreas Gohr                break;
6271096e46SAndreas Gohr
6371096e46SAndreas Gohr            case DOKU_LEXER_UNMATCHED:
6471096e46SAndreas Gohr                $handler->addCall('cdata', [$match], $pos);
6571096e46SAndreas Gohr                break;
6671096e46SAndreas Gohr        }
6771096e46SAndreas Gohr
6871096e46SAndreas Gohr        return true;
69be906b56SAndreas Gohr    }
70be906b56SAndreas Gohr}
71