Updating branch refs/heads/master to a82faa6e504ce80bcd99d499503b2311b178c7e5 (commit) from 4423fae2c7f227c1b5b19486d95e30751265b133 (commit)
commit a82faa6e504ce80bcd99d499503b2311b178c7e5 Author: Nick Schermer <n...@xfce.org> Date: Tue Jan 3 19:59:07 2012 +0100 Add the dl plugin. lib/plugins/dl/style.css | 8 ++ lib/plugins/dl/syntax.php | 158 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 0 deletions(-) diff --git a/lib/plugins/dl/style.css b/lib/plugins/dl/style.css new file mode 100644 index 0000000..083fa50 --- /dev/null +++ b/lib/plugins/dl/style.css @@ -0,0 +1,8 @@ +div.dokuwiki dt { + font-weight: bold; +} +div.dokuwiki dd { + margin-left: 20px; + margin-top: 0.5em; + margin-bottom: 1em; +} diff --git a/lib/plugins/dl/syntax.php b/lib/plugins/dl/syntax.php new file mode 100644 index 0000000..1d5d979 --- /dev/null +++ b/lib/plugins/dl/syntax.php @@ -0,0 +1,158 @@ + <?php + 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'); + + /** Declare Definition List. + + Declares a HTML - Definition-List + + Indentation: First either no indentation, or any number of spaces. + Title: Line starts with (optional) spaces and a question mark + Definition: Line starts with (opt.) spaces and an exclamation mark + End: Multiple lines are allowed, so an empty line declares the end + Subdefinitions: Indent more + + Syntax: + ? Definition Title + Multiple lines are possible + ! Definition Description + ? Definition Title1 + ? Definition Title2 + ! Definition Description1 + ! Definition Description2 + ! Definition Description3 + ? Subdefinition + ! Description + ! Back + ? Again deeper + + License: LGPL + */ + class syntax_plugin_dl extends DokuWiki_Syntax_Plugin { + + function getInfo() { + return array('author' => 'Marc Wäckerlin', + 'email' => 'marc [at] waeckerlin [dot-org]', + 'name' => 'Definition List Plugin', + 'desc' => 'HTML Definition List', + 'url' => 'http://marc.waeckerlin.org'); + } + + function getType() { + return 'container'; + } + + function getAllowedTypes() { + return array('container','substition','protected','disabled','formatting','paragraphs'); + } + + function getPType() { + return 'block'; + } + + function getSort() { + return 10; + } + + function connectTo($mode) { + $this->Lexer->addEntryPattern('^ *\!', $mode, 'plugin_dl'); + $this->Lexer->addEntryPattern('^ *\?[^\n]*', $mode, 'plugin_dl'); + } + + function postConnect() { + $this->Lexer->addPattern('\n *\!', 'plugin_dl'); + $this->Lexer->addPattern('^ *\!', 'plugin_dl'); + $this->Lexer->addPattern('\n *\?[^\n]*', 'plugin_dl'); + $this->Lexer->addPattern('^ *\?[^\n]*', 'plugin_dl'); + $this->Lexer->addExitPattern('\n$', 'plugin_dl'); + } + + function handle($match, $state, $pos, &$handler){ + if (($state==DOKU_LEXER_MATCHED || + $state==DOKU_LEXER_ENTER) + && ereg('\?', $match)) { + $title = + htmlspecialchars(ereg_replace("\n* *\?(.*)", '\1', $match)); + $match = ereg_replace("(\n* *\?).*", '\1', $match); + } else { + $title = ''; + } + return array($match, $state, $title); + } + + function render($format, &$renderer, $data) { + static $close = ''; + static $level = 0; + static $last_neesting = 0; + static $indent = array(); + static $dlstart = "\n<dl>"; + static $dlend = "\n</dl>"; + static $dtstart = "\n<dt>"; + static $dtend = "</dt>"; + static $ddstart = "\n<dd>"; + static $ddend = "</dd>"; + list($match, $state, $title) = $data; + while ($match[0]=="\n") $match=substr($match, 1); + $neesting = strlen($match); + if ($state==DOKU_LEXER_MATCHED) { + if ($last_neesting<$neesting) { + $renderer->doc .= $close.$ddstart.$dlstart; + $close = ''; + $indent[++$level] = $neesting; + } else if ($last_neesting>$neesting) { + $renderer->doc .= $close.$dlend.($level?$ddend:''); + $close = ''; + while ($level && $indent[--$level]>$neesting) + $renderer->doc .= $dlend.($level?$ddend:''); + } + $last_neesting = $neesting; + } + switch ($state) { + case DOKU_LEXER_ENTER: { + $last_neesting = $neesting; + if ($level>0) $renderer->doc .= $close; + for (; $level>0; --$level) + $renderer->doc .= $dlend.($level!=1?$ddend:''); + $renderer->doc .= $dlstart; + if (ereg('\?', $match)) { + $renderer->doc .= $dtstart; + $close = $dtend; + if ($title!='') + $renderer->doc .= '<a name="'.$title.'"></a>'.$title; + } else if (ereg('!', $match)) { + $renderer->doc .= $ddstart; + $close = $ddend; + } else return false; + $indent[++$level] = $neesting; + } return true; + case DOKU_LEXER_EXIT: { + $renderer->doc .= $close; + for (; $level>0; --$level) + $renderer->doc .= $dlend.($level!=1?$ddend:''); + $renderer->doc .= "\n"; + } return true; + case DOKU_LEXER_MATCHED: { + if (ereg('\?', $match)) { + $renderer->doc .= $close; + $renderer->doc .= $dtstart; + $close = $dtend; + if ($title!='') + $renderer->doc .= '<a class="target" name="' + .$title.'"></a>'.$title; + } else if (ereg('!', $match)) { + + $renderer->doc .= $close; + $renderer->doc .= $ddstart; + $close = $ddend; + } else return false; + } return true; + case DOKU_LEXER_UNMATCHED: { + $renderer->doc .= htmlspecialchars($match); + } return true; + } + return false; + } + } + ?> + _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits