1.1 --- a/xmlparser.py Fri Jun 16 19:06:27 2017 +0200
1.2 +++ b/xmlparser.py Fri Jun 16 19:46:09 2017 +0200
1.3 @@ -80,11 +80,16 @@
1.4 "ul" : "* %s",
1.5 }
1.6
1.7 +formatted_tags = ["ac:rich-text-body"]
1.8 +layout_tags = ["ac:layout", "ac:layout-section", "ac:layout-cell"]
1.9 preformatted_tags = ["pre", "ac:plain-text-body"]
1.10 single_level_tags = ["strong", "em", "u", "del", "sup", "sub", "code"]
1.11 -formatted_tags = ["ac:layout", "ac:rich-text-body", "table"]
1.12 +table_tags = ["ac:task-list", "table"]
1.13 +table_cell_tags = ["ac:task-body", "ac:task-status", "td", "th"]
1.14 +table_row_tags = ["ac:task", "tr"]
1.15
1.16 -indented_tags = ["li", "p"] + preformatted_tags + formatted_tags
1.17 +hierarchical_tags = formatted_tags + preformatted_tags + layout_tags + table_tags
1.18 +indented_tags = ["li", "p"] + hierarchical_tags
1.19 block_tags = indented_tags + blocktypes.keys() + list_tags.keys()
1.20 span_override_tags = ["ac:link"]
1.21
1.22 @@ -194,7 +199,7 @@
1.23 # Track cumulative element nesting in order to produce appropriate depth
1.24 # indicators in the formatted output.
1.25
1.26 - if name in preformatted_tags or name in formatted_tags:
1.27 + if name in hierarchical_tags:
1.28 self.level += 1
1.29 self.max_level = max(self.level, self.max_level)
1.30
1.31 @@ -218,7 +223,7 @@
1.32 # Reset the indent for any preformatted/formatted region so that it may
1.33 # itself be indented.
1.34
1.35 - if name in preformatted_tags or name in formatted_tags:
1.36 + if name in hierarchical_tags:
1.37 self.indents.pop()
1.38
1.39 Parser.endElement(self, name)
1.40 @@ -229,7 +234,7 @@
1.41 if self.states.has_key(name):
1.42 self.states[name] -= 1
1.43
1.44 - if name in preformatted_tags or name in formatted_tags:
1.45 + if name in hierarchical_tags:
1.46 self.level -= 1
1.47 if not self.level:
1.48 self.max_level = 0
1.49 @@ -264,9 +269,9 @@
1.50
1.51 # Handle state.
1.52
1.53 - if name == "table":
1.54 + if name in table_tags:
1.55 self.table_rows = 0
1.56 - elif name == "tr":
1.57 + elif name in table_row_tags:
1.58 self.table_columns = 0
1.59
1.60 # Find conversions.
1.61 @@ -348,7 +353,7 @@
1.62
1.63 # Handle preformatted sections.
1.64
1.65 - elif name in preformatted_tags or name in formatted_tags:
1.66 + elif name in hierarchical_tags:
1.67
1.68 # Nest the section appropriately.
1.69
1.70 @@ -358,7 +363,7 @@
1.71
1.72 # Macro name information is used to style rich text body regions.
1.73
1.74 - if name != "table" and self.macros and macro_rich_text_styles.has_key(self.macros[-1]):
1.75 + if name not in table_tags and self.macros and macro_rich_text_styles.has_key(self.macros[-1]):
1.76 details = macro_rich_text_styles[self.macros[-1]]
1.77 title = self.macro_parameters[-1].get("title")
1.78 if title:
1.79 @@ -366,12 +371,21 @@
1.80
1.81 conversion = "%s#!wiki %s\n\n%%s\n%s" % (opening, details, closing)
1.82
1.83 - elif name == "table":
1.84 + # Tables employ specially-marked sections.
1.85 +
1.86 + elif name in table_tags:
1.87 conversion = "%s#!table\n%%s\n%s" % (opening, closing)
1.88
1.89 + # Layout tags may be nested and their markers are placed on separate
1.90 + # lines in the output. They also employ specially-marked sections.
1.91 +
1.92 + elif name in layout_tags:
1.93 + section_name = name.split(":", 1)[-1]
1.94 + conversion = "%s#!%s\n%%s\n%s" % (opening, section_name, closing)
1.95 +
1.96 else:
1.97 - # Preformatted sections containing newlines must contain an initial
1.98 - # newline.
1.99 + # Preformatted sections containing newlines must contain an
1.100 + # initial newline.
1.101
1.102 if text.find("\n") != -1 and not text.startswith("\n"):
1.103 opening += "\n"
1.104 @@ -453,11 +467,11 @@
1.105
1.106 # Postprocess table columns and rows.
1.107
1.108 - if name in ("th", "td"):
1.109 + if name in table_cell_tags:
1.110 if self.table_columns:
1.111 text = "\n|| %s" % text
1.112 self.table_columns += 1
1.113 - elif name == "tr":
1.114 + elif name in table_row_tags:
1.115 if self.table_rows:
1.116 text = "\n==\n%s" % text
1.117 self.table_rows += 1