# HG changeset patch # User Paul Boddie # Date 1549661781 -3600 # Node ID 53b6ad24b799f7b0f3a784668bc5dd985b1f7b24 # Parent fdb7b2a836fd3320238cd91d12eade722306b4af Introduced explicit whitespace replacement for link targets. diff -r fdb7b2a836fd -r 53b6ad24b799 moinformat/links/common.py --- a/moinformat/links/common.py Fri Feb 08 22:35:46 2019 +0100 +++ b/moinformat/links/common.py Fri Feb 08 22:36:21 2019 +0100 @@ -3,7 +3,7 @@ """ Common linking scheme functionality. -Copyright (C) 2018 Paul Boddie +Copyright (C) 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,6 +23,14 @@ "Translate Moin links into other forms." + # Pagename whitespace conversion, configured using the "whitespace" metadata + # setting. + + default_whitespace_map = [ + (" ", "_"), + ("\n", "_"), + ] + def __init__(self, metadata): "Initialise the linker with the 'metadata'." diff -r fdb7b2a836fd -r 53b6ad24b799 moinformat/links/html.py --- a/moinformat/links/html.py Fri Feb 08 22:35:46 2019 +0100 +++ b/moinformat/links/html.py Fri Feb 08 22:36:21 2019 +0100 @@ -3,7 +3,7 @@ """ HTML linking scheme. -Copyright (C) 2018 Paul Boddie +Copyright (C) 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -106,7 +106,6 @@ # Split the pagename into path components. t = target.split("#", 1) - p = t[0].rstrip("/").split("/") # Determine the actual pagename referenced. # Replace the root pagename if it appears. @@ -173,6 +172,7 @@ encoding fragment identifiers. """ + s = self.replace_whitespace(s) parts = s.split("#", 1) if len(parts) > 1: @@ -180,6 +180,19 @@ return "#".join(map(quote, parts)) + # Whitespace conversion in pagenames. + + def replace_whitespace(self, pagename): + + "Map whitespace in 'pagename' to appropriate characters." + + wsmap = self.metadata.get("whitespace", self.default_whitespace_map) + + for old, new in wsmap: + pagename = pagename.replace(old, new) + + return pagename + # Identifier encoding. def make_id(self, s):