1<?php
2/**
3 * Wiki-Style Script - auxiliary plugin
4 * Add <span class="wss-nowiki-section"> to avoid handling nowiki components by the script
5 * Almost copied from DokuWiki units' function
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     HokkaidoPerson <dosankomali@yahoo.co.jp>
9 */
10
11 // must be run within Dokuwiki
12if(!defined('DOKU_INC')) die();
13
14class syntax_plugin_wikistyle2html_pcnt extends DokuWiki_Syntax_Plugin {
15
16    function getType(){
17        return 'substition';
18    }
19
20    function getSort(){
21        return 169;    // before Doku_Parser_Mode_unformatted
22    }
23
24    /**
25     * Connect lookup pattern to lexer
26     */
27    function connectTo($mode) {
28        $this->Lexer->addEntryPattern('%%(?=.*%%)',$mode,'plugin_wikistyle2html_pcnt');
29    }
30
31    function postConnect() {
32        $this->Lexer->addExitPattern('%%','plugin_wikistyle2html_pcnt');
33    }
34
35    /**
36     * Handle the match
37     */
38    function handle($match, $state, $pos, Doku_Handler $handler) {
39        if ( $state == DOKU_LEXER_UNMATCHED ) {
40            return array($match, $state);
41        }
42    }
43
44    /**
45     * Create output
46     */
47    function render($format, Doku_Renderer $renderer, $data) {
48        if ( $data[1] == DOKU_LEXER_UNMATCHED ) {
49            $renderer->doc .= '<span class="wss-nowiki-section">' . hsc($data[0]) . '</span>';
50        }
51
52    }
53}
54