summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2007-08-05 15:24:05 +0200
committerAndreas Gohr <andi@splitbrain.org>2007-08-05 15:24:05 +0200
commitb8595a660455f6778266779753c6238127664a28 (patch)
tree29e0a132e510d6b98f1985b9f4e876a5351d3e64 /inc/parser
parent71f7bde7834ef576e5312e68d5e739bfe70afbcb (diff)
downloadrpg-b8595a660455f6778266779753c6238127664a28.tar.gz
rpg-b8595a660455f6778266779753c6238127664a28.tar.bz2
separated TOC from page
This patch introduces a tpl_toc() function which can be used to freely place the Table of Contents in a template. When used, tpl_content should be called with a parameter of false to supress the automatic TOC placement. Note: if tpl_toc() us run *before* tpl_content(), TOCs will not work in the preview. A work around is to run tpl_content() in a output buffer first. This patch also adds a getTOC() function for admin plugins which allows plugin authors to put create their own TOC which will be placed correctly in the template. A convenience function html_mktocitem() is available. The config manager was adjusted to make ue of this new feature, but some bugs might remain. darcs-hash:20070805132405-7ad00-77d2c3cdf66cc62b2d408cc6580f938636a109af.gz
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/metadata.php3
-rw-r--r--inc/parser/xhtml.php43
2 files changed, 8 insertions, 38 deletions
diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php
index 5f06865cf..6e93fd61f 100644
--- a/inc/parser/metadata.php
+++ b/inc/parser/metadata.php
@@ -42,6 +42,9 @@ class Doku_Renderer_metadata extends Doku_Renderer {
}
function document_end(){
+ // store internal info in metadata (notoc,nocache)
+ $this->meta['internal'] = $this->info;
+
if (!$this->meta['description']['abstract']){
// cut off too long abstracts
$this->doc = trim($this->doc);
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 30e154af6..e22298fa3 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -82,55 +82,22 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$this->doc .= '</div>'.DOKU_LF;
}
- // prepend the TOC
- if($this->info['toc']){
- $this->doc = $this->render_TOC($this->toc).$this->doc;
+ // Prepare the TOC
+ if($this->info['toc'] && is_array($this->toc) && count($this->toc) > 2){
+ global $TOC;
+ $TOC = $this->toc;
}
// make sure there are no empty paragraphs
$this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
}
- /**
- * Return the TOC rendered to XHTML
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- */
- function render_TOC($toc=null){
- if(is_null($toc) && is_array($this->toc)) $toc = $this->toc;
-
- if(count($toc) < 3) return '';
- global $lang;
- $out = '<!-- TOC START -->'.DOKU_LF;
- $out .= '<div class="toc">'.DOKU_LF;
- $out .= '<div class="tocheader toctoggle" id="toc__header">';
- $out .= $lang['toc'];
- $out .= '</div>'.DOKU_LF;
- $out .= '<div id="toc__inside">'.DOKU_LF;
- $out .= html_buildlist($toc,'toc',array(__CLASS__,'_tocitem'));
- $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
- $out .= '<!-- TOC END -->'.DOKU_LF;
- return $out;
- }
-
- /**
- * Callback for html_buildlist
- */
- function _tocitem($item){
- return '<span class="li"><a href="#'.$item['hid'].'" class="toc">'.
- Doku_Renderer_xhtml::_xmlEntities($item['title']).'</a></span>';
- }
-
function toc_additem($id, $text, $level) {
global $conf;
//handle TOC
if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
- // the TOC is one of our standard ul list arrays ;-)
- $this->toc[] = array( 'hid' => $id,
- 'title' => $text,
- 'type' => 'ul',
- 'level' => $level-$conf['toptoclevel']+1);
+ $this->toc[] = html_mktocitem("#$id", $text, $level);
}
}