aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-08-19 05:05:02 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-08-19 05:05:02 +0000
commit63edea27bc71c3bdf1837f994fb7effdd93fb2dd (patch)
treef060d006dc27b5162c3bdc6f680afb2829fb801f /IkiWiki/Plugin
parent02e4b42034e62cacaf4c4a6bb7ca296e7dc8528d (diff)
downloadikiwiki-63edea27bc71c3bdf1837f994fb7effdd93fb2dd.tar
ikiwiki-63edea27bc71c3bdf1837f994fb7effdd93fb2dd.tar.gz
* Add first draft at a Restructured Text (rst) plugin, by Sergio
Talens-Oliag. Note that this has many known issues -- see the caveats on the plugin's page. * Credit everyone who wrote a plugin on the plugins' wiki pages.
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/map.pm2
-rw-r--r--IkiWiki/Plugin/pagestats.pm2
-rw-r--r--IkiWiki/Plugin/rst.pm69
3 files changed, 71 insertions, 2 deletions
diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
index 070f49415..0ae5c1002 100644
--- a/IkiWiki/Plugin/map.pm
+++ b/IkiWiki/Plugin/map.pm
@@ -2,7 +2,7 @@
#
# Produce a hyerarchical map of links.
#
-# By Alessandro Dotti Contra <alessandro@hyboria.org>
+# by Alessandro Dotti Contra <alessandro@hyboria.org>
#
# Revision: 0.2
package IkiWiki::Plugin::map;
diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm
index de559e2c5..8ce563fc5 100644
--- a/IkiWiki/Plugin/pagestats.pm
+++ b/IkiWiki/Plugin/pagestats.pm
@@ -7,7 +7,7 @@
# (default)
# table: produces a table with the number of backlinks for each page
#
-# By Enrico Zini.
+# by Enrico Zini
package IkiWiki::Plugin::pagestats;
use warnings;
diff --git a/IkiWiki/Plugin/rst.pm b/IkiWiki/Plugin/rst.pm
new file mode 100644
index 000000000..6bf11fe36
--- /dev/null
+++ b/IkiWiki/Plugin/rst.pm
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+# Very simple reStructuredText processor.
+#
+# This plugin calls python and requires python-docutils to transform the text
+# into html.
+#
+# Its main problem is that it does not support ikiwiki's WikiLinks nor
+# Preprocessor Directives.
+#
+# 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;
+
+ my $tries=10;
+ while (1) {
+ eval {
+ # Try to call python and run our command
+ open2(*IN, *OUT, "python", "-c", $pyCmnd)
+ or return $content;
+ };
+ last unless $@;
+ $tries--;
+ if ($tries < 1) {
+ IkiWiki::debug("failed to run python to convert rst: $@");
+ 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