Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
for item in items:
item_id = id(item)
if item_id not in elements:
elements[item_id] = {"item": item, "classes": [], "style": []}
elements[item_id]["style"].append(processed_style)
elements[item_id]["classes"].append(class_)
# Now apply inline style
# merge style only once for each element
# crucial when you have a lot of pseudo/classes
# and a long list of elements
for _, element in elements.items():
final_style = merge_styles(
element["item"].attrib.get("style", ""),
element["style"],
element["classes"],
remove_unset_properties=self.remove_unset_properties,
)
if final_style:
# final style could be empty string because of
# remove_unset_properties
element["item"].attrib["style"] = final_style
self._style_to_basic_html_attributes(
element["item"], final_style, force=True
)
if self.remove_classes:
# now we can delete all 'class' attributes
for item in page.xpath("//@class"):
if item_id not in elements:
elements[item_id] = {
'item': item,
'classes': [],
'style': [],
}
elements[item_id]['style'].append(processed_style)
elements[item_id]['classes'].append(class_)
# Now apply inline style
# merge style only once for each element
# crucial when you have a lot of pseudo/classes
# and a long list of elements
for _, element in elements.items():
final_style = merge_styles(
element['item'].attrib.get('style', ''),
element['style'],
element['classes'],
remove_unset_properties=self.remove_unset_properties,
)
if final_style:
# final style could be empty string because of
# remove_unset_properties
element['item'].attrib['style'] = final_style
self._style_to_basic_html_attributes(
element['item'],
final_style,
force=True
)
if self.remove_classes: