Skip to content

Commit 1e40da3

Browse files
committed
removes debugging attributes from the target output
1 parent bd7e911 commit 1e40da3

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/auxml/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ def __init__(self):
2222

2323
exp = mm.expand_all(fname, root)
2424
self.save(exp)
25-
25+
26+
2627
def save(self, el):
28+
remove_debug_attrs(el)
2729
open(cmdline.outfile(), 'wb').write(etree.tostring(el, method="html"))
2830

2931
def main():

src/auxml/parser.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,23 @@ def parse_string(s):
4242
soup = BeautifulSoup(s, "html.parser")
4343
tree = etree.fromstring(str(soup), _xml_parser)
4444
return tree
45+
46+
# mutates
47+
def deep_rm_attr(el, attr_name):
48+
'''recursively descend through all elements removing attributes
49+
with `attr_name`.'''
50+
51+
if el is None:
52+
return
53+
54+
if attr_name in el.attrib:
55+
del el.attrib[attr_name]
56+
57+
for child in el:
58+
deep_rm_attr(child, attr_name)
59+
60+
61+
# mutates
62+
def remove_debug_attrs(el):
63+
deep_rm_attr(el, ATTR_FILENAME)
64+
deep_rm_attr(el, ATTR_LINENUM)

0 commit comments

Comments
 (0)