1<?php
2/**
3 * Plugin Tab: Inserts "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" into the document for every <tab> it encounters
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Juergen-aus-Koeln (previous Tim Skoch <timskoch@hotmail.com>)
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'syntax.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_tab extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * return some info
21     */
22    function getInfo(){
23        return array(
24            'author' => 'Tim Skoch',
25            'email'  => 'timskoch@hotmail.com',
26            'date'   => '2018-02-06',
27            'name'   => 'Tab Plugin',
28            'desc'   => 'Inserts "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" into the html of the document for every <tab> it encounters',
29            'url'    => 'http://www.dokuwiki.org/wiki:plugins:tab',
30        );
31    }
32
33    /**
34     * What kind of syntax are we?
35     */
36    function getType(){
37        return 'substition';
38    }
39
40    /**
41     * What kind of syntax do we allow (optional)
42     */
43//    function getAllowedTypes() {
44//        return array();
45//    }
46
47    /**
48     * What about paragraphs? (optional)
49     */
50//    function getPType(){
51//        return 'normal';
52//    }
53
54    /**
55     * Where to sort in?
56     */
57    function getSort(){
58        return 999;
59    }
60
61
62    // Connect pattern to lexer
63    function connectTo($mode) {
64      $this->Lexer->addSpecialPattern('<tab\d*>', $mode, 'plugin_tab'); }
65
66    // Handle the match
67    function handle($match, $state, $pos, Doku_Handler $handler){
68        $match = substr($match,4,-1);             //strip markup from start and end
69
70        if ((strlen($match)>0) && ($match >0)) {  // add as many space as defined if value is positive
71            $data .= str_repeat('&#160;', $match);
72        }
73        else {                                    // if standard tab is used then insert 5 spaces
74          $data = '&#160;&#160;&#160;&#160;&#160;';
75        }
76        return $data;
77    }
78
79    // Create output
80    function render($mode, Doku_Renderer $renderer, $data) {
81        if($mode == 'xhtml'){
82            $renderer->doc .= $data;
83            return true;         }
84        return false;
85    }
86
87}
88