Skip to content

Commit 820c5c9

Browse files
author
p12
committed
Transform/DDG: remove attributes from the root description element
1 parent dbf6508 commit 820c5c9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ddg_parse_html.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def get_declaration(root_el, name):
123123
else:
124124
raise DdgException("No declarations after parsing")
125125

126+
def del_all_attrs(el):
127+
for key in el.attrib:
128+
del el.attrib[key]
126129
''' Processes description text. Drops all tags except <code> and <i>. Replaces
127130
<b> with <i>. Replaces span.mw-geshi with <code>. Returns the processed
128131
description as str. The description is limited to one sentence (delimited
@@ -135,13 +138,14 @@ def process_description(el):
135138

136139
el = deepcopy(el) # we'll modify the tree
137140
el.tag = 'root'
141+
del_all_attrs(el)
142+
138143
for t in el.xpath('.//span[contains(@class, "mw-geshi")]'):
139144
t.tag = 'code'
140145

141146
for t in el.xpath('.//*'):
142147
if t.tag in ['code', 'i', 'b']:
143-
for key in t.attrib:
144-
del t.attrib[key]
148+
del_all_attrs(t)
145149
else:
146150
t.drop_tag()
147151
desc = e.tostring(el, method='html', encoding=str, with_tail=False)

0 commit comments

Comments
 (0)