1<?php
2/**
3 * DokuWiki Plugin textrotate (Syntax Component)
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author  lisps
7 * @author  peterfromearth
8 */
9
10class syntax_plugin_textrotate extends DokuWiki_Syntax_Plugin {
11
12    public function getType(){ return 'formatting'; }
13    public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
14    public function getSort(){ return 66; }
15
16    /*
17     * Connect pattern to lexer
18     */
19    function connectTo($mode) {
20		$this->Lexer->addEntryPattern(
21		'!!(?=.*!!)',
22		$mode,
23		'plugin_textrotate'
24		);
25	}
26
27	function postConnect() {
28		$this->Lexer->addExitPattern(
29		'!!',
30		'plugin_textrotate'
31		);
32	}
33
34    /*
35     * Handle the matches
36     */
37    function handle($match, $state, $pos, Doku_Handler $handler){
38
39		switch ($state) {
40			case DOKU_LEXER_ENTER :
41			    return [$state, ''];
42			case DOKU_LEXER_UNMATCHED :
43				return [$state, $match];
44			case DOKU_LEXER_EXIT :
45				return [$state, ''];
46		}
47		return [];
48    }
49
50    /*
51     * Create output
52     */
53    function render($mode, Doku_Renderer $renderer, $data)
54	{
55		list($state, $opt) = $data;
56
57		if($mode != 'xhtml') return false;
58		switch ($state) {
59		    case DOKU_LEXER_ENTER :
60		        if($mode === 'xhtml') {
61		          $renderer->doc .= "<span class='plugin_textrotate_rotated'>";
62		        }
63		        break;
64
65		    case DOKU_LEXER_UNMATCHED :
66		        $renderer->doc .= $renderer->_xmlEntities($opt);
67		        break;
68		    case DOKU_LEXER_EXIT :
69		        if($mode === 'xhtml') {
70		          $renderer->doc .= '</span>';
71		        }
72		        break;
73		}
74		return true;
75	}
76}
77
78