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
8b148543
Commit
8b148543
authored
May 15, 2018
by
eckhart
Browse files
- syntaxtree.Node.as_xml: prepare whitespace handling
parent
19c7acea
Changes
1
Hide whitespace changes
Inline
Side-by-side
DHParser/syntaxtree.py
View file @
8b148543
...
...
@@ -566,23 +566,30 @@ class Node(collections.abc.Sized):
column.
"""
inline
=
False
def
opening
(
node
)
->
str
:
"""Returns the opening string for the representation of `node`."""
txt
=
[
'<'
,
node
.
tag_name
]
has_reserved_attrs
=
hasattr
(
node
,
'_xml_attr'
)
\
and
any
(
r
in
node
.
attributes
for
r
in
{
'err'
,
'line'
,
'col'
})
nonlocal
inline
inline
=
False
if
hasattr
(
node
,
'_xml_attr'
):
if
'_inline'
in
node
.
attributes
:
inline
=
True
del
node
.
attributes
[
'_inline'
]
txt
.
extend
(
' %s="%s"'
%
(
k
,
v
)
for
k
,
v
in
node
.
attributes
.
items
())
if
src
and
not
has_reserved_attrs
:
txt
.
append
(
' line="%i" col="%i"'
%
line_col
(
line_breaks
,
node
.
pos
))
if
showerrors
and
node
.
errors
and
not
has_reserved_attrs
:
txt
.
append
(
' err="%s"'
%
''
.
join
(
str
(
err
).
replace
(
'"'
,
r
'\"'
)
for
err
in
node
.
errors
))
return
""
.
join
(
txt
+
[
">
\n
"
])
return
""
.
join
(
txt
+
[
">"
if
inline
else
">
\n
"
])
def
closing
(
node
):
"""Returns the closing string for the representation of `node`."""
return
'
\n
</'
+
node
.
tag_name
+
'>'
return
(
'</'
if
inline
else
'
\n
</'
)
+
node
.
tag_name
+
'>'
line_breaks
=
linebreaks
(
src
)
if
src
else
[]
return
self
.
_tree_repr
(
' '
*
indentation
,
opening
,
closing
,
density
=
1
)
...
...
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