1<?php
2/**
3 * Bootstrap Wrapper Plugin: Pane
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @copyright  (C) 2015-2020, Giuseppe Di Terlizzi
8 */
9
10class syntax_plugin_bootswrapper_pane extends syntax_plugin_bootswrapper_bootstrap
11{
12
13    public $p_type         = 'block';
14    public $pattern_start  = '<pane[\s].*?>(?=.*?</pane>)';
15    public $pattern_end    = '</pane>';
16    public $tag_name       = 'pane';
17    public $tag_attributes = array(
18
19        'id' => array(
20            'type'     => 'string',
21            'values'   => null,
22            'required' => true,
23            'default'  => null),
24
25    );
26
27    public function render($mode, Doku_Renderer $renderer, $data)
28    {
29
30        if (empty($data)) {
31            return false;
32        }
33
34        if ($mode !== 'xhtml') {
35            return false;
36        }
37
38        /** @var Doku_Renderer_xhtml $renderer */
39        list($state, $match, $pos, $attributes) = $data;
40
41        if ($state == DOKU_LEXER_ENTER) {
42            $id     = $attributes['id'];
43            $markup = '<div role="tabpanel" class="bs-wrap bs-wrap-tab-pane tab-pane" id="' . $id . '">';
44
45            $renderer->doc .= $markup;
46
47            if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
48                $renderer->startSectionEdit($pos, array('target' => 'plugin_bootswrapper_pane', 'name' => $state));
49            } else {
50                $renderer->startSectionEdit($pos, 'plugin_bootswrapper_pane', $state);
51            }
52
53            return true;
54        }
55
56        if ($state == DOKU_LEXER_EXIT) {
57            $renderer->finishSectionEdit($pos + strlen($match));
58            $renderer->doc .= '</div>';
59
60            return true;
61        }
62
63        return true;
64    }
65}
66