From b8595a660455f6778266779753c6238127664a28 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 5 Aug 2007 15:24:05 +0200 Subject: 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 --- inc/parser/metadata.php | 3 +++ inc/parser/xhtml.php | 43 +++++-------------------------------------- 2 files changed, 8 insertions(+), 38 deletions(-) (limited to 'inc/parser') 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 .= ''.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('#

\s*

#','',$this->doc); } - /** - * Return the TOC rendered to XHTML - * - * @author Andreas Gohr - */ - function render_TOC($toc=null){ - if(is_null($toc) && is_array($this->toc)) $toc = $this->toc; - - if(count($toc) < 3) return ''; - global $lang; - $out = ''.DOKU_LF; - $out .= '
'.DOKU_LF; - $out .= '
'; - $out .= $lang['toc']; - $out .= '
'.DOKU_LF; - $out .= '
'.DOKU_LF; - $out .= html_buildlist($toc,'toc',array(__CLASS__,'_tocitem')); - $out .= '
'.DOKU_LF.'
'.DOKU_LF; - $out .= ''.DOKU_LF; - return $out; - } - - /** - * Callback for html_buildlist - */ - function _tocitem($item){ - return ''. - Doku_Renderer_xhtml::_xmlEntities($item['title']).''; - } - 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); } } -- cgit v1.2.3