summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorchris <chris@jalakai.co.uk>2007-02-06 02:48:21 +0100
committerchris <chris@jalakai.co.uk>2007-02-06 02:48:21 +0100
commite7856bea477397d242c532d448a8ade3f4014c68 (patch)
tree90deb8db8c036feace7e2f2b73b754921d95952c /inc
parent34dbe7111b03874a70e60229522124c79f45f19e (diff)
downloadrpg-e7856bea477397d242c532d448a8ade3f4014c68.tar.gz
rpg-e7856bea477397d242c532d448a8ade3f4014c68.tar.bz2
refactor renderer header() to separate out adding toc items
adds a new render method toc_additem($id, $text, $level) This allows toc items to be added separately from the header() function, allowing plugins to generate their own table of content items without having to copy dw core code (which may in the future change). darcs-hash:20070206014821-9b6ab-218184e543f6b348e710acc2fe30a8ec329c66a8.gz
Diffstat (limited to 'inc')
-rw-r--r--inc/parser/metadata.php21
-rw-r--r--inc/parser/renderer.php2
-rw-r--r--inc/parser/xhtml.php15
3 files changed, 25 insertions, 13 deletions
diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php
index 1bb14b674..5a9f6a122 100644
--- a/inc/parser/metadata.php
+++ b/inc/parser/metadata.php
@@ -47,25 +47,30 @@ class Doku_Renderer_metadata extends Doku_Renderer {
}
}
- function header($text, $level, $pos) {
+ function toc_additem($id, $text, $level) {
global $conf;
- if (!$this->meta['title']) $this->meta['title'] = $text;
-
- // create a unique header id
- $hid = $this->_headerToLink($text,'true');
-
- //handle TOC
+ //only add items within configured levels
if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
// the TOC is one of our standard ul list arrays ;-)
$this->meta['description']['tableofcontents'][] = array(
- 'hid' => $hid,
+ 'hid' => $id,
'title' => $text,
'type' => 'ul',
'level' => $level-$conf['toptoclevel']+1
);
}
+ }
+
+ function header($text, $level, $pos) {
+
+ if (!$this->meta['title']) $this->meta['title'] = $text;
+
+ // add the header to the TOC
+ $hid = $this->_headerToLink($text,'true');
+ $this->toc_additem($hid, $text, $level);
+
// add to summary
if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF;
}
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index 2b6957692..a6bf0c543 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -70,6 +70,8 @@ class Doku_Renderer extends DokuWiki_Plugin {
function render_TOC() { return ''; }
+ function toc_additem($id, $text, $level) {}
+
function header($text, $level, $pos) {}
function section_edit($start, $end, $level, $name) {}
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 7cccb14ec..266bfcf4a 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -112,20 +112,25 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$this->_xmlEntities($item['title']).'</a></span>';
}
- function header($text, $level, $pos) {
+ function toc_additem($id, $text, $level) {
global $conf;
- // create a unique header id
- $hid = $this->_headerToLink($text,'true');
-
//handle TOC
if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
// the TOC is one of our standard ul list arrays ;-)
- $this->toc[] = array( 'hid' => $hid,
+ $this->toc[] = array( 'hid' => $id,
'title' => $text,
'type' => 'ul',
'level' => $level-$conf['toptoclevel']+1);
}
+ }
+
+ function header($text, $level, $pos) {
+
+ $hid = $this->_headerToLink($text,true);
+
+ //only add items within configured levels
+ $this->toc_additem($hid, $text, $level);
// write the header
$this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';