1<?php
2
3// implementation of
4// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/cite
5
6// must be run within Dokuwiki
7if(!defined('DOKU_INC')) die();
8
9
10class syntax_plugin_webcomponent_cite extends DokuWiki_Syntax_Plugin {
11
12    function getType() {
13        return 'formatting';
14    }
15
16    function getPType() {
17        return 'block';
18    }
19
20    function getAllowedTypes() {
21        return array ('substition','formatting','disabled');
22    }
23
24    function getSort() {
25        return 201;
26    }
27
28
29
30    function connectTo($mode) {
31
32        $pattern = '<' . $this->getPluginComponent() . '.*?>(?=.*?</' . $this->getPluginComponent() . '>)';
33        $this->Lexer->addEntryPattern($pattern, $mode, 'plugin_' . webcomponent::PLUGIN_NAME . '_' . $this->getPluginComponent());
34
35    }
36
37    function postConnect() {
38
39        $this->Lexer->addExitPattern('</' . self::getTag() . '>', 'plugin_' . webcomponent::PLUGIN_NAME . '_' . $this->getPluginComponent());
40
41    }
42
43    function handle($match, $state, $pos, Doku_Handler $handler) {
44
45        switch ($state) {
46
47            case DOKU_LEXER_ENTER :
48                $match = utf8_substr($match, strlen($this->getPluginComponent()) + 1, -1);
49                $parameters = webcomponent::parseMatch($match);
50                return array($state, $parameters);
51
52            case DOKU_LEXER_UNMATCHED :
53                return array ($state, $match);
54
55            case DOKU_LEXER_EXIT :
56
57                // Important otherwise we don't get an exit in the render
58                return array($state, '');
59
60
61        }
62        return array();
63
64    }
65
66    function render($mode, Doku_Renderer $renderer, $data) {
67
68        if ($mode == 'xhtml') {
69
70            /** @var Doku_Renderer_xhtml $renderer */
71            list($state, $parameters) = $data;
72            switch ($state) {
73                case DOKU_LEXER_ENTER :
74                    $renderer->doc .= '<'.$this->getPluginComponent().'>';
75                    break;
76
77                case DOKU_LEXER_UNMATCHED :
78                    $renderer->doc .= $renderer->_xmlEntities($parameters);
79                    break;
80
81                case DOKU_LEXER_EXIT :
82                    $renderer->doc .= '</'.$this->getPluginComponent().'>';
83                    break;
84            }
85            return true;
86        }
87
88        // unsupported $mode
89        return false;
90    }
91
92    public static function getTag()
93    {
94        list(/* $t */, /* $p */, /* $n */, $c) = explode('_', get_called_class(), 4);
95        return (isset($c) ? $c : '');
96    }
97
98}
99
100