On Thu, Oct 28, 2010 at 09:59:39PM +0200, Andreas Gohr wrote: > > I have written a reStructuredText plugin for DokuWiki which works > > pretty well but it requires one to add <rst> and </rst> around the > > blocks of reStructuredText. > > > > Is there a way I can make DokuWiki process all files with a .rst > > suffix as reStructuredText using my plugin? I can then just import the > > whole hierarchy of .rst files and it should work as originally designed. > > > > Essentially what I need is a way to tell DokuWiki to take the contents > > of the .rst file, prefix it with <rst>, postfix it with </rst> and then > > feed it through the standard parser. > > Doing this is really simple. I just tried that with the markdownextra > plugin. I simply added an action component intercepting > PARSER_WIKITEXT_PREPROCESS. It checks if the page ID ends in .md and > wraps the content in <markdown></markdown> tags. > > Note that it checks the page ID, not the actual file extension in the > back. So a page called test.md is actually still named test.md.txt in > the data directory, but I think this should be good enough for you. > Aha, I hadn't thought of that approach. It will work for me as all I have to do is import all my .rst files and rename them to .rst.txt, not a big problem. > It's just a few lines of code (just adjust the thing below for the > restructured text plugin). > I'm off to try it now, thank you! :-) > <?php > /** > * DokuWiki Plugin markdownextra (Action Component) > * > * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html > * @author Andreas Gohr <andi@xxxxxxxxxxxxxx> > */ > > // must be run within Dokuwiki > if (!defined('DOKU_INC')) die(); > if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); > require_once DOKU_PLUGIN.'action.php'; > > class action_plugin_markdownextra extends DokuWiki_Action_Plugin { > > function register(&$controller) { > $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', > 'BEFORE', $this, 'handle_parser_wikitext_preprocess'); > } > > function handle_parser_wikitext_preprocess(&$event, $param) { > global $ID; > if(substr($ID,-3) != '.md') return true; > > $event->data = "<markdown>\n".$event->data."\n</markdown>"; > } > > } > > > > -- > splitbrain.org > -- > DokuWiki mailing list - more info at > http://www.dokuwiki.org/mailinglist -- Chris Green -- DokuWiki mailing list - more info at http://www.dokuwiki.org/mailinglist