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_divwiki 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->addSpecialPattern('\<dlh\.div\.wiki[^\>]*\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
50                $this->Lexer->addSpecialPattern('\<\/dlh\.div\.wiki\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
51
52        }
53
54
55        /**
56        * Handle matches of the DLH syntax
57        *
58        * @param string       $match   The match of the syntax
59        * @param int          $state   The state of the handler
60        * @param int          $pos     The position in the document
61        * @param Doku_Handler $handler The handler
62        *
63        * @return array Data for the renderer
64        */
65        public function handle($match, $state, $pos, Doku_Handler $handler)
66        {
67
68			if( substr($match,0,3) =='<dl'){
69				return array($state, 'BEGIN',$match);
70
71			}elseif( substr($match,0,3) =='</d'){
72				return array($state, '/END',$match);
73
74			}
75
76			return false;
77
78        } //handle
79
80
81        /**
82        * Render xhtml output or metadata
83        *
84        * @param string        $mode     Renderer mode (supported modes: xhtml)
85        * @param Doku_Renderer $renderer The renderer
86        * @param array         $data     The data from the handler() function
87        *
88        * @return bool If rendering was successful.
89        */
90        public function render($mode, Doku_Renderer $renderer, $data)
91        {
92                if ($mode == 'xhtml') {
93
94                        if($data[1]=='BEGIN'){
95                                // securityLevel loose allows more advanced functionality such as subgraphs to run.
96                                // @todo: this should be an option in the interface.
97                                $renderer->doc .= str_replace('<dlh.div.wiki','<div',$data[2]);;
98								return true;
99
100                        }elseif($data[1]=='/END'){
101                                $renderer->doc .= "</div>";
102								return true;
103
104                        }
105
106                        return false;
107
108
109                } //mode xhtml
110
111        return false;
112
113        } //function render
114
115
116} //class
117
118
119
120
121
122
123