summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-08-10 04:09:23 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-08-10 04:09:23 +0000
commit954cdda317b150a5df8e6077edaf23ba8aee1029 (patch)
tree2d9b64bea2232ab02c7a03b6f92592f5388a0cb9
parent1cfc21fb30464cefa5b02c16568e1c071ba03704 (diff)
preliminary rst plugin by Sergio Talens-Oliag
-rw-r--r--doc/patchqueue/rst.mdwn63
1 files changed, 63 insertions, 0 deletions
diff --git a/doc/patchqueue/rst.mdwn b/doc/patchqueue/rst.mdwn
new file mode 100644
index 000000000..1534cd9e5
--- /dev/null
+++ b/doc/patchqueue/rst.mdwn
@@ -0,0 +1,63 @@
+This is a whole lot better than nothing, but it's a shame it forks python
+every page. Anyone want to get [this](http://search.cpan.org/~nodine/Text-Restructured-0.003016/) into Debian and use it instead?
+-- [[Joey]]
+
+ #!/usr/bin/perl
+ # Very simple reStructuredText processor.
+ #
+ # This plugin calls python and requires python-docutils to transform the text
+ # into html.
+ #
+ # It's main problem is that it does not support ikiwiki's WikiLinks nor
+ # Preprocessor Directives (in fact the same problem applies to the current
+ # Wikitext processor, although in that case the output looks less worse ;)
+ #
+ # Probably Wikilinks and Preprocessor Directives should support a list of
+ # extensions to process (i.e. the linkify function could be transformed into
+ # reStructuredText instead of HTML using a hook on rst.py instead of the
+ # current linkify function)
+ #
+ # by Sergio Talens-Oliag <sto@debian.org>
+
+ package IkiWiki::Plugin::rst;
+
+ use warnings;
+ use strict;
+ use IkiWiki;
+ use IPC::Open2;
+
+ # Simple python script, maybe it should be implemented using an external script.
+ # The settings_overrides are given to avoid potential security risks when
+ # reading external files or if raw html is included on rst pages.
+ my $pyCmnd = "
+ from docutils.core import publish_string;
+ from sys import stdin;
+ html = publish_string(stdin.read(), writer_name='html',
+ settings_overrides = { 'halt_level': 6,
+ 'file_insertion_enabled': 0,
+ 'raw_enabled': 0 }
+ );
+ print html[html.find('<body>')+6:html.find('</body>')].strip();
+ ";
+
+ sub import { #{{{
+ IkiWiki::hook(type => "htmlize", id => "rst", call => \&htmlize);
+ } # }}}
+
+ sub htmlize ($) { #{{{
+ my $content = shift;
+
+ # Try to call python and run our command
+ open2(*IN, *OUT, "python", "-c", "$pyCmnd") or return $content;
+
+ # open2 doesn't respect "use open ':utf8'"
+ binmode (IN, ':utf8');
+ binmode (OUT, ':utf8');
+
+ print OUT $content;
+ close OUT;
+ local $/ = undef;
+ return <IN>;
+ } # }}}
+
+ 1