1.1 --- a/moinformat/links/common.py Tue Nov 27 22:50:43 2018 +0100
1.2 +++ b/moinformat/links/common.py Fri Feb 08 22:36:54 2019 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Common linking scheme functionality.
1.6
1.7 -Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -23,6 +23,14 @@
1.13
1.14 "Translate Moin links into other forms."
1.15
1.16 + # Pagename whitespace conversion, configured using the "whitespace" metadata
1.17 + # setting.
1.18 +
1.19 + default_whitespace_map = [
1.20 + (" ", "_"),
1.21 + ("\n", "_"),
1.22 + ]
1.23 +
1.24 def __init__(self, metadata):
1.25
1.26 "Initialise the linker with the 'metadata'."
2.1 --- a/moinformat/links/html.py Tue Nov 27 22:50:43 2018 +0100
2.2 +++ b/moinformat/links/html.py Fri Feb 08 22:36:54 2019 +0100
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 HTML linking scheme.
2.6
2.7 -Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -106,7 +106,6 @@
2.13 # Split the pagename into path components.
2.14
2.15 t = target.split("#", 1)
2.16 - p = t[0].rstrip("/").split("/")
2.17
2.18 # Determine the actual pagename referenced.
2.19 # Replace the root pagename if it appears.
2.20 @@ -173,6 +172,7 @@
2.21 encoding fragment identifiers.
2.22 """
2.23
2.24 + s = self.replace_whitespace(s)
2.25 parts = s.split("#", 1)
2.26
2.27 if len(parts) > 1:
2.28 @@ -180,6 +180,19 @@
2.29
2.30 return "#".join(map(quote, parts))
2.31
2.32 + # Whitespace conversion in pagenames.
2.33 +
2.34 + def replace_whitespace(self, pagename):
2.35 +
2.36 + "Map whitespace in 'pagename' to appropriate characters."
2.37 +
2.38 + wsmap = self.metadata.get("whitespace", self.default_whitespace_map)
2.39 +
2.40 + for old, new in wsmap:
2.41 + pagename = pagename.replace(old, new)
2.42 +
2.43 + return pagename
2.44 +
2.45 # Identifier encoding.
2.46
2.47 def make_id(self, s):
3.1 --- a/moinformat/parsers/moin.py Tue Nov 27 22:50:43 2018 +0100
3.2 +++ b/moinformat/parsers/moin.py Fri Feb 08 22:36:54 2019 +0100
3.3 @@ -3,7 +3,7 @@
3.4 """
3.5 Moin wiki format parser.
3.6
3.7 -Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
3.8 +Copyright (C) 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
3.9
3.10 This program is free software; you can redistribute it and/or modify it under
3.11 the terms of the GNU General Public License as published by the Free Software
3.12 @@ -756,7 +756,7 @@
3.13 # Links and transclusions may start inline spans.
3.14
3.15 "link" : join((r"\[\[", # [[
3.16 - group("target", ".*?"), # ...
3.17 + group("target", r"\E*?"), # ...
3.18 choice((r"\|", # |
3.19 group("end", r"]]"))))), # ]]
3.20
4.1 --- a/moinformat/serialisers/html/moin.py Tue Nov 27 22:50:43 2018 +0100
4.2 +++ b/moinformat/serialisers/html/moin.py Fri Feb 08 22:36:54 2019 +0100
4.3 @@ -254,9 +254,9 @@
4.4 def _link(self, target, nodes, tag, attr):
4.5 label = None
4.6 if self.linker:
4.7 - target, label = self.linker.translate(target)
4.8 + href, label = self.linker.translate(target)
4.9
4.10 - self.out('<%s %s="%s"' % (tag, attr, escape_attr(target)))
4.11 + self.out('<%s %s="%s"' % (tag, attr, escape_attr(href)))
4.12
4.13 if nodes:
4.14 for node in nodes[1:]:
6.1 --- a/tests/test_links.txt Tue Nov 27 22:50:43 2018 +0100
6.2 +++ b/tests/test_links.txt Fri Feb 08 22:36:54 2019 +0100
6.3 @@ -6,3 +6,9 @@
6.4 A [[SomePage|''fancy'' link]] and [[SomePage|another|with|arguments]].
6.5
6.6 An {{attachment:picture.jpg|image|width=200}}.
6.7 +
6.8 +A paragraph with a [[wrapped
6.9 +link]], a [[wrapped
6.10 +link|wrapped link with label]], a [[link|link with
6.11 +wrapped label]], and a [[#wrapped
6.12 +intra-page link]].