*
term
Term explanation
* * * Syntax: * = term : definition * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Pavel Vitis */ 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'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_definitions extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Pavel Vitis', 'email' => 'pavel [dot] vitis [at] seznam [dot] cz', 'date' => '2005-08-17', 'name' => 'Definition list plugin', 'desc' => 'Add HTML style definition list = term : definition', 'url' => 'http://www.dokuwiki.org/plugin:definitions', ); } /** * What kind of syntax are we? */ function getType(){ return 'container'; } function getAllowedTypes() { // allow all types inside
descriptions return array('container','substition','protected','disabled','formatting'); } /** * Paragraph Type * * Defines how this syntax is handled regarding paragraphs. This is important * for correct XHTML nesting. Should return one of the following: * * 'normal' - The plugin can be used inside paragraphs * 'block' - Open paragraphs need to be closed before plugin output * 'stack' - Special case. Plugin wraps other paragraphs. * * @see Doku_Handler_Block */ function getPType(){ // Normal because we don't want to have

around each block return 'normal'; } /** * Where to sort in? */ function getSort(){ // just make sure that we render before 'code' parser otherwise it ends up as code block return 11; } /** * Connect pattern to lexer */ function connectTo($mode) { // let's get all from '=' to ':' inclusive $this->Lexer->addEntryPattern('\n {2,}=[^:]+:',$mode,'plugin_definitions'); $this->Lexer->addEntryPattern('\n\t{1,}=[^:]+:',$mode,'plugin_definitions'); // and match all forthcoming '= term :' as well $this->Lexer->addPattern('\n {2,}=[^:]+:', 'plugin_definitions'); $this->Lexer->addPattern('\n\t{1,}=[^:]+:', 'plugin_definitions'); } function postConnect() { // end each definition with new line $this->Lexer->addExitPattern('\n','plugin_definitions'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ switch ( $state ) { case DOKU_LEXER_ENTER: // we are at the start of whole list, so strip off '=' at the beginning and ':' // at the end and we get the 'term' $match = substr(trim($match),1,-1); return array($match, $state); break; case DOKU_LEXER_MATCHED: // we are at another = line, so strip off '=' at the beginning and ':' // at the end and we get another 'term' $match = substr(trim($match),1,-1); return array($match, $state); break; case DOKU_LEXER_UNMATCHED: // we are inside description here so do nothing special return array($match, $state); break; case DOKU_LEXER_EXIT: // we are at the end of whole list so do nothing special return array($match, $state); break; } } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ if ($data[1] == DOKU_LEXER_ENTER) { // output starting tag and first term and start description $renderer->doc .= "
\n\t
".$data[0]."
\n\t\t
"; } else if ($data[1] == DOKU_LEXER_MATCHED){ // close previous description and output term and start another description if (trim($data[0]) != '') { $renderer->doc .= "
\n\t
".$data[0]."
\n\t\t
"; } else { $renderer->doc .= "
\n\t\t
"; } } else if ($data[1] == DOKU_LEXER_UNMATCHED){ // we are inside description, so pass it to renderer unchanged $renderer->doc .= ''.$data[0].''; } else if ($data[1] == DOKU_LEXER_EXIT){ // close last description and close whole block $renderer->doc .= "
\n
\n"; } return true; } return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 : ?>