1<?php
2/**
3 * TocTweak plugin for DokuWiki; Syntax closetoc
4 * set toggle state initially closed (by script.js)
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Satoshi Sahara <sahara.satoshi@gmail.com>
8 */
9
10if (!defined('DOKU_INC')) die();
11
12class syntax_plugin_toctweak_closetoc extends DokuWiki_Syntax_Plugin {
13
14    protected $mode;
15    protected $pattern = array();
16
17    function __construct() {
18        $this->mode = substr(get_class($this), 7); // drop 'syntax_' from class name
19
20        // syntax patterns
21        $this->pattern[5] = '~~CLOSETOC~~'; // DOKU_LEXER_SPECIAL
22    }
23
24
25    function getType() { return 'substition'; }
26    function getPType(){ return 'block'; }
27    function getSort() { return 990; }
28
29    /**
30     * Connect pattern to lexer
31     */
32    function connectTo($mode) {
33        $this->Lexer->addSpecialPattern($this->pattern[5], $mode, $this->mode);
34    }
35
36    /**
37     * Handle the match
38     */
39    function handle($match, $state, $pos, Doku_Handler $handler) {
40        global $ID;
41        return array($ID);
42    }
43
44    /**
45     * Create output
46     */
47    function render($format, Doku_Renderer $renderer, $data) {
48        global $ID;
49        if (($format == 'metadata') && ($data[0] == $ID)) {
50             $renderer->meta['toc']['initial_state'] = -1;
51        }
52        return true;
53    }
54
55}
56
57