xref: /dokuwiki/inc/Parsing/ParserMode/Table.php (revision c8dd1b9d24a2f9905db764a0ac4646fb1e172af4)
1be906b56SAndreas Gohr<?php
2be906b56SAndreas Gohr
3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode;
4be906b56SAndreas Gohr
5*c8dd1b9dSAndreas Gohruse dokuwiki\Parsing\ModeRegistry;
6*c8dd1b9dSAndreas Gohr
7be906b56SAndreas Gohrclass Table extends AbstractMode
8be906b56SAndreas Gohr{
9be906b56SAndreas Gohr    /**
10be906b56SAndreas Gohr     * Table constructor.
11be906b56SAndreas Gohr     */
12be906b56SAndreas Gohr    public function __construct()
13be906b56SAndreas Gohr    {
14*c8dd1b9dSAndreas Gohr        $this->allowedModes = ModeRegistry::getInstance()->getModesForCategories([
15*c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_FORMATTING,
16*c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_SUBSTITION,
17*c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_DISABLED,
18*c8dd1b9dSAndreas Gohr            ModeRegistry::CATEGORY_PROTECTED,
19*c8dd1b9dSAndreas Gohr        ]);
20be906b56SAndreas Gohr    }
21be906b56SAndreas Gohr
22be906b56SAndreas Gohr    /** @inheritdoc */
23be906b56SAndreas Gohr    public function connectTo($mode)
24be906b56SAndreas Gohr    {
25be906b56SAndreas Gohr        $this->Lexer->addEntryPattern('[\t ]*\n\^', $mode, 'table');
26be906b56SAndreas Gohr        $this->Lexer->addEntryPattern('[\t ]*\n\|', $mode, 'table');
27be906b56SAndreas Gohr    }
28be906b56SAndreas Gohr
29be906b56SAndreas Gohr    /** @inheritdoc */
30be906b56SAndreas Gohr    public function postConnect()
31be906b56SAndreas Gohr    {
32be906b56SAndreas Gohr        $this->Lexer->addPattern('\n\^', 'table');
33be906b56SAndreas Gohr        $this->Lexer->addPattern('\n\|', 'table');
34be906b56SAndreas Gohr        $this->Lexer->addPattern('[\t ]*:::[\t ]*(?=[\|\^])', 'table');
35be906b56SAndreas Gohr        $this->Lexer->addPattern('[\t ]+', 'table');
36be906b56SAndreas Gohr        $this->Lexer->addPattern('\^', 'table');
37be906b56SAndreas Gohr        $this->Lexer->addPattern('\|', 'table');
38be906b56SAndreas Gohr        $this->Lexer->addExitPattern('\n', 'table');
39be906b56SAndreas Gohr    }
40be906b56SAndreas Gohr
41be906b56SAndreas Gohr    /** @inheritdoc */
42be906b56SAndreas Gohr    public function getSort()
43be906b56SAndreas Gohr    {
44be906b56SAndreas Gohr        return 60;
45be906b56SAndreas Gohr    }
46be906b56SAndreas Gohr}
47