1<?php
2/**
3 * InlineTOC-Plugin: Renders the page's toc inside the page content
4 *
5 * @license GPL v2 (http://www.gnu.org/licenses/gpl.html)
6 * @author  Andreone
7 */
8
9if (!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/');
10require_once(DOKU_INC . 'inc/init.php');
11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
12require_once(DOKU_PLUGIN . 'syntax.php');
13
14class syntax_plugin_inlinetoc extends DokuWiki_Syntax_Plugin {
15
16    /**
17     * What kind of syntax are we?
18     */
19    function getType() {
20        return 'substition';
21    }
22
23    /**
24     * Where to sort in? (took the same as for ~~NOTOC~~)
25     */
26    function getSort() {
27        return 30;
28    }
29
30    /**
31     * What kind of type are we?
32     */
33    function getPType() {
34            return 'block';
35    }
36
37    /**
38     * Connect pattern to lexer
39     */
40    function connectTo($mode) {
41        $this->Lexer->addSpecialPattern('{{INLINETOC}}', $mode, 'plugin_inlinetoc');
42    }
43
44    /**
45     * Handle the match
46     */
47    function handle($match, $state, $pos, &$handler) {
48        return '';
49    }
50
51    /**
52     * Add placeholder to cached page (will be replaced by action component)
53     */
54    function render($mode, &$renderer, $data) {
55
56    	if ($mode == 'metadata') {
57			$renderer->meta['movetoc'] = true;
58			return true;
59		}
60
61        $renderer->doc .= '<!-- INLINETOCPLACEHOLDER -->';
62    }
63}
64