xref: /dokuwiki/inc/Parsing/ParserMode/Quote.php (revision 71096e46fcbfaeaa808667aba794e77fe2780169)
1be906b56SAndreas Gohr<?php
2be906b56SAndreas Gohr
3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode;
4be906b56SAndreas Gohr
5*71096e46SAndreas Gohruse dokuwiki\Parsing\Handler;
6*71096e46SAndreas 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,
18c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_SUBSTITION,
19c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_DISABLED,
20c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_PROTECTED,
21c8dd1b9dSAndreas Gohr        ]);
22be906b56SAndreas Gohr    }
23be906b56SAndreas Gohr
24be906b56SAndreas Gohr    /** @inheritdoc */
25*71096e46SAndreas Gohr    public function getSort()
26*71096e46SAndreas Gohr    {
27*71096e46SAndreas Gohr        return 220;
28*71096e46SAndreas Gohr    }
29*71096e46SAndreas Gohr
30*71096e46SAndreas 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 */
44*71096e46SAndreas Gohr    public function handle($match, $state, $pos, Handler $handler)
45be906b56SAndreas Gohr    {
46*71096e46SAndreas Gohr        switch ($state) {
47*71096e46SAndreas Gohr            case DOKU_LEXER_ENTER:
48*71096e46SAndreas Gohr                $handler->setCallWriter(new QuoteHandler($handler->getCallWriter()));
49*71096e46SAndreas Gohr                $handler->addCall('quote_start', [$match], $pos);
50*71096e46SAndreas Gohr                break;
51*71096e46SAndreas Gohr
52*71096e46SAndreas Gohr            case DOKU_LEXER_EXIT:
53*71096e46SAndreas Gohr                $handler->addCall('quote_end', [], $pos);
54*71096e46SAndreas Gohr                /** @var QuoteHandler $reWriter */
55*71096e46SAndreas Gohr                $reWriter = $handler->getCallWriter();
56*71096e46SAndreas Gohr                $handler->setCallWriter($reWriter->process());
57*71096e46SAndreas Gohr                break;
58*71096e46SAndreas Gohr
59*71096e46SAndreas Gohr            case DOKU_LEXER_MATCHED:
60*71096e46SAndreas Gohr                $handler->addCall('quote_newline', [$match], $pos);
61*71096e46SAndreas Gohr                break;
62*71096e46SAndreas Gohr
63*71096e46SAndreas Gohr            case DOKU_LEXER_UNMATCHED:
64*71096e46SAndreas Gohr                $handler->addCall('cdata', [$match], $pos);
65*71096e46SAndreas Gohr                break;
66*71096e46SAndreas Gohr        }
67*71096e46SAndreas Gohr
68*71096e46SAndreas Gohr        return true;
69be906b56SAndreas Gohr    }
70be906b56SAndreas Gohr}
71