1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/test_xml_lists_blocks.txt Thu Apr 11 13:07:34 2013 +0200
1.3 @@ -0,0 +1,8 @@
1.4 +<ul>
1.5 +<li><a href="http://moinmo.in/">A link</a> and following text</li>
1.6 +<li>An item with <pre>preformatted text</pre> and following text</li>
1.7 +<li>An item with <ac:plain-text-body>raw preformatted text</ac:plain-text-body> and more text</li>
1.8 +<li>An item with <ac:macro name="code"><ac:plain-text-body>preformatted text</ac:plain-text-body></ac:macro> and more text</li>
1.9 +<li>An item with <a href="http://moinmo.in/">a link</a> and following text</li>
1.10 +<li><a href="http://moinmo.in/">A link</a> and following text and <a href="http://moinmo.in/">another link</a></li>
1.11 +</ul>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/test_xml_lists_links.txt Thu Apr 11 13:07:34 2013 +0200
2.3 @@ -0,0 +1,4 @@
2.4 +<ul>
2.5 +<li><a href="http://list.org">Mailman</a></li>
2.6 +<li><a href="http://list.org">Mailman</a> versus <a href="http://moinmo.in/">MoinMoin</a></li>
2.7 +</ul>
3.1 --- a/xmlparser.py Wed Apr 10 19:16:14 2013 +0200
3.2 +++ b/xmlparser.py Thu Apr 11 13:07:34 2013 +0200
3.3 @@ -81,6 +81,7 @@
3.4
3.5 indented_tags = ["li", "p"] + preformatted_tags + formatted_tags
3.6 block_tags = indented_tags + blocktypes.keys() + list_tags.keys()
3.7 +span_override_tags = ["ac:link"]
3.8
3.9 link_target_tags = {
3.10 # Confluence element Attributes providing the target
3.11 @@ -328,7 +329,7 @@
3.12 if name in ("ac:link", "ac:image"):
3.13 prefix = link_target_types.get(self.target_type, "")
3.14 anchor = self.attributes[-1].get("ac:anchor")
3.15 - text = conversion % (prefix, anchor or self.target, self.label or text or self.target)
3.16 + text = conversion % (prefix, anchor or self.target, self.label or text.strip() or self.target)
3.17 self.target = self.target_type = self.label = None
3.18
3.19 elif name == "a":
3.20 @@ -362,11 +363,11 @@
3.21
3.22 if len(self.text) > 1:
3.23 nodes = self.text[-2]
3.24 + parent = self.elements[-2]
3.25
3.26 # Where preceding text exists, add any blank line separators.
3.27
3.28 if "".join(nodes):
3.29 - parent = self.elements[-2]
3.30
3.31 # All top-level elements are separated with blank lines.
3.32
3.33 @@ -375,15 +376,24 @@
3.34
3.35 # Block elements always cause a new line to be started.
3.36
3.37 - if name in block_tags or self.have_block:
3.38 + if name in block_tags or self.have_block and name not in span_override_tags:
3.39 nodes.append("\n")
3.40
3.41 self.have_block = False
3.42
3.43 - # Without preceding text, save any block node state so that new line
3.44 - # separators can be added at another level.
3.45 + # Lists inside lists require separation.
3.46 +
3.47 + elif list_tags.has_key(name) and parent == "li":
3.48 + nodes.append("\n")
3.49
3.50 - elif name in block_tags:
3.51 + # Without preceding text, save any block node state for non-block
3.52 + # elements so that new line separators can be added at another
3.53 + # level.
3.54 +
3.55 + elif name in block_tags and parent not in block_tags:
3.56 + self.have_block = True
3.57 +
3.58 + elif name not in block_tags and self.have_block and name not in span_override_tags:
3.59 self.have_block = True
3.60
3.61 else: