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_comment 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\.\*\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
50        }
51
52
53        public function postConnect()
54        {
55                $this->Lexer->addExitPattern('\<\/dlh\.\*\>','plugin_dirtylittlehelper_'.$this->getPluginComponent());
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( substr($match,0,3) =='<dl'){
76                                        return array($state, 'BEGIN');
77                                }
78
79                        case DOKU_LEXER_UNMATCHED :
80								return array($state, 'UNMATCHED');
81
82                        case DOKU_LEXER_EXIT :
83                                if( substr($match,0,3) =='</d'){
84                                        return array($state, '/END');
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						// comments will not be shown -> do nothing
106                        if($data[1]=='BEGIN'){
107								return true;
108
109                        }elseif($data[1]=='/END'){
110								return true;
111
112
113                        }elseif($data[1]=='UNMATCHED'){
114								return true;
115                        }
116
117                        return false;
118
119
120                } //mode xhtml
121
122        return false;
123
124        } //function render
125
126
127} //class
128
129
130
131
132
133
134