1<?php
2/**
3 * Bootstrap Wrapper Plugin: Generic Wrapper (span or div)
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_wrapper extends syntax_plugin_bootswrapper_bootstrap
11{
12
13    public $pattern_start = '<(?:WRAPPER|wrapper).*?>(?=.*?</(?:WRAPPER|wrapper)>)';
14    public $pattern_end   = '</(?:WRAPPER|wrapper)>';
15    public $tag_name      = 'wrapper';
16
17    public $tag_attributes = array(
18
19        'screen' => array(
20            'type'     => 'boolean',
21            'values'   => array(0, 1),
22            'required' => false,
23            'default'  => false),
24
25        'print'  => array(
26            'type'     => 'boolean',
27            'values'   => array(0, 1),
28            'required' => false,
29            'default'  => false),
30
31    );
32
33    public function render($mode, Doku_Renderer $renderer, $data)
34    {
35
36        if (empty($data)) {
37            return false;
38        }
39
40        if ($mode !== 'xhtml') {
41            return false;
42        }
43
44        /** @var Doku_Renderer_xhtml $renderer */
45        list($state, $match, $pos, $attributes, $is_block) = $data;
46
47        global $wrapper_tag;
48
49        if ($state == DOKU_LEXER_ENTER) {
50            $wrapper_tag        = ($is_block) ? 'div' : 'span';
51            $wrap_classes       = $attributes['class'];
52            $wrap_classes[]     = 'bs-wrapper';
53            $wrapper_attributes = $this->buildAttributes($attributes, array('class' => $wrap_classes));
54            $markup             = "<$wrapper_tag $wrapper_attributes>";
55
56            $renderer->doc .= $markup;
57
58            return true;
59        }
60
61        if ($state == DOKU_LEXER_EXIT) {
62            $renderer->doc .= "</$wrapper_tag>";
63            return true;
64        }
65
66        return false;
67    }
68}
69