-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.php
62 lines (53 loc) · 1.87 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* InlineTOC-Plugin: Renders the page's toc inside the page content
*
* @license GPL v2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreone
*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_inlinetoc extends DokuWiki_Action_Plugin {
/**
* Register event handlers
*/
function register(&$controller) {
$controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'handle_act_render', array());
$controller->register_hook('RENDERER_CONTENT_POSTPROCESS', 'AFTER', $this, 'handle_renderer_content_postprocess', array());
}
/**
* Make sure the other toc is not printed
*/
function handle_act_render(&$event, $param) {
global $ID;
global $INFO;
if (p_get_metadata($ID, 'movetoc')) {
$INFO['prependTOC'] = false;
}
}
/**
* Replace our placeholder with the actual toc content
*/
function handle_renderer_content_postprocess(&$event, $param) {
global $TOC;
if ($TOC) {
$html = '<div id="inlinetoc2" class="inlinetoc2">' . html_buildlist($TOC, 'inlinetoc2', array($this, 'html_list_inlinetoc2')) . '</div>';
$event->data[1] = str_replace('<!-- INLINETOCPLACEHOLDER -->',
$html,
$event->data[1]);
}
}
/**
* Callback for html_buildlist.
* Builds list items with inlinetoc2 printable class instead of dokuwiki's toc class which isn't printable.
*/
function html_list_inlinetoc2($item){
if(isset($item['hid'])){
$link = '#'.$item['hid'];
}else{
$link = $item['link'];
}
return '<span class="li"><a href="'.$link.'" class="inlinetoc2">'. hsc($item['title']).'</a></span>';
}
}