2 # -*- coding: utf-8 -*-
4 # rst — xml-rpc-based ikiwiki plugin to process RST files
6 # based a little bit on rst.pm by Sergio Talens-Oliag, but only a little bit. :)
8 # Copyright © 2007-2008 martin f. krafft <madduck@madduck.net>
9 # 2007-2011 Joey Hess <joey@kitenet.net>
10 # 2009 Ulrik Sverdrup <ulrik.sverdrup@gmail.com>
11 # 2011 Simon McVittie <smcv@debian.org>
12 # 2012 W. Trevor King <wking@tremily.us>
14 # Redistribution and use in source and binary forms, with or without
15 # modification, are permitted provided that the following conditions
17 # 1. Redistributions of source code must retain the above copyright
18 # notice, this list of conditions and the following disclaimer.
19 # 2. Redistributions in binary form must reproduce the above copyright
20 # notice, this list of conditions and the following disclaimer in the
21 # documentation and/or other materials provided with the distribution.
23 # THIS SOFTWARE IS PROVIDED BY IKIWIKI AND CONTRIBUTORS ``AS IS''
24 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
27 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 __description__ = 'xml-rpc-based ikiwiki plugin to process RST files'
39 __author__ = 'martin f. krafft <madduck@madduck.net>'
40 __copyright__ = 'Copyright © ' + __author__
41 __licence__ = 'BSD-2-clause'
43 from proxy import IkiWikiProcedureProxy
47 def rst2html(proxy, *args):
48 # delayed import so docutils is only needed if you *use* rst -
49 # http://bugs.debian.org/637604
51 if publish_parts is None:
53 from docutils.core import publish_parts
54 except ImportError, e:
55 proxy.error('cannot import docutils.core: %s: %s' %
56 (e.__class__.__name__, e))
59 kwargs = _to_dict(args)
60 parts = publish_parts(kwargs["content"],
62 settings_overrides = { 'halt_level': 6
63 , 'file_insertion_enabled': 0
66 return '\n'.join(parts['html_body'].splitlines()[1:-1])
69 # args is a list paired by key, value, so we turn it into a dict
70 return dict((k, v) for k, v in zip(*[iter(args)]*2))
72 def getsetup(proxy, *kwargs):
73 return 'plugin', { 'safe' : 1, 'rebuild' : 1, 'section' : 'format' }
77 sys.stderr.write(__name__ + ':DEBUG:%s\n' % s)
80 proxy = IkiWikiProcedureProxy(__name__, debug_fn=None)
81 proxy.hook('getsetup', getsetup)
82 proxy.hook('htmlize', rst2html)