Commit 0dfccc2e authored by eckhart's avatar eckhart
Browse files

- syntaxstree supports attribute "xml:space"

parent 141f02ef
...@@ -644,7 +644,8 @@ class Node(collections.abc.Sized): ...@@ -644,7 +644,8 @@ class Node(collections.abc.Sized):
thereby signalling that the children of this node shall not be thereby signalling that the children of this node shall not be
printed on several lines to avoid unwanted gaps in the output. printed on several lines to avoid unwanted gaps in the output.
""" """
return node.tag_name in inline_tags return node.tag_name in inline_tags or (hasattr(node, '_xml_attr') \
and node.attributes.get('xml:space', 'default') == 'preserve')
line_breaks = linebreaks(src) if src else [] line_breaks = linebreaks(src) if src else []
return self._tree_repr(' ' * indentation, opening, closing, return self._tree_repr(' ' * indentation, opening, closing,
......
...@@ -257,13 +257,20 @@ class TestSerialization: ...@@ -257,13 +257,20 @@ class TestSerialization:
def test_xml_inlining(self): def test_xml_inlining(self):
tree = parse_sxpr('(A (B "C") (D "E"))') tree = parse_sxpr('(A (B "C") (D "E"))')
# obsolete: tree.attributes['_inline'] = "1"
xml = tree.as_xml(inline_tags={'A'}) xml = tree.as_xml(inline_tags={'A'})
assert xml == "<A>\n <B>C</B><D>E</D>\n</A>" assert xml == "<A>\n <B>C</B><D>E</D>\n</A>", xml
assert tree.as_xml() != "<A>\n <B>C</B><D>E</D>\n</A>", xml
tree.attributes['xml:space'] = 'preserve'
xml = tree.as_xml()
assert xml == '<A xml:space="preserve">\n <B>C</B><D>E</D>\n</A>', xml
tree = parse_sxpr('(A (B (C "D") (E "F")) (G "H"))') tree = parse_sxpr('(A (B (C "D") (E "F")) (G "H"))')
# obsolete: tree.attributes['_inline'] = "1"
xml = tree.as_xml(inline_tags={'A'}) xml = tree.as_xml(inline_tags={'A'})
assert xml == "<A>\n <B><C>D</C><E>F</E></B><G>H</G>\n</A>" assert xml == "<A>\n <B><C>D</C><E>F</E></B><G>H</G>\n</A>", xml
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment