This may not be the most spectacular DokuWiki plugin available, but it suits my own needs just fine. The plugin renders ( will render in the near future) the diamond and heart card suit symbols in red, and the clubs and spade card suit symbols in black. It also adds four buttons to the editor toolbar for quick access to the trump suit symbols.
Due to my very limited knowledge of PHP and javascript I can't guarantee this won't set fire to your DokuWiki server. Mine seems to have survived this far though, so there is hope yet. Suggestions for improvement are very welcome.
No special syntax. Just use standard UTF card suit symbols (optionally inserted by using the toolbar buttons).
Point your plug-in manager at trumpsuits-dokuwiki-plugin.tar.gz or trumpsuits-dokuwiki-plugin.zip.
Create the folder lib/plugins/trumpsuits in your DokuWiki folder. Create syntax.php and scrips.js as given below. Create the folder lib/plugins/trumpsuits/images and place the images in this table in there.
Take care not to include whitespace in front of the first php tag or after the last php tag. This leads to strange behaviour by DokuWiki.
<?php /** * Plugin base links: Creates links relative to site root for all links beginning with "/" * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Pieter van der Meulen <pieter@vdmeulen.net> */ 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_trumpsuits extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Pieter van der Meulen', 'email' => 'pieter@vdmeulen.net', 'date' => '2007-08-09', 'name' => 'trumpsuits', 'desc' => 'Adds toolbar buttons in editor for trump suits. Displays red suits red, black suits black.', 'url' => 'http://www.vdmeulen.net/wiki/bridge/trumpsuits-dokuwiki-plugin', ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } //This must be implemented function getSort(){ return 123; } } ?>
Hieruit eventueel nog stukje gebruiken:
<?php /** * Plugin Trumpsigns: Inserts <font size="+1" color="..."> tags into the document when trumpsigns are encountered * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Pieter van der Meulen <dev@vdmeulen.net> */ 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' => 'Pieter van der Meulen', 'email' => 'dev@vdmeulen.net', 'date' => '2006-11-20', 'name' => 'Trumpsigns Plugin', 'desc' => 'Inserts <font size="+1" color="..."> tags into the html around trump signs', 'url' => 'http://www.vdmeulen.net/wiki/bridge/troeftekens_in_dokuwiki#vergroot_in_rood_en_wart_weergeven', ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * Where to sort in? */ function getSort(){ return 789; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('♣',$mode,'plugin_trumpsigns'); $this->Lexer->addSpecialPattern('♦',$mode,'plugin_trumpsigns'); $this->Lexer->addSpecialPattern('♥',$mode,'plugin_trumpsigns'); $this->Lexer->addSpecialPattern('♠',$mode,'plugin_trumpsigns'); } /** * 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 .= "<FONT SIZE=\"+1\" COLOR=\"RED\">XXX+"; $renderer->doc .= $data; $renderer->doc .= "-XXX</FONT>"; return true; } return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 :
//create a single toolbutton with desired properties function plugin_trumpsuits_createToolbutton (id, tooltipText, imgFile, insText, accKey) { var ico = document.createElement("img"); ico.src = DOKU_BASE + "lib/plugins/trumpsuits/images/" + imgFile; var btn = document.createElement("button"); btn.id = "syntax__plugin_trumpsuits_" + id; btn.className = "toolbutton"; btn.appendChild(ico); btn.title = tooltipText; btn.accessKey = accKey; eval('btn.onclick = function(){insertAtCarret("wiki__text", "' + insText + '"); return false;}'); return(btn); } //if this is an "edit" page, add toolbuttons function plugin_trumpsuits_toolbar_additions() { var toolbar = $("tool__bar"); if(!toolbar) {return;} if(!$("edbtn__save")) {return;} //We must be able to save the page var tbtn = plugin_trumpsuits_createToolbutton("spades", "Spades", "spades.png", "♠", 'S'); if (tbtn) {toolbar.appendChild(tbtn);} tbtn = plugin_trumpsigns_createToolbutton("hearts", "Hearts", "hearts.png", "♥", 'H'); if (tbtn) {toolbar.appendChild(tbtn);} tbtn = plugin_trumpsigns_createToolbutton("diamonds", "Diamonds", "diamonds.png", "♦", 'D'); if (tbtn) {toolbar.appendChild(tbtn);} tbtn = plugin_trumpsigns_createToolbutton("clubs", "Clubs", "clubs.png", "♣", 'C'); if (tbtn) {toolbar.appendChild(tbtn);} } addInitEvent(plugin_trumpsuits_toolbar_additions);
Notes on javasript in plugins: http://wiki.splitbrain.org/wiki:devel:javascript. For debugging, first turn CSS en javascript compression off in your DokuWiki config. Then debug path/to/wiki/lib/exe/js.php. I use the Firefox javascript debugger plugin. User manual: http://devedge-temp.mozilla.org/viewsource/2002/venkman/01/index_en.html.
Browser an OS dependent CSS selectors: https://rafael.adm.br/css_browser_selector/