1.1 --- a/moinformat/links/common.py Fri Feb 08 22:35:46 2019 +0100
1.2 +++ b/moinformat/links/common.py Fri Feb 08 22:36:21 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 Fri Feb 08 22:35:46 2019 +0100
2.2 +++ b/moinformat/links/html.py Fri Feb 08 22:36:21 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):