Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
8c6c408e
Commit
8c6c408e
authored
May 17, 2018
by
eckhart
Browse files
- syntaxtree.Node.as_xml: xml_inlining is now transitive
parent
85e9b79a
Changes
2
Hide whitespace changes
Inline
Side-by-side
DHParser/syntaxtree.py
View file @
8c6c408e
...
...
@@ -466,7 +466,8 @@ class Node(collections.abc.Sized):
return
self
.
_xml_attr
def
_tree_repr
(
self
,
tab
,
open_fn
,
close_fn
,
data_fn
=
lambda
i
:
i
,
density
=
0
)
->
str
:
def
_tree_repr
(
self
,
tab
,
open_fn
,
close_fn
,
data_fn
=
lambda
i
:
i
,
density
=
0
,
inline
=
False
)
->
str
:
"""
Generates a tree representation of this node and its children
in string from.
...
...
@@ -496,15 +497,17 @@ class Node(collections.abc.Sized):
tail
=
tail
.
lstrip
(
None
if
density
&
2
else
''
)
sep
,
inner_tab
=
(
''
,
''
)
if
hasattr
(
self
,
'_xml_attr'
)
and
'_inline'
in
self
.
attributes
\
else
(
'
\n
'
,
tab
)
outer_tab
=
''
if
inline
else
tab
inline
=
inline
or
hasattr
(
self
,
'_xml_attr'
)
and
'_inline'
in
self
.
attributes
sep
,
inner_tab
=
(
''
,
''
)
if
inline
else
(
'
\n
'
,
tab
)
if
self
.
children
:
content
=
[]
for
child
in
self
.
children
:
subtree
=
child
.
_tree_repr
(
tab
,
open_fn
,
close_fn
,
data_fn
,
density
).
split
(
'
\n
'
)
subtree
=
child
.
_tree_repr
(
tab
,
open_fn
,
close_fn
,
data_fn
,
density
,
inline
).
split
(
'
\n
'
)
content
.
append
((
sep
+
inner_tab
).
join
(
s
for
s
in
subtree
))
return
head
+
tab
+
(
sep
+
inner_tab
).
join
(
content
)
+
tail
return
head
+
outer_
tab
+
(
sep
+
inner_tab
).
join
(
content
)
+
tail
res
=
cast
(
str
,
self
.
result
)
# safe, because if there are no children, result is a string
if
density
&
1
and
res
.
find
(
'
\n
'
)
<
0
:
# and head[0] == "<":
...
...
test/test_syntaxtree.py
View file @
8c6c408e
...
...
@@ -260,7 +260,10 @@ class TestSerialization:
tree
.
attributes
[
'_inline'
]
=
"1"
xml
=
tree
.
as_xml
()
assert
xml
==
"<A>
\n
<B>C</B><D>E</D>
\n
</A>"
tree
=
parse_sxpr
(
'(A (B (C "D") (E "F")) (G "H"))'
)
tree
.
attributes
[
'_inline'
]
=
"1"
xml
=
tree
.
as_xml
()
assert
xml
==
"<A>
\n
<B><C>D</C><E>F</E></B><G>H</G>
\n
</A>"
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