# HG changeset patch # User Paul Boddie # Date 1670968372 -3600 # Node ID dfc8861d4e599dfbb7e4fd7b677462ab777d999e # Parent 4c7049736a29e5498159951a028a6435b121d036 Attempted to fix attachment linking. diff -r 4c7049736a29 -r dfc8861d4e59 moinformat/links/html.py --- a/moinformat/links/html.py Mon Dec 12 00:38:07 2022 +0100 +++ b/moinformat/links/html.py Tue Dec 13 22:52:52 2022 +0100 @@ -3,7 +3,7 @@ """ HTML linking scheme. -Copyright (C) 2018, 2019 Paul Boddie +Copyright (C) 2018, 2019, 2022 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 @@ -129,13 +129,14 @@ """ identifier = target.get_identifier() + pagename = target.get_pagename() text = target.get_text() type = target.get_type() # Attachment links. if type == "attachment": - return Link(self.translate_attachment(identifier), + return Link(self.translate_attachment(identifier, pagename), identifier, target) # Interwiki links. @@ -149,11 +150,20 @@ # Specific link translators. - def translate_attachment(self, target): + def translate_attachment(self, target, pagename): + + """ + Return a translation of the given attachment 'target' associated with + the given 'pagename'. + """ - "Return a translation of the given attachment 'target'." + common_attachments = self.metadata.get("common_attachments") + top_level = self.get_top_level() - return self.quote("./%s/%s" % (self.attachments_dir, target)) + return self.quote("%s%s/%s%s" % (top_level and "%s/" % top_level or "", + self.attachments_dir, + not common_attachments and "%s/" % pagename or "", + target)) def translate_interwiki(self, url, target): diff -r 4c7049736a29 -r dfc8861d4e59 moinformat/macros/attachlist.py --- a/moinformat/macros/attachlist.py Mon Dec 12 00:38:07 2022 +0100 +++ b/moinformat/macros/attachlist.py Tue Dec 13 22:52:52 2022 +0100 @@ -3,7 +3,7 @@ """ AttachList macro for Moin compatibility. -Copyright (C) 2019 Paul Boddie +Copyright (C) 2019, 2022 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 @@ -75,7 +75,8 @@ for filename in filenames: text = [Text(filename)] - nodes = [Link([LinkLabel(text)], LinkTarget("attachment", filename))] + nodes = [Link([LinkLabel(text)], LinkTarget("attachment", filename, + pagename=pagename))] items.append(ListItem(nodes, indent, marker, space, num)) # Replace the macro node with the list. diff -r 4c7049736a29 -r dfc8861d4e59 moinformat/serialisers/html/graphviz.py --- a/moinformat/serialisers/html/graphviz.py Mon Dec 12 00:38:07 2022 +0100 +++ b/moinformat/serialisers/html/graphviz.py Tue Dec 13 22:52:52 2022 +0100 @@ -3,7 +3,7 @@ """ Graphviz serialiser, generating content for embedding in HTML documents. -Copyright (C) 2018, 2019 Paul Boddie +Copyright (C) 2018, 2019, 2022 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 @@ -135,7 +135,8 @@ # Make sure that page attachments can be stored. self.output.ensure_attachments(pagename) - link = self.linker.translate(LinkTarget("attachment", attachment)) + link = self.linker.translate(LinkTarget("attachment", attachment, + pagename=pagename)) # No filename is defined for inline output. diff -r 4c7049736a29 -r dfc8861d4e59 moinformat/utils/links.py --- a/moinformat/utils/links.py Mon Dec 12 00:38:07 2022 +0100 +++ b/moinformat/utils/links.py Tue Dec 13 22:52:52 2022 +0100 @@ -3,7 +3,7 @@ """ Link target parsing. -Copyright (C) 2018, 2019 Paul Boddie +Copyright (C) 2018, 2019, 2022 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 @@ -25,16 +25,21 @@ "A link target abstraction." - def __init__(self, type, text, identifier=None): + def __init__(self, type, text, identifier=None, pagename=None): - "Initialise the link with the given 'type', 'text' and 'identifier'." + """ + Initialise the link with the given 'type', 'text', and optional + 'identifier' and 'pagename'. + """ self.type = type self.text = text self.identifier = identifier + self.pagename = pagename def __repr__(self): - return "LinkTarget(%r, %r, %r)" % (self.type, self.text, self.identifier) + return "LinkTarget(%r, %r, %r, %r)" % (self.type, self.text, + self.identifier, self.pagename) def __str__(self): return self.text @@ -47,6 +52,9 @@ else: return self.text + def get_pagename(self): + return self.pagename + def get_text(self): return self.text