1.1 --- a/convert.py Mon Aug 06 15:45:11 2018 +0200
1.2 +++ b/convert.py Mon Aug 06 15:50:16 2018 +0200
1.3 @@ -220,7 +220,7 @@
1.4
1.5 # Obtain a serialiser using the configuration.
1.6
1.7 - serialiser = make_serialiser(format, output, linker)
1.8 + serialiser = make_serialiser(format, output, linker, pagename)
1.9 outtext = serialise(d, serialiser)
1.10
1.11 # If reading from a file, show the result. Otherwise, write to the
2.1 --- a/moinformat/links/html.py Mon Aug 06 15:45:11 2018 +0200
2.2 +++ b/moinformat/links/html.py Mon Aug 06 15:50:16 2018 +0200
2.3 @@ -124,8 +124,7 @@
2.4
2.5 "Return a translation of the given attachment 'target'."
2.6
2.7 - return self.quote("%sattachments/%s/%s" % (
2.8 - self.get_top_level(), self.pagename, target))
2.9 + return self.quote("./attachments/%s" % target)
2.10
2.11 def translate_interwiki(self, url, target):
2.12
2.13 @@ -137,7 +136,7 @@
2.14
2.15 "Return a translation of the given relative 'target'."
2.16
2.17 - return self.quote(target[len("../"):])
2.18 + return self.quote(target)
2.19
2.20 def translate_subpage(self, target):
2.21
3.1 --- a/moinformat/output/directory.py Mon Aug 06 15:45:11 2018 +0200
3.2 +++ b/moinformat/output/directory.py Mon Aug 06 15:50:16 2018 +0200
3.3 @@ -21,7 +21,7 @@
3.4
3.5 from moinformat.output.common import Output
3.6 from moinformat.utils.directory import Directory
3.7 -from os.path import extsep, join, split, splitext
3.8 +from os.path import extsep, join
3.9
3.10 class DirectoryOutput(Output):
3.11
3.12 @@ -42,9 +42,40 @@
3.13
3.14 self.index_name = self.parameters.get("index_name") or "index.html"
3.15 self.page_suffix = self.parameters.get("page_suffix") or "%shtml" % extsep
3.16 + self.root_pagename = self.parameters.get("root_pagename") or "FrontPage"
3.17
3.18 # Convenience methods.
3.19
3.20 + def ensure(self, pagename):
3.21 +
3.22 + "Ensure that the given 'pagename' exists."
3.23 +
3.24 + if not pagename:
3.25 + return None
3.26 +
3.27 + self.dir.ensure(self.to_filename(pagename))
3.28 +
3.29 + def ensure_attachments(self, pagename):
3.30 +
3.31 + "Ensure that attachment storage for the given 'pagename' exists."
3.32 +
3.33 + if not pagename:
3.34 + return None
3.35 +
3.36 + self.dir.ensure(join(self.to_filename(pagename), "attachments"))
3.37 +
3.38 + def get_attachment_filename(self, pagename, filename):
3.39 +
3.40 + """
3.41 + Return the full path of an attachment file for the given 'pagename'
3.42 + having the given 'filename'.
3.43 + """
3.44 +
3.45 + if not pagename:
3.46 + return None
3.47 +
3.48 + return self.dir.get_filename(join(self.to_filename(pagename), "attachments", filename))
3.49 +
3.50 def get_filename(self, filename):
3.51
3.52 """
3.53 @@ -60,22 +91,18 @@
3.54
3.55 "Return the filename corresponding to 'pagename'."
3.56
3.57 - return "%s%s" % (pagename, self.page_suffix)
3.58 + # For the root page, use the top-level directory.
3.59 +
3.60 + if pagename == self.root_pagename:
3.61 + return ""
3.62 + else:
3.63 + return pagename
3.64
3.65 def to_pagename(self, filename):
3.66
3.67 "Return the pagename corresponding to 'filename'."
3.68
3.69 - # Take the leafname as the pagename from an arbitrary filename, removing
3.70 - # any file extension.
3.71 -
3.72 - return splitext(split(filename)[-1])[0]
3.73 -
3.74 - def to_parent_filename(self, pagename):
3.75 -
3.76 - "Return the parent page filename corresponding to 'pagename'."
3.77 -
3.78 - return pagename
3.79 + return self.within(filename)
3.80
3.81 # Serialisation methods.
3.82
3.83 @@ -102,39 +129,16 @@
3.84 the page is a parent of other pages.
3.85 """
3.86
3.87 - dir = self.dir
3.88 - parent = self.parent(pagename)
3.89 -
3.90 - # The page may have a parent.
3.91 -
3.92 - if parent:
3.93 - parentfile = self.to_filename(parent)
3.94 - parentdir = self.to_parent_filename(parent)
3.95 -
3.96 - # Relocate any file for the parent to an index file within a page
3.97 - # directory.
3.98 + filename = self.to_filename(pagename)
3.99
3.100 - if dir.isfile(parentfile):
3.101 - parent_tmp = "%s.tmp" % parentfile
3.102 - dir.rename(parentfile, parent_tmp)
3.103 - if not dir.exists(parentdir):
3.104 - dir.makedirs(parentdir)
3.105 - dir.rename(parent_tmp, join(parentdir, self.index_name))
3.106 + # Make a directory for the page.
3.107
3.108 - # Or make a directory for the parent.
3.109 -
3.110 - elif not dir.exists(parentdir):
3.111 - dir.makedirs(parentdir)
3.112 + if not self.dir.exists(filename):
3.113 + self.dir.makedirs(filename)
3.114
3.115 # Write to an index filename within any existing directory.
3.116
3.117 - dirname = self.to_parent_filename(pagename)
3.118 -
3.119 - if dir.isdir(dirname):
3.120 - filename = join(dirname, self.index_name)
3.121 - else:
3.122 - filename = self.to_filename(pagename)
3.123 -
3.124 + filename = join(filename, self.index_name)
3.125 self.writefile(text, filename, encoding)
3.126
3.127 output = DirectoryOutput
4.1 --- a/moinformat/output/standalone.py Mon Aug 06 15:45:11 2018 +0200
4.2 +++ b/moinformat/output/standalone.py Mon Aug 06 15:50:16 2018 +0200
4.3 @@ -27,6 +27,29 @@
4.4
4.5 name = "standalone"
4.6
4.7 + # Convenience methods.
4.8 +
4.9 + def ensure(self, pagename):
4.10 +
4.11 + "Ensure that the given 'pagename' exists."
4.12 +
4.13 + pass
4.14 +
4.15 + def ensure_attachments(self, pagename):
4.16 +
4.17 + "Ensure that attachment storage for the given 'pagename' exists."
4.18 +
4.19 + pass
4.20 +
4.21 + def get_attachment_filename(self, pagename, filename):
4.22 +
4.23 + """
4.24 + Prevent independent output by returning a filename of None corresponding
4.25 + to the given 'pagename' and any specified 'filename'.
4.26 + """
4.27 +
4.28 + return None
4.29 +
4.30 def get_filename(self, filename):
4.31
4.32 """
5.1 --- a/moinformat/serialisers/html/graphviz.py Mon Aug 06 15:45:11 2018 +0200
5.2 +++ b/moinformat/serialisers/html/graphviz.py Mon Aug 06 15:50:16 2018 +0200
5.3 @@ -69,17 +69,17 @@
5.4
5.5 # Special methods for graph production.
5.6
5.7 - def _tag(self, tagname, attrname, filename, attributes, closing):
5.8 - l = ["%s='%s'" % (attrname, escape_attr(filename))]
5.9 + def _tag(self, tagname, attrname, target, attributes, closing):
5.10 + l = ["%s='%s'" % (attrname, escape_attr(target))]
5.11 for key, value in attributes.items():
5.12 l.append("%s='%s'" % (key, value))
5.13 self.out("<%s %s%s>" % (tagname, " ".join(l), closing and " /"))
5.14
5.15 - def image(self, filename, attributes):
5.16 - self._tag("img", "src", filename, attributes, True)
5.17 + def image(self, target, attributes):
5.18 + self._tag("img", "src", target, attributes, True)
5.19
5.20 - def object(self, filename, attributes):
5.21 - self._tag("object", "data", filename, attributes, False)
5.22 + def object(self, target, attributes):
5.23 + self._tag("object", "data", target, attributes, False)
5.24 self.out("</object>")
5.25
5.26 def raw(self, text):
5.27 @@ -97,16 +97,27 @@
5.28 format = self.directives.get("format", ["svg"])[0]
5.29 transforms = self.directives.get("transform", [])
5.30
5.31 + # Graph output is stored for a known page only.
5.32 +
5.33 + if not self.pagename:
5.34 + return
5.35 +
5.36 # Get an identifier and usable filename to store the output.
5.37
5.38 - identifier = "%s.%s" % (get_output_identifier(text), format)
5.39 - filename = self.output.get_filename(identifier)
5.40 + identifier = get_output_identifier(text)
5.41 + attachment = "%s.%s" % (identifier, format)
5.42 + filename = self.output.get_attachment_filename(self.pagename, attachment)
5.43
5.44 # Handle situations where no independent output is permitted.
5.45
5.46 if not filename:
5.47 return
5.48
5.49 + # Make sure that page attachments can be stored.
5.50 +
5.51 + self.output.ensure_attachments(self.pagename)
5.52 + target, label = self.linker.translate("attachment:%s" % attachment)
5.53 +
5.54 # Permit imagemaps only for image formats.
5.55
5.56 if format in IMAGE_FORMATS:
5.57 @@ -135,12 +146,12 @@
5.58 self.raw(graphviz.get_output())
5.59 attributes["usemap"] = "#%s" % im_attributes["id"]
5.60
5.61 - self.image(identifier, attributes)
5.62 + self.image(target, attributes)
5.63
5.64 # For other output, create a file and embed the object.
5.65
5.66 else:
5.67 - self.object(identifier, attributes)
5.68 + self.object(target, attributes)
5.69
5.70 serialiser = HTMLGraphvizSerialiser
5.71