Nothing too special. I have some poetry on my site, so I wanted a way to add 'tabs'. Since you can't really do tabs in HTML, I decided to just use non-breaking spaces (nbsp's) instead. 5 nbsp's = 1 tab.
Simply insert '<tab>' into the text. When Dokuwiki parses it, it will replace '<tab>' with 5 nbsp's.
<?php /** * Plugin Tab: Inserts " " into the document for every <tab> it encounters * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Tim Skoch <timskoch@hotmail.com> */ 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_tab extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Tim Skoch', 'email' => 'timskoch@hotmail.com', 'date' => '2006-08-16', 'name' => 'Tab Plugin', 'desc' => 'Inserts " " into the html of the document for every <tab> it encounters', 'url' => 'http://www.dokuwiki.org/wiki:plugins:tab', ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * What kind of syntax do we allow (optional) */ // function getAllowedTypes() { // return array(); // } /** * What about paragraphs? (optional) */ // function getPType(){ // return 'normal'; // } /** * Where to sort in? */ function getSort(){ return 999; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('<tab>',$mode,'plugin_tab'); // $this->Lexer->addEntryPattern('<TEST>',$mode,'plugin_test'); } // function postConnect() { // $this->Lexer->addExitPattern('</TEST>','plugin_test'); // } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ switch ($state) { case DOKU_LEXER_ENTER : break; case DOKU_LEXER_MATCHED : break; case DOKU_LEXER_UNMATCHED : break; case DOKU_LEXER_EXIT : break; case DOKU_LEXER_SPECIAL : break; } return array(); } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ $renderer->doc .= " "; // ptype = 'normal' // $renderer->doc .= "<p>Hello World!</p>"; // ptype = 'block' return true; } return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 :
Just like any other plugin: Create a new folder “lib/plugins/tab”, and create a file “syntax.php” with the above code as its contents.
Enjoy!
Is any really necessary?
Tim,
We used your code to spawn our pagebreak plugin. Thanks a million for giving us a starting point. ~Jonathan and Chris
Could be done in less lines (drop test code etc).
<?php /** * Plugin Tab: Inserts " " into the document for every <tab> it encounters * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Tim Skoch <timskoch@hotmail.com> */ 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_tab extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Tim Skoch', 'email' => 'timskoch@hotmail.com', 'date' => '2006-08-16', 'name' => 'Tab Plugin', 'desc' => 'Inserts " " into the html of the document for every <tab> it encounters', 'url' => 'http://www.dokuwiki.org/wiki:plugins:tab', ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * Where to sort in? */ function getSort(){ return 999; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('<tab>', $mode, 'plugin_tab'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ return array(); } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ $renderer->doc .= ' '; return true; } return false; } } ?>
When we updated to the latest version of DokuWiki, this broke. It failed to interpret ” ” as a non-breaking space, and simply displayed it as text instead. The quick fix for me was to replace ” ” with ”     ”. Works for us, but we are a one-language shop and our limited userbase is almost exclusively using Firefox. YMMV.
— Nathan Randall 2008-04-15 10:33
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported