forked from LiveCarta/BookConverter
LAW-6611 | Add ability to remove attr value
This commit is contained in:
@@ -16,7 +16,7 @@ class HtmlPresetsProcessor:
|
|||||||
"table_wrapper": self._process_tag_using_table,
|
"table_wrapper": self._process_tag_using_table,
|
||||||
"decomposer": self._decompose_tag,
|
"decomposer": self._decompose_tag,
|
||||||
"replacer": self._replace_tag,
|
"replacer": self._replace_tag,
|
||||||
"attr_remover": self._remove_attrs,
|
"attr_remover": self._remove_attr,
|
||||||
"attr_replacer": self._replace_attr,
|
"attr_replacer": self._replace_attr,
|
||||||
"unwrapper": self._unwrap_tag,
|
"unwrapper": self._unwrap_tag,
|
||||||
"inserter": self._insert_tag,
|
"inserter": self._insert_tag,
|
||||||
@@ -155,8 +155,20 @@ class HtmlPresetsProcessor:
|
|||||||
kwargs["found_tag"].attrs = dict_attributes
|
kwargs["found_tag"].attrs = dict_attributes
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _remove_attrs(**kwargs):
|
def _remove_attr(**kwargs):
|
||||||
kwargs["found_tag"].attrs = {}
|
"""Deletes an attribute or part of an attribute value from an HTML tag"""
|
||||||
|
for attr in kwargs["rule"]["condition"]["attrs"]:
|
||||||
|
attr_name, attr_value = \
|
||||||
|
attr["name"], attr["value"]
|
||||||
|
if attr["value"] is None:
|
||||||
|
# delete entire attribute
|
||||||
|
del kwargs["found_tag"].attrs[attr_name]
|
||||||
|
else:
|
||||||
|
# delete part of attribute value
|
||||||
|
pattern = rf"{attr_value}:\s*[0-9.-]+[a-z%]*;*"
|
||||||
|
attr_string = str(kwargs["found_tag"][attr_name])
|
||||||
|
new_value = re.sub(pattern, "", attr_string)
|
||||||
|
kwargs["found_tag"][attr_name] = new_value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _replace_attr(**kwargs):
|
def _replace_attr(**kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user