1.1 --- a/moinformat/parsers/moin.py Mon Aug 13 22:54:01 2018 +0200
1.2 +++ b/moinformat/parsers/moin.py Tue Aug 14 22:33:30 2018 +0200
1.3 @@ -51,21 +51,14 @@
1.4
1.5 format = "moin"
1.6
1.7 - def __init__(self, formats=None, root=None):
1.8 + def __init__(self, metadata, parsers=None, root=None):
1.9
1.10 """
1.11 - Initialise the parser with any given 'formats' mapping from region type
1.12 - names to parser objects. An optional 'root' indicates the document-level
1.13 - parser.
1.14 + Initialise the parser with the given 'metadata' and optional 'parsers'.
1.15 + An optional 'root' indicates the document-level parser.
1.16 """
1.17
1.18 - # Introduce this class as the default parser for the wiki format.
1.19 -
1.20 - default_formats = {"wiki" : MoinParser, "moin" : MoinParser}
1.21 - if formats:
1.22 - default_formats.update(formats)
1.23 -
1.24 - ParserBase.__init__(self, default_formats, root)
1.25 + ParserBase.__init__(self, metadata, parsers, root)
1.26
1.27 # Record certain node occurrences for later evaluation.
1.28
1.29 @@ -149,6 +142,20 @@
1.30
1.31
1.32
1.33 + # Conversion back to text.
1.34 +
1.35 + def get_serialiser(self):
1.36 +
1.37 + "Return metadata employing Moin as the output format."
1.38 +
1.39 + metadata = self.metadata.copy()
1.40 + metadata.set("link_format", None)
1.41 + metadata.set("output_context", "standalone")
1.42 + metadata.set("output_format", "moin")
1.43 + return metadata.get_serialiser()
1.44 +
1.45 +
1.46 +
1.47 # Parser methods supporting different page features.
1.48
1.49 def parse_attrname(self, attrs):
1.50 @@ -425,7 +432,7 @@
1.51
1.52 # Invalid nodes were found: serialise the attributes as text.
1.53
1.54 - cell.append_inline(Text(serialise(attrs)))
1.55 + cell.append_inline(Text(serialise(attrs, self.get_serialiser())))
1.56
1.57 def parse_table_row(self, region):
1.58
1.59 @@ -455,9 +462,15 @@
1.60 # If the cell was started but not finished, convert the row into text.
1.61
1.62 if not row.nodes or not cell.empty():
1.63 +
1.64 + # Convert the nodes back to text.
1.65 +
1.66 + serialiser = self.get_serialiser()
1.67 +
1.68 for node in row.nodes:
1.69 - region.append_inline(Text(serialise(node)))
1.70 - region.append_inline(Text(serialise(cell) + trailing))
1.71 + region.append_inline(Text(serialise(node, serialiser)))
1.72 +
1.73 + region.append_inline(Text(serialise(cell, serialiser) + trailing))
1.74
1.75 self.new_block(region)
1.76 return