1<?php
2
3class syntax_plugin_mobiletable extends DokuWiki_Syntax_Plugin {
4
5    function getType() {
6        return 'formatting';
7    }
8
9    function getAllowedTypes() {
10        return ['container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'];
11    }
12
13    function getPType() {
14        return 'stack';
15    }
16
17    function getSort() {
18        return 167;
19    }
20
21    function connectTo($mode){
22        $this->Lexer->addEntryPattern('<mobiletable(?: [0-9]+)?>(?=.*?</mobiletable>)', $mode, 'plugin_mobiletable');
23    }
24
25    function postConnect(){
26        $this->Lexer->addExitPattern('<\/mobiletable>', 'plugin_mobiletable');
27    }
28
29    function handle($match, $state, $pos, Doku_Handler $handler) {
30        if ($state == DOKU_LEXER_ENTER) {
31            preg_match('/<mobiletable ([0-9]+)?>/i', $match, $parts);
32            return '<div class="mobiletable" data-column="'.(isset($parts[1]) && $parts[1] > 0 ? $parts[1] - 1 : '-1').'">';
33        } elseif ($state == DOKU_LEXER_EXIT) {
34            return '</div>';
35        }
36    }
37
38    function render($mode, Doku_Renderer $renderer, $data) {
39        if ($mode == 'xhtml') {
40            $renderer->doc .= $data;
41        }
42        return true;
43    }
44
45}
46