Quick test of the plugin-system in dokuwiki. Allows the user to embed markdown syntax in <markdown> tags. Also fixes bug #333.
Try it with the bookmarklet from The asciinator.
Note that this plugin is currently good only for formatting chunks of markdown text. Essential Dokuwiki features such as wiki links and the table of contents cannot yet be nested within the <markdown> tags.
This procedure and syntax.php source have been tried successfully with dokuwiki-2007-06-26. Please update this section as newer versions of Dokuwiki are released. For notes on use with older versions of Dokuwiki, see below
<?php /** * Markdown-Plugin: Parses markdown-blocks * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Carl-Christian Salvesen <calle@ioslo.net> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'inc/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); require_once(DOKU_PLUGIN.'markdown/markdown.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_markdown extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Carl-Christian Salvesen', 'email' => 'calle@ioslo.net', 'date' => '2006-05-24', 'name' => 'Markdown Plugin', 'desc' => 'Parses markdown-blocks', 'url' => 'http://wiki.ioslo.net/dokuwiki/markdown', ); } /** * What kind of syntax are we? */ function getType(){ return 'protected'; } /** * Where to sort in? */ function getSort(){ return 205; } function getPType() { return 'block'; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addEntryPattern('<markdown>(?=.*</markdown>)',$mode,'plugin_markdown'); } function postConnect() { $this->Lexer->addExitPattern('</markdown>','plugin_markdown'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ return array($match); } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml' && $data[0] != "<markdown>" && $data[0] != "</markdown>") { $renderer->doc .= Markdown($data[0]); return true; } return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 : ?>
<?php /** * Markdown-Plugin: Parses markdown-blocks * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Carl-Christian Salvesen <calle@ioslo.net> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'inc/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); require_once(DOKU_PLUGIN.'markdown/markdown.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_markdown extends DokuWiki_Syntax_Plugin { /** * What kind of syntax are we? */ function getType(){ return 'protected'; } /** * Where to sort in? */ function getSort(){ return 205; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addEntryPattern('<markdown>',$mode,'plugin_markdown'); } function postConnect() { $this->Lexer->addExitPattern('</markdown>','plugin_markdown'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ $match = substr($match,10,-11); //strip <markdown> and </markdown> return array($match); } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ //handle various info stuff $renderer->doc .= Markdown($data[0]); return true; } return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 : ?>
I could be wrong, but it looks like the substr() call to strip the <markdown> tags is no longer needed. (using version 2005-07-1) They were stripping some of my text, and I got the expected behavior when I just removed that line. — James Van Lommel 2005/07/03 23:15
The plugin needs to implement the getInfo() method or DokuWiki complains. — Alan Liu 2005/07/15 19:48
Using the 2005-09-22 version, I had to:
lib/plugins/markdown/markdown.phplib/plugins/markdown/syntax.phpconf/local.php and add $conf[’pluginmanager’] = 1;David Rasch 2006/01/23 14:22 EST
Using the 2006-03-09 version
conf/local.php I didn’t need to have $conf[’pluginmanager’] = 1;$conf[’htmlok’] = 1; before it would worksubstr() line as detailed by James.Andy Grimsdale 2006/04/06 23:50 GMT