1.1 --- a/moinformat/links/html.py Mon Dec 12 00:38:07 2022 +0100
1.2 +++ b/moinformat/links/html.py Tue Dec 13 22:52:52 2022 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 HTML linking scheme.
1.6
1.7 -Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2018, 2019, 2022 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 @@ -129,13 +129,14 @@
1.13 """
1.14
1.15 identifier = target.get_identifier()
1.16 + pagename = target.get_pagename()
1.17 text = target.get_text()
1.18 type = target.get_type()
1.19
1.20 # Attachment links.
1.21
1.22 if type == "attachment":
1.23 - return Link(self.translate_attachment(identifier),
1.24 + return Link(self.translate_attachment(identifier, pagename),
1.25 identifier, target)
1.26
1.27 # Interwiki links.
1.28 @@ -149,11 +150,20 @@
1.29
1.30 # Specific link translators.
1.31
1.32 - def translate_attachment(self, target):
1.33 + def translate_attachment(self, target, pagename):
1.34 +
1.35 + """
1.36 + Return a translation of the given attachment 'target' associated with
1.37 + the given 'pagename'.
1.38 + """
1.39
1.40 - "Return a translation of the given attachment 'target'."
1.41 + common_attachments = self.metadata.get("common_attachments")
1.42 + top_level = self.get_top_level()
1.43
1.44 - return self.quote("./%s/%s" % (self.attachments_dir, target))
1.45 + return self.quote("%s%s/%s%s" % (top_level and "%s/" % top_level or "",
1.46 + self.attachments_dir,
1.47 + not common_attachments and "%s/" % pagename or "",
1.48 + target))
1.49
1.50 def translate_interwiki(self, url, target):
1.51