, Pavel Vitis */ /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_outliner extends DokuWiki_Syntax_Plugin { /** * What kind of syntax are we? */ public function getType() { return 'container'; } public function getAllowedTypes() { return array('container', 'baseonly', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); } /* Accept own mode so nesting is allowed */ public function accepts($mode) { if ($mode == substr(get_class($this), 7)) return true; return parent::accepts($mode); } public function getPType() { return 'block'; } /** * Where to sort in? */ public function getSort() { return 10; } /** * Connect pattern to lexer */ public function connectTo($mode) { $this->Lexer->addEntryPattern( '\n\s*-->[^\n]*(?=.*?\n\s*<--[^\n]*)', $mode, 'plugin_outliner'); } public function postConnect() { $this->Lexer->addExitPattern( '\n\s*<--[^\n]*', 'plugin_outliner'); } /** * Handle the match */ public function handle($match, $state, $pos, Doku_Handler $handler) { global $ID; switch ($state) { case DOKU_LEXER_ENTER: $matches = array(); preg_match('/-->\s*([^#^@]*)([#^@]*)/', $match, $matches); $title = $matches[1]; $outline_id = ''.md5($ID).'_'.$pos; // Test if '^ - opened node' flag is present $opened = (strpos($matches[2], '^') !== false); // Test if '# - no popup' flag is present $nopopup = (strpos($matches[2], '#') !== false); // Test if '$ - link flag is present $link = (strpos($matches[2], '@') !== false); return array($state, $title, $outline_id, $opened, $nopopup, $link); case DOKU_LEXER_EXIT: return array($state); case DOKU_LEXER_UNMATCHED : return array($state, $match); default: return array(); } } /** * Create output */ public function render($format, Doku_Renderer $renderer, $data) { if ($format == 'xhtml') { $state = $data[0]; switch ($state) { case DOKU_LEXER_ENTER: list($state, $title, $outline_id, $opened, $nopopup, $link) = $data; $renderer->doc .= '
doc .= '">
'.html_wikilink($linkId[0],$linkId[1])."
\n"; } else{ $renderer->doc .= '">
'.hsc($title)."
\n"; } break; case DOKU_LEXER_EXIT: $renderer->doc .= "
\n"; break; case DOKU_LEXER_UNMATCHED: $renderer->cdata($data[1]); break; } return true; } return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 :