This is a hack of the new parser that will let you have folding/collapsing sections. It is more work to add folding sections with the new parser, but I think it is worth it. I did this using the 2005-05-09 version, but it should work for the 2005-05-07 release as well.
I like this feature a lot, and I use it on long FAQ pages. This only provides normally closed sections, since that is what I use on my FAQ pages. I changed from using the -+, ++, +- syntax because it was a lot easier to integrate ======== with the new parser. Sorry. But, with DokuWiki it is easy to use a regular expression at the file system level to replace all those tags.
In inc/parser/handler.php add this at line 76:
'========'=>6, // folding section support - stollcri
In inc/parser/parser.php add this on lines 186-191:
// folding section support - stollcri $this->Lexer->addSpecialPattern( '[ \t]*={8,}[^\n]+={2,}[ \t]*\n', 'base', 'header' );
In inc/parser/xhtml.php replace lines 111-113 with this:
// folding section support - stollcri if($level == $conf['foldlevel']){ // add button for last section if any if($this->lastsec) $this->_secedit($this->lastsec,$pos-1); // remember current position $this->lastsec = $pos; $this->doc .= DOKU_LF; $this->doc .= '<a name="'.$this->_headerToLink($text).'"></a>'.DOKU_LF; $this->doc .= '<h'.$level.' onclick="fold(\''.$this->_headerToLink($text).'_'.$pos.'\');">'.DOKU_LF; $this->doc .= $this->_xmlEntities($text); $this->doc .= '</h'.$level.'>'.DOKU_LF; $this->doc .= '<div class="foldsec" id="'.$this->_headerToLink($text).'_'.$pos.'" style="display:none";>'; $this->meta['foldsec'] = TRUE; } else { $this->doc .= DOKU_LF.'<a name="'.$this->_headerToLink($text).'"></a><h'.$level.'>'; $this->doc .= $this->_xmlEntities($text); $this->doc .= "</h$level>".DOKU_LF; $this->meta['foldsec'] = FALSE; }
In inc/parser/xhtml.php add this on lines 139-140 (right after $this->doc .= DOKU_LF.'</div>'.DOKU_LF;):
// folding section support - stollcri if($this->meta['foldsec']) $this->doc .= '</div>';
In conf/local.php at the end before the closing tag:
// Enable folding section support (stollcri) $conf['foldlevel'] = 6;
In script.js add this at the end:
// Folding section support (stollcri) function fold( divid ) { var divstyle = document.getElementById(divid).style; var showhide = (divstyle.display == 'none')?'block':'none'; divstyle.display = showhide; }
In tpl/default/design.css add this at the end:
/* Folding section support (stollcri) */ h6 { cursor: pointer; color: #436976; background-color: transparent; font-family: "Lucida Grande", Verdana, Lucida, Helvetica, Arial, sans-serif; font-size: 120%; font-weight: bold; margin-left: 40px; margin-right: 0; margin-top: 0; margin-bottom: 0; padding-left: 0; padding-right: 0; padding-top: 0.5em; padding-bottom: 0; border-bottom: 1px solid #8cacbb; clear: left; } h6:hover { color:#FF9933; text-decoration:none; } div.foldsec { color: black; background-color: #DEE7EC; margin-left: 45px; margin-right: 0; margin-top: 0; margin-bottom: 0; padding-left: 8px; padding-right: 0; padding-top: 0; padding-bottom: 0; border-right: 1px solid #8cacbb; clear: left; }
In inc/html.php add this at line 298: (this is so that the folding sections work when search results are highlighted)
// make folding sections work when highlighting - stollcri if(isset($query) && $query!=''){ // unfold all sections so highlight are not hidden $html = preg_replace('/style="display:none"/', '/style="display:block"', $html); // un-escape single quotes $html = preg_replace("/fold\(\\\'/", "fold('", $html); $html = preg_replace("/\\\'\);/", "');", $html); }
To use the folding section you must use ”========”, eight equal signs, like this:
======== My folding section ======== This will be folded by default
This tip was written before the plugin interface was introduced. The folded plugin is based on this hack and does the same, more or less. So I guess there is no real use for implementing folding support the way it is described here. — Esther Brunner 2005-11-29 15:54