1<?php
2/**
3 * Allow Indentation DokuWiki Plugin (Syntax Component)
4 *
5 * Allow using an indentation in wiki text and disable a rendering indented
6 * blocks as a preformatted text.
7 *
8 * @license MIT https://opensource.org/licenses/MIT
9 * @author  Lisin Dmitriy <mrlisdim@gmail.com>
10 */
11
12
13if (!defined('DOKU_INC')) {
14    die();
15}
16
17
18class syntax_plugin_allowindentation extends DokuWiki_Syntax_Plugin
19{
20    /**
21     * @return string Syntax mode type
22     */
23    function getPType()
24    {
25        return 'normal';
26    }
27
28    /**
29     * @return string Paragraph type
30     */
31    public function getType()
32    {
33        return 'container';
34    }
35
36    /**
37     * Allow all possible types
38     */
39    function getAllowedTypes()
40    {
41        return array (
42            'container',
43            'substition',
44            'protected',
45            'disabled',
46            'formatting',
47            'paragraphs',
48            'baseonly'
49        );
50    }
51
52    /**
53     * Priority less than `preformatted`
54     * @return int Sort order - Low numbers go before high numbers
55     */
56    public function getSort()
57    {
58        return 19;
59    }
60
61    /**
62     * Connect pattern to lexer
63     *
64     * Catch all preformatted entries to prevent them from rendering as
65     * `<pre>`.
66     *
67     * @param string $mode Parser mode
68     */
69    public function connectTo($mode)
70    {
71        $this->Lexer->addSpecialPattern('\n  (?![\*\-])', $mode, 'plugin_allowindentation');
72        $this->Lexer->addSpecialPattern('\n\t(?![\*\-])', $mode, 'plugin_allowindentation');
73    }
74
75    /**
76     * Do nothing in this plugin.
77     */
78    function postConnect() { }
79
80    /**
81     * Handle matches of the allowindentation syntax
82     *
83     * Return nothing to handle it in `render`.
84     *
85     * @param string       $match   The match of the syntax
86     * @param int          $state   The state of the handler
87     * @param int          $pos     The position in the document
88     * @param Doku_Handler $handler The handler
89     *
90     * @return array Data for the renderer
91     */
92    public function handle($match, $state, $pos, Doku_Handler $handler)
93    {
94        return array();
95    }
96
97    /**
98     * Render xhtml output or metadata
99     *
100     * Actually prevent any rendering in this plugin.
101     *
102     * @param string        $mode     Renderer mode (supported modes: xhtml)
103     * @param Doku_Renderer $renderer The renderer
104     * @param array         $data     The data from the handler() function
105     *
106     * @return bool If rendering was successful.
107     */
108    public function render($mode, Doku_Renderer $renderer, $data)
109    {
110        return false;
111    }
112}
113