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'
45 from proxy import IkiWikiProcedureProxy
51 def rst2html(proxy, *args):
52 # delayed import so docutils is only needed if you *use* rst -
53 # http://bugs.debian.org/637604
55 if publish_parts is None:
57 from docutils.core import publish_parts
58 except ImportError as e:
59 proxy.error('cannot import docutils.core: {}: {}'.format(
60 e.__class__.__name__, e))
63 kwargs = _to_dict(args)
64 parts = publish_parts(kwargs["content"],
66 settings_overrides = { 'halt_level': 6
67 , 'file_insertion_enabled': 0
70 return '\n'.join(parts['html_body'].splitlines()[1:-1])
73 # args is a list paired by key, value, so we turn it into a dict
74 return dict((k, v) for k, v in zip(*[iter(args)]*2))
76 def getsetup(proxy, *kwargs):
77 return 'plugin', { 'safe' : 1, 'rebuild' : 1, 'section' : 'format' }
80 _sys.stderr.write(__name__ + ':DEBUG:{}\n'.format(s))
83 proxy = IkiWikiProcedureProxy(__name__, debug_fn=None)
84 proxy.hook('getsetup', getsetup)
85 proxy.hook('htmlize', rst2html)