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 © martin f. krafft <madduck@madduck.net>
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY IKIWIKI AND CONTRIBUTORS ``AS IS''
20 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
23 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 __description__ = 'xml-rpc-based ikiwiki plugin to process RST files'
35 __author__ = 'martin f. krafft <madduck@madduck.net>'
36 __copyright__ = 'Copyright © ' + __author__
37 __licence__ = 'BSD-2-clause'
39 from proxy import IkiWikiProcedureProxy
43 def rst2html(proxy, *args):
44 # delayed import so docutils is only needed if you *use* rst -
45 # http://bugs.debian.org/637604
47 if publish_parts is None:
49 from docutils.core import publish_parts
50 except ImportError, e:
51 proxy.error('cannot import docutils.core: %s: %s' %
52 (e.__class__.__name__, e))
55 kwargs = _to_dict(args)
56 parts = publish_parts(kwargs["content"],
58 settings_overrides = { 'halt_level': 6
59 , 'file_insertion_enabled': 0
62 return '\n'.join(parts['html_body'].splitlines()[1:-1])
65 # args is a list paired by key, value, so we turn it into a dict
66 return dict((k, v) for k, v in zip(*[iter(args)]*2))
68 def getsetup(proxy, *kwargs):
69 return 'plugin', { 'safe' : 1, 'rebuild' : 1, 'section' : 'format' }
73 sys.stderr.write(__name__ + ':DEBUG:%s\n' % s)
76 proxy = IkiWikiProcedureProxy(__name__, debug_fn=None)
77 proxy.hook('getsetup', getsetup)
78 proxy.hook('htmlize', rst2html)