====== Folding Sections Plugin ======
Here is my folding section plugin. I am still working on this, so any feedback is appreciated.
When you do a search and go to a page that has folded sections, not only do the sections not unfold nor highlight inside the section, but they won't unfold. I know where the problem is, but I am trying to find a way to fix it using the plugin facilities.
I want to find a way to automatically close out the last section at the end of a page, like other heading levels do. Right now you have to close out the last section or your page layout and XHTML compliance is broken.
To use this plugin created the directory ''foldsec'' inside the plugins directory. Next create a file named syntax.php and copy the code below into it. So, you have a file ''lib/plugins/foldsec/syntax.php'' containing the text below.
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_foldsec extends DokuWiki_Syntax_Plugin {
function getInfo(){
return array(
'author' => 'Chris Stoll',
'email' => 'stollcri [at] gmail [dot] com',
'date' => '2005-06-09',
'name' => 'Folding Sections',
'desc' => 'Allows section to fold and unfold. (Sometimes also called collpsible headings.)',
'url' => 'http://www.dokuwiki.org/plugin:folding_sections',
);
}
function getType(){
return 'baseonly';
}
function getPType(){
return 'block';
}
function getSort(){
// parse this before the other headers
return 45;
}
function connectTo($mode) {
// match between eight consecutive equal signs
$this->Lexer->addSpecialPattern('[ \t]*={8,}[^\n]+={2,}[ \t]*(?=\n)',$mode,'plugin_foldsec');
// match between two consecutive tildes
$this->Lexer->addSpecialPattern('[ \t]*~{2,}[^\n]+~{2,}[ \t]*(?=\n)',$mode,'plugin_foldsec');
}
function handle($match, $state, $pos, &$handler){
// strip off the tags
if (strpos($match,'========')===false) {
$match = trim(substr(trim($match),2,-2));
$process = false;
} else {
$match = trim(substr(trim($match),8,-8));
$process = true;
}
return array($pos,$match,$process);
}
function render($mode, &$renderer, $data) {
if($mode == 'xhtml'){
$pos=cleanID($data[0]);
$title=cleanID($data[1]);
$process=$data[2];
if (!$process) {
if ($data[1]=='FOLD:END' && !$renderer->info['foldsecend']) {
$renderer->info['foldsecend']=true;
$renderer->doc .= '
'.DOKU_LF; // for XML/XHTML compliance } return true; } if ($renderer->info['foldsec']) { // close out the previos section, unless it was already closed if (!$renderer->info['foldsecend']) { $renderer->doc .= '
'.DOKU_LF; // for XML/XHTML compliance $renderer->doc .= ''.DOKU_LF; } } else { // add only if this is the first folding section // // I left these in here so that I can simply distribute one file // and it would cause less problems for inexperienced users. // Just drop in this file and it should work. - stollcri // $renderer->doc .= ''.DOKU_LF; // for XML/XHTML compliance $renderer->doc .= DOKU_LF; $renderer->doc .= ''.DOKU_LF; $renderer->doc .= DOKU_LF; $renderer->doc .= ''.DOKU_LF; $renderer->doc .= DOKU_LF; } $renderer->doc .= ''.DOKU_LF; $renderer->doc .= '