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_tablewiki extends DokuWiki_Syntax_Plugin
15{
16        var $dlh_handle = '';
17		var $dlh_tmp = '';
18
19        /**
20        * @return string Syntax mode type
21        */
22        public function getType()
23        {
24                return 'substition';
25        }
26
27        /**
28        * @return string Paragraph type
29        */
30        public function getPType()
31        {
32                return 'normal';
33        }
34
35        /**
36        * @return int Sort order - Low numbers go before high numbers
37        */
38        public function getSort()
39        {
40                return 150;
41        }
42
43        /**
44        * Connect lookup pattern to lexer.
45        *
46        * @param string $mode Parser mode
47        */
48        public function connectTo($mode)
49        {
50                $this->Lexer->addSpecialPattern('\<dlh\.table\.wiki[^\>]*\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
51                $this->Lexer->addSpecialPattern('\<\/dlh\.table\.wiki\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
52
53				$this->Lexer->addSpecialPattern('\<dlh\.caption\.wiki[^\>]*\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
54                $this->Lexer->addSpecialPattern('\<\/dlh\.caption\.wiki\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
55
56				$this->Lexer->addSpecialPattern('\<dlh\.th\.wiki[^\>]*\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
57                $this->Lexer->addSpecialPattern('\<\/dlh\.th\.wiki\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
58
59				$this->Lexer->addSpecialPattern('\<dlh\.tr\.wiki[^\>]*\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
60                $this->Lexer->addSpecialPattern('\<\/dlh\.tr\.wiki\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
61
62				$this->Lexer->addSpecialPattern('\<dlh\.td\.wiki[^\>]*\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
63                $this->Lexer->addSpecialPattern('\<\/dlh\.td\.wiki\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
64
65		}
66
67
68        /**
69        * Handle matches of the DLH syntax
70        *
71        * @param string       $match   The match of the syntax
72        * @param int          $state   The state of the handler
73        * @param int          $pos     The position in the document
74        * @param Doku_Handler $handler The handler
75        *
76        * @return array Data for the renderer
77        */
78        public function handle($match, $state, $pos, Doku_Handler $handler)
79        {
80
81			if( substr($match,0,3) =='<dl'){
82				return array($state, 'BEGIN',$match);
83
84			}elseif( substr($match,0,3) =='</d'){
85				return array($state, '/END',$match);
86
87			}
88
89			return false;
90
91        } //handle
92
93
94        /**
95        * Render xhtml output or metadata
96        *
97        * @param string        $mode     Renderer mode (supported modes: xhtml)
98        * @param Doku_Renderer $renderer The renderer
99        * @param array         $data     The data from the handler() function
100        *
101        * @return bool If rendering was successful.
102        */
103        public function render($mode, Doku_Renderer $renderer, $data)
104        {
105                if ($mode == 'xhtml') {
106
107                        if($data[1]=='BEGIN'){
108                                // securityLevel loose allows more advanced functionality such as subgraphs to run.
109                                // @todo: this should be an option in the interface.
110                                $renderer->doc .= str_replace('.wiki' , '' ,  str_replace('<dlh.','<',$data[2]) );
111								return true;
112
113                        }elseif($data[1]=='/END'){
114                                $renderer->doc .= str_replace('.wiki' , '' ,  str_replace('</dlh.','</',$data[2]) );
115								return true;
116
117                        }
118
119                        return false;
120
121
122                } //mode xhtml
123
124        return false;
125
126        } //function render
127
128
129} //class
130
131
132
133
134
135
136