1<?php
2/**
3* DokuWiki Plugin dirtylittlehelper (Syntax Component)
4*
5* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6* @author  KalleAPunkt
7*/
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) {
11die();
12}
13
14class syntax_plugin_dirtylittlehelper_style extends DokuWiki_Syntax_Plugin
15{
16        var $dlh_handle = '';
17
18        /**
19        * @return string Syntax mode type
20        */
21        public function getType()
22        {
23                return 'substition';
24        }
25
26        /**
27        * @return string Paragraph type
28        */
29        public function getPType()
30        {
31                return 'normal';
32        }
33
34        /**
35        * @return int Sort order - Low numbers go before high numbers
36        */
37        public function getSort()
38        {
39                return 150;
40        }
41
42        /**
43        * Connect lookup pattern to lexer.
44        *
45        * @param string $mode Parser mode
46        */
47        public function connectTo($mode)
48        {
49                $this->Lexer->addEntryPattern('\<dlh\.style\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
50        }
51
52        public function postConnect()
53        {
54                $this->Lexer->addExitPattern('\<\/dlh\.style\>','plugin_dirtylittlehelper_'.$this->getPluginComponent());
55
56        }
57
58
59        /**
60        * Handle matches of the DLH syntax
61        *
62        * @param string       $match   The match of the syntax
63        * @param int          $state   The state of the handler
64        * @param int          $pos     The position in the document
65        * @param Doku_Handler $handler The handler
66        *
67        * @return array Data for the renderer
68        */
69        public function handle($match, $state, $pos, Doku_Handler $handler)
70        {
71
72                switch ($state) {
73
74                        case DOKU_LEXER_ENTER:
75                                if($match=='<dlh.style>'){
76                                        return array($state, 'STYLE',$match);
77                                }
78
79                        case DOKU_LEXER_UNMATCHED :
80								return array($state, 'UNMATCHED', $match);
81
82                        case DOKU_LEXER_EXIT :
83                                if($match=='</dlh.style>'){
84                                        return array($state, '/STYLE',$match);
85                                }
86                }
87        return false;
88
89        } //handle
90
91
92        /**
93        * Render xhtml output or metadata
94        *
95        * @param string        $mode     Renderer mode (supported modes: xhtml)
96        * @param Doku_Renderer $renderer The renderer
97        * @param array         $data     The data from the handler() function
98        *
99        * @return bool If rendering was successful.
100        */
101        public function render($mode, Doku_Renderer $renderer, $data)
102        {
103                if ($mode == 'xhtml') {
104
105                        if($data[1]=='STYLE'){
106                                // securityLevel loose allows more advanced functionality such as subgraphs to run.
107                                // @todo: this should be an option in the interface.
108                                $renderer->doc .= '<style>';
109								return true;
110
111                        }elseif($data[1]=='/STYLE'){
112                                $renderer->doc .= "</style>";
113								return true;
114
115
116                        }elseif($data[1]=='UNMATCHED'){
117                                $renderer->doc .= $data[2];
118								return true;
119                        }
120
121                        return false;
122
123
124                } //mode xhtml
125
126        return false;
127
128        } //function render
129
130
131} //class
132
133
134
135
136
137
138