1 This is a whole lot better than nothing, but it's a shame it forks python
2 every page. Anyone want to get [this](http://search.cpan.org/~nodine/Text-Restructured-0.003016/) into Debian and use it instead?
6 # Very simple reStructuredText processor.
8 # This plugin calls python and requires python-docutils to transform the text
11 # It's main problem is that it does not support ikiwiki's WikiLinks nor
12 # Preprocessor Directives (in fact the same problem applies to the current
13 # Wikitext processor, although in that case the output looks less worse ;)
15 # Probably Wikilinks and Preprocessor Directives should support a list of
16 # extensions to process (i.e. the linkify function could be transformed into
17 # reStructuredText instead of HTML using a hook on rst.py instead of the
18 # current linkify function)
20 # by Sergio Talens-Oliag <sto@debian.org>
22 package IkiWiki::Plugin::rst;
29 # Simple python script, maybe it should be implemented using an external script.
30 # The settings_overrides are given to avoid potential security risks when
31 # reading external files or if raw html is included on rst pages.
33 from docutils.core import publish_string;
34 from sys import stdin;
35 html = publish_string(stdin.read(), writer_name='html',
36 settings_overrides = { 'halt_level': 6,
37 'file_insertion_enabled': 0,
40 print html[html.find('<body>')+6:html.find('</body>')].strip();
44 IkiWiki::hook(type => "htmlize", id => "rst", call => \&htmlize);
47 sub htmlize ($) { #{{{
50 # Try to call python and run our command
51 open2(*IN, *OUT, "python", "-c", "$pyCmnd") or return $content;
53 # open2 doesn't respect "use open ':utf8'"
54 binmode (IN, ':utf8');
55 binmode (OUT, ':utf8');