1.1 --- a/moinformat/serialisers/common.py Tue Jun 20 18:58:47 2023 +0200
1.2 +++ b/moinformat/serialisers/common.py Wed Jun 28 16:12:26 2023 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Moin serialiser support.
1.6
1.7 -Copyright (C) 2017, 2018, 2019, 2021 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2017, 2018, 2019, 2021, 2023 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 @@ -92,6 +92,36 @@
1.13 else:
1.14 return cls(self.metadata, self.serialisers)
1.15
1.16 + # Serialisation visitor methods.
1.17 +
1.18 + def to_string(self, node):
1.19 +
1.20 + "Visit the 'node' to invoke the appropriate serialisation handler."
1.21 +
1.22 + node.visit(self)
1.23 +
1.24 + def region_to_string(self, region):
1.25 +
1.26 + """
1.27 + Obtain a serialiser for the region from the same format family. Retain
1.28 + the same serialiser if no appropriate serialiser could be obtained.
1.29 + """
1.30 +
1.31 + serialiser_name = self.formats and "%s.%s" % (self.formats[0], region.type) or None
1.32 + serialiser = self.get_serialiser(serialiser_name)
1.33 +
1.34 + # Serialise the region.
1.35 +
1.36 + serialiser.container(region)
1.37 +
1.38 + def container(self, container):
1.39 +
1.40 + "Visit all nodes in 'container'."
1.41 +
1.42 + if container.nodes:
1.43 + for node in container.nodes:
1.44 + self.to_string(node)
1.45 +
1.46 def escape_attr(s):
1.47
1.48 "Escape XML document attribute."