1<?php
2/**
3 * Bootstrap Wrapper Plugin: Label
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_label extends syntax_plugin_bootswrapper_bootstrap
11{
12
13    public $p_type         = 'normal';
14    public $pattern_start  = '<(?:LABEL|label).*?>(?=.*?</(?:LABEL|label)>)';
15    public $pattern_end    = '</(?:LABEL|label)>';
16    public $tag_name       = 'label';
17    public $tag_attributes = array(
18
19        'type' => array(
20            'type'     => 'string',
21            'values'   => array('default', 'primary', 'success', 'info', 'warning', 'danger'),
22            'required' => true,
23            'default'  => 'default'),
24
25        'icon' => array(
26            'type'     => 'string',
27            'values'   => null,
28            'required' => false,
29            'default'  => null),
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 $label_tag;
48
49        if ($state == DOKU_LEXER_ENTER) {
50            $label_tag = (($is_block) ? 'div' : 'span');
51            $type      = $attributes['type'];
52            $icon      = $attributes['icon'];
53
54            $markup = '<' . $label_tag . ' class="bs-wrap bs-wrap-label label label-' . $type . '">';
55
56            if ($icon) {
57                $markup .= '<i class="' . $icon . '"></i> ';
58            }
59
60            $renderer->doc .= $markup;
61            return true;
62        }
63
64        if ($state == DOKU_LEXER_EXIT) {
65            $renderer->doc .= "</$label_tag>";
66            return true;
67        }
68
69        return true;
70    }
71}
72