1.1 --- a/moinformat/links/html.py Sun Jan 15 17:10:21 2023 +0100
1.2 +++ b/moinformat/links/html.py Sun Jan 15 17:11:37 2023 +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
2.1 --- a/moinformat/macros/attachlist.py Sun Jan 15 17:10:21 2023 +0100
2.2 +++ b/moinformat/macros/attachlist.py Sun Jan 15 17:11:37 2023 +0100
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 AttachList macro for Moin compatibility.
2.6
2.7 -Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2019, 2022 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 @@ -75,7 +75,8 @@
2.13
2.14 for filename in filenames:
2.15 text = [Text(filename)]
2.16 - nodes = [Link([LinkLabel(text)], LinkTarget("attachment", filename))]
2.17 + nodes = [Link([LinkLabel(text)], LinkTarget("attachment", filename,
2.18 + pagename=pagename))]
2.19 items.append(ListItem(nodes, indent, marker, space, num))
2.20
2.21 # Replace the macro node with the list.
3.1 --- a/moinformat/serialisers/html/graphviz.py Sun Jan 15 17:10:21 2023 +0100
3.2 +++ b/moinformat/serialisers/html/graphviz.py Sun Jan 15 17:11:37 2023 +0100
3.3 @@ -3,7 +3,7 @@
3.4 """
3.5 Graphviz serialiser, generating content for embedding in HTML documents.
3.6
3.7 -Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
3.8 +Copyright (C) 2018, 2019, 2022 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 @@ -135,7 +135,8 @@
3.13 # Make sure that page attachments can be stored.
3.14
3.15 self.output.ensure_attachments(pagename)
3.16 - link = self.linker.translate(LinkTarget("attachment", attachment))
3.17 + link = self.linker.translate(LinkTarget("attachment", attachment,
3.18 + pagename=pagename))
3.19
3.20 # No filename is defined for inline output.
3.21
4.1 --- a/moinformat/utils/links.py Sun Jan 15 17:10:21 2023 +0100
4.2 +++ b/moinformat/utils/links.py Sun Jan 15 17:11:37 2023 +0100
4.3 @@ -3,7 +3,7 @@
4.4 """
4.5 Link target parsing.
4.6
4.7 -Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
4.8 +Copyright (C) 2018, 2019, 2022 Paul Boddie <paul@boddie.org.uk>
4.9
4.10 This program is free software; you can redistribute it and/or modify it under
4.11 the terms of the GNU General Public License as published by the Free Software
4.12 @@ -25,16 +25,21 @@
4.13
4.14 "A link target abstraction."
4.15
4.16 - def __init__(self, type, text, identifier=None):
4.17 + def __init__(self, type, text, identifier=None, pagename=None):
4.18
4.19 - "Initialise the link with the given 'type', 'text' and 'identifier'."
4.20 + """
4.21 + Initialise the link with the given 'type', 'text', and optional
4.22 + 'identifier' and 'pagename'.
4.23 + """
4.24
4.25 self.type = type
4.26 self.text = text
4.27 self.identifier = identifier
4.28 + self.pagename = pagename
4.29
4.30 def __repr__(self):
4.31 - return "LinkTarget(%r, %r, %r)" % (self.type, self.text, self.identifier)
4.32 + return "LinkTarget(%r, %r, %r, %r)" % (self.type, self.text,
4.33 + self.identifier, self.pagename)
4.34
4.35 def __str__(self):
4.36 return self.text
4.37 @@ -47,6 +52,9 @@
4.38 else:
4.39 return self.text
4.40
4.41 + def get_pagename(self):
4.42 + return self.pagename
4.43 +
4.44 def get_text(self):
4.45 return self.text
4.46