2 # Very simple reStructuredText processor.
4 # This plugin calls python and requires python-docutils to transform the text
7 # Its main problem is that it does not support ikiwiki's WikiLinks nor
8 # Preprocessor Directives.
10 # Probably Wikilinks and Preprocessor Directives should support a list of
11 # extensions to process (i.e. the linkify function could be transformed into
12 # reStructuredText instead of HTML using a hook on rst.py instead of the
13 # current linkify function)
15 # by Sergio Talens-Oliag <sto@debian.org>
17 package IkiWiki::Plugin::rst;
24 # Simple python script, maybe it should be implemented using an external script.
25 # The settings_overrides are given to avoid potential security risks when
26 # reading external files or if raw html is included on rst pages.
28 from docutils.core import publish_string;
29 from sys import stdin;
30 html = publish_string(stdin.read(), writer_name='html',
31 settings_overrides = { 'halt_level': 6,
32 'file_insertion_enabled': 0,
35 print html[html.find('<body>')+6:html.find('</body>')].strip();
39 IkiWiki::hook(type => "htmlize", id => "rst", call => \&htmlize);
42 sub htmlize (@) { #{{{
44 my $content=$params{content};
50 # Try to call python and run our command
51 $pid=open2(*IN, *OUT, "python", "-c", $pyCmnd)
57 IkiWiki::debug("failed to run python to convert rst: $@");
61 # open2 doesn't respect "use open ':utf8'"
62 binmode (IN, ':utf8');
63 binmode (OUT, ':utf8');