Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
badw-it
DHParser
Commits
0dfccc2e
Commit
0dfccc2e
authored
Jun 22, 2018
by
eckhart
Browse files
- syntaxstree supports attribute "xml:space"
parent
141f02ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
DHParser/syntaxtree.py
View file @
0dfccc2e
...
...
@@ -644,7 +644,8 @@ class Node(collections.abc.Sized):
thereby signalling that the children of this node shall not be
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
[]
return
self
.
_tree_repr
(
' '
*
indentation
,
opening
,
closing
,
...
...
test/test_syntaxtree.py
View file @
0dfccc2e
...
...
@@ -257,13 +257,20 @@ class TestSerialization:
def
test_xml_inlining
(
self
):
tree
=
parse_sxpr
(
'(A (B "C") (D "E"))'
)
# obsolete: tree.attributes['_inline'] = "1"
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"))'
)
# obsolete: tree.attributes['_inline'] = "1"
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__"
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment