1 I have a working minimal implementation letting the rst renderer resolve undefined native rST links to ikiwiki pages. I have posted it as one patch at:
3 Preview commit: http://github.com/engla/ikiwiki/commit/486fd79e520da1d462f00f40e7a90ab07e9c6fdf
4 Repository: git://github.com/engla/ikiwiki.git
6 Design issues of the patch:
8 Right now it changes rendering so that undefined pages (previous errors) are resolved to either ikiwiki pages or link to "#". It could be changed (trivially) so that undefined pages give the same error as before. Since it only resolves links that would previously error out, impact on current installations should be minimal.
10 I don't know why backlinks don't show up with the patch as it is; they are registered, but not rendered on the linked-to page.
12 Desing issues in general:
14 We resolve rST links without definition, we don't help resolving defined relative links, so we don't support specifying link name and target separately.
16 Many other issues with rST are of course unresolved, but some might be solved by implementing custom rST directives (which is a supported extension mechanism).
22 From 486fd79e520da1d462f00f40e7a90ab07e9c6fdf Mon Sep 17 00:00:00 2001
23 From: Ulrik Sverdrup <ulrik.sverdrup@gmail.com>
24 Date: Thu, 17 Sep 2009 15:18:50 +0200
25 Subject: [PATCH] rst: Resolve native reStructuredText links to ikiwiki pages
27 Links in rST use syntax `Like This`_ or OneWordLink_, and are
28 generally used for relative or absolue links, with an auxiliary
31 .. _`Like This`: http://ikiwiki.info
32 .. _OneWordLink: relative
34 We can hook into docutils to resolve unresolved links so that rST
35 links without definition can be resolved to wiki pages. This enables
36 WikiLink_ to link to [[WikiLink]] (if no .. _WikiLink is specified).
38 Comparing to Ikiwiki's wikilinks
40 [[blogging|blog]] specifies a link to the page blog, with the name
41 blogging. In rST we should use blogging_
45 *However*, note that this patch does not hook into this. What we
46 resolve in this patch is finding the appropriate "_blogging" if it is
47 not found, not resolving the address 'blog'.
49 plugins/rst | 46 +++++++++++++++++++++++++++++++++++++++++-----
50 1 files changed, 41 insertions(+), 5 deletions(-)
52 diff --git a/plugins/rst b/plugins/rst
53 index a2d07eb..a74baa8 100755
57 # based a little bit on rst.pm by Sergio Talens-Oliag, but only a little bit. :)
59 # Copyright © martin f. krafft <madduck@madduck.net>
60 +# Copyright © Ulrik Sverdrup <ulrik.sverdrup@gmail.com>, 2009
62 # Released under the terms of the GNU GPL version 2
66 __description__ = 'xml-rpc-based ikiwiki plugin to process RST files'
69 __author__ = 'martin f. krafft <madduck@madduck.net>'
70 __copyright__ = 'Copyright © ' + __author__
73 from docutils.core import publish_parts;
74 +from docutils.writers import html4css1
75 from proxy import IkiWikiProcedureProxy
77 -def rst2html(proxy, *kwargs):
78 - # FIXME arguments should be treated as a hash, the order could change
79 - # at any time and break this.
80 - parts = publish_parts(kwargs[3], writer_name='html',
81 +class IkiwikiWriter(html4css1.Writer):
82 + def resolve_node(self, node):
83 + refname = node.get('refname', None)
87 + bestlink = self.proxy.rpc('bestlink', self.page, refname)
90 + node['class'] = 'wiki'
96 + rel_url = self.proxy.rpc('urlto', bestlink, self.page)
97 + self.proxy.rpc('add_link', self.page, bestlink)
98 + node['refuri'] = rel_url
99 + self.proxy.rpc('debug', "Emitting link %s => %s" % (refname, rel_url))
102 + resolve_node.priority = 1
104 + def __init__(self, proxy, page):
105 + html4css1.Writer.__init__(self)
108 + self.unknown_reference_resolvers = (self.resolve_node, )
110 +def rst2html(proxy, *args):
111 + # args is a list paired by key, value, so we turn it into a dict
112 + kwargs = dict((k, v) for k, v in zip(*[iter(args)]*2))
113 + page = kwargs['page']
115 + parts = publish_parts(kwargs['content'],
116 + writer=IkiwikiWriter(proxy, page),
117 settings_overrides = { 'halt_level': 6
118 , 'file_insertion_enabled': 0