1<?php
2/**
3 * Creole Plugin, strong component: Creole style strong 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_strong extends DokuWiki_Syntax_Plugin {
14    var $eventhandler = NULL;
15
16    function getInfo() {
17        return array(
18                'author' => 'Gina Häußge, Michael Klier, Esther Brunner, LarsDW223',
19                'email'  => 'dokuwiki@chimeric.de',
20                'date'   => '2015-08-29',
21                'name'   => 'Creole Plugin, strong component',
22                'desc'   => 'Creole style strong text',
23                'url'    => 'http://wiki.splitbrain.org/plugin:creole',
24                );
25    }
26
27    function getType() { return 'protected'; }
28    function getSort() { return 9; }
29
30    function connectTo($mode) {
31        $this->Lexer->addSpecialPattern(
32                '\*\*',
33                $mode,
34                'plugin_creole_strong'
35                );
36    }
37
38    /**
39     * Constructor.
40     */
41    public function __construct() {
42        $this->eventhandler = plugin_load('helper', 'creole_eventhandler');
43        $this->eventhandler->addOnNotify('insert', 'header', 'header',
44                                         'open', 'strong', NULL,
45                                         array($this, 'onHeaderCallback'));
46        $this->eventhandler->addOnNotify('found', 'emptyline', NULL,
47                                         'open', 'strong', NULL,
48                                         array($this, 'onHeaderCallback'));
49        $this->eventhandler->addOnNotify('open', 'list', NULL,
50                                         'open', 'strong', NULL,
51                                         array($this, 'onHeaderCallback'));
52        $this->eventhandler->addOnNotify('open', 'table', NULL,
53                                         'open', 'strong', NULL,
54                                         array($this, 'onHeaderCallback'));
55    }
56
57    function handle($match, $state, $pos, Doku_Handler $handler) {
58        if ( $this->eventhandler->queuedEventExists ('open', 'strong', NULL) == false ) {
59            $state = DOKU_LEXER_ENTER;
60        } else {
61            $state = DOKU_LEXER_EXIT;
62        }
63
64        switch ($state) {
65            case DOKU_LEXER_ENTER:
66                $this->eventhandler->notifyEvent('open', 'strong', NULL, $pos, $match, $handler);
67                $handler->addCall('strong_open', array(), $pos);
68                break;
69            case DOKU_LEXER_UNMATCHED:
70                $handler->addCall('cdata', array($match), $pos);
71                break;
72            case DOKU_LEXER_EXIT:
73                $this->eventhandler->notifyEvent('close', 'strong', NULL, $pos, $match, $handler);
74                $handler->addCall('strong_close', array(), $pos);
75                break;
76        }
77        return true;
78    }
79
80    function render($mode, Doku_Renderer $renderer, $data) {
81        return true;
82    }
83
84    public function onHeaderCallback (creole_syntax_event $myEvent, $pos, $match, $handler) {
85        $this->eventhandler->notifyEvent('close', 'strong', NULL, $pos, $match, $handler);
86        $handler->addCall('strong_close', array(), $pos);
87    }
88}
89// vim:ts=4:sw=4:et:enc=utf-8:
90