1<?php
2/**
3 * Creole Plugin, subscript component: Creole style subscripted text
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     LarsDW223
7 */
8
9/**
10 * All DokuWiki plugins to extend the parser/rendering mechanism
11 * need to inherit from this class
12 */
13class syntax_plugin_creole_subscript extends DokuWiki_Syntax_Plugin {
14    var $eventhandler = NULL;
15
16    function getType() { return 'protected'; }
17    function getSort() { return 102; }
18
19    function connectTo($mode) {
20        $this->Lexer->addSpecialPattern(
21                ',,',
22                $mode,
23                'plugin_creole_subscript'
24                );
25    }
26
27    /**
28     * Constructor.
29     */
30    public function __construct() {
31        $this->eventhandler = plugin_load('helper', 'creole_eventhandler');
32        $this->eventhandler->addOnNotify('insert', 'header', 'header',
33                                         'open', 'subscript', NULL,
34                                         array($this, 'onHeaderCallback'));
35        $this->eventhandler->addOnNotify('found', 'emptyline', NULL,
36                                         'open', 'subscript', NULL,
37                                         array($this, 'onHeaderCallback'));
38        $this->eventhandler->addOnNotify('open', 'list', NULL,
39                                         'open', 'subscript', NULL,
40                                         array($this, 'onHeaderCallback'));
41        $this->eventhandler->addOnNotify('open', 'table', NULL,
42                                         'open', 'subscript', NULL,
43                                         array($this, 'onHeaderCallback'));
44    }
45
46    function handle($match, $state, $pos, Doku_Handler $handler) {
47        if ( $this->eventhandler->queuedEventExists ('open', 'subscript', NULL) == false ) {
48            $state = DOKU_LEXER_ENTER;
49        } else {
50            $state = DOKU_LEXER_EXIT;
51        }
52
53        switch ($state) {
54            case DOKU_LEXER_ENTER:
55                $this->eventhandler->notifyEvent('open', 'subscript', NULL, $pos, $match, $handler);
56                $handler->addCall('subscript_open', array(), $pos);
57                break;
58            case DOKU_LEXER_UNMATCHED:
59                $handler->addCall('cdata', array($match), $pos);
60                break;
61            case DOKU_LEXER_EXIT:
62                $this->eventhandler->notifyEvent('close', 'subscript', NULL, $pos, $match, $handler);
63                $handler->addCall('subscript_close', array(), $pos);
64                break;
65        }
66        return true;
67    }
68
69    function render($mode, Doku_Renderer $renderer, $data) {
70        return true;
71    }
72
73    public function onHeaderCallback (creole_syntax_event $myEvent, $pos, $match, $handler) {
74        $this->eventhandler->notifyEvent('close', 'subscript', NULL, $pos, $match, $handler);
75        $handler->addCall('subscript_close', array(), $pos);
76    }
77}
78// vim:ts=4:sw=4:et:enc=utf-8:
79