# HG changeset patch # User Paul Boddie # Date 1497635169 -7200 # Node ID 72d0d89748c72dc3f8d5e099bf3cb37c9e16d0a6 # Parent 1d93ae7fe8edc386dd8d8a5262320cfd439c278b Introduced elementary support for layout tags, employing special sections, and task list tags, converting task lists to tables. diff -r 1d93ae7fe8ed -r 72d0d89748c7 xmlparser.py --- a/xmlparser.py Fri Jun 16 19:06:27 2017 +0200 +++ b/xmlparser.py Fri Jun 16 19:46:09 2017 +0200 @@ -80,11 +80,16 @@ "ul" : "* %s", } +formatted_tags = ["ac:rich-text-body"] +layout_tags = ["ac:layout", "ac:layout-section", "ac:layout-cell"] preformatted_tags = ["pre", "ac:plain-text-body"] single_level_tags = ["strong", "em", "u", "del", "sup", "sub", "code"] -formatted_tags = ["ac:layout", "ac:rich-text-body", "table"] +table_tags = ["ac:task-list", "table"] +table_cell_tags = ["ac:task-body", "ac:task-status", "td", "th"] +table_row_tags = ["ac:task", "tr"] -indented_tags = ["li", "p"] + preformatted_tags + formatted_tags +hierarchical_tags = formatted_tags + preformatted_tags + layout_tags + table_tags +indented_tags = ["li", "p"] + hierarchical_tags block_tags = indented_tags + blocktypes.keys() + list_tags.keys() span_override_tags = ["ac:link"] @@ -194,7 +199,7 @@ # Track cumulative element nesting in order to produce appropriate depth # indicators in the formatted output. - if name in preformatted_tags or name in formatted_tags: + if name in hierarchical_tags: self.level += 1 self.max_level = max(self.level, self.max_level) @@ -218,7 +223,7 @@ # Reset the indent for any preformatted/formatted region so that it may # itself be indented. - if name in preformatted_tags or name in formatted_tags: + if name in hierarchical_tags: self.indents.pop() Parser.endElement(self, name) @@ -229,7 +234,7 @@ if self.states.has_key(name): self.states[name] -= 1 - if name in preformatted_tags or name in formatted_tags: + if name in hierarchical_tags: self.level -= 1 if not self.level: self.max_level = 0 @@ -264,9 +269,9 @@ # Handle state. - if name == "table": + if name in table_tags: self.table_rows = 0 - elif name == "tr": + elif name in table_row_tags: self.table_columns = 0 # Find conversions. @@ -348,7 +353,7 @@ # Handle preformatted sections. - elif name in preformatted_tags or name in formatted_tags: + elif name in hierarchical_tags: # Nest the section appropriately. @@ -358,7 +363,7 @@ # Macro name information is used to style rich text body regions. - if name != "table" and self.macros and macro_rich_text_styles.has_key(self.macros[-1]): + if name not in table_tags and self.macros and macro_rich_text_styles.has_key(self.macros[-1]): details = macro_rich_text_styles[self.macros[-1]] title = self.macro_parameters[-1].get("title") if title: @@ -366,12 +371,21 @@ conversion = "%s#!wiki %s\n\n%%s\n%s" % (opening, details, closing) - elif name == "table": + # Tables employ specially-marked sections. + + elif name in table_tags: conversion = "%s#!table\n%%s\n%s" % (opening, closing) + # Layout tags may be nested and their markers are placed on separate + # lines in the output. They also employ specially-marked sections. + + elif name in layout_tags: + section_name = name.split(":", 1)[-1] + conversion = "%s#!%s\n%%s\n%s" % (opening, section_name, closing) + else: - # Preformatted sections containing newlines must contain an initial - # newline. + # Preformatted sections containing newlines must contain an + # initial newline. if text.find("\n") != -1 and not text.startswith("\n"): opening += "\n" @@ -453,11 +467,11 @@ # Postprocess table columns and rows. - if name in ("th", "td"): + if name in table_cell_tags: if self.table_columns: text = "\n|| %s" % text self.table_columns += 1 - elif name == "tr": + elif name in table_row_tags: if self.table_rows: text = "\n==\n%s" % text self.table_rows += 1