forked from LiveCarta/BookConverter
html_presets_processor.py changed structure of presets
This commit is contained in:
@@ -24,7 +24,7 @@ class HtmlPresetsProcessor:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _wrap_tag(**kwargs):
|
def _wrap_tag(**kwargs):
|
||||||
kwargs["tag"].wrap(kwargs["body_tag"].new_tag(
|
kwargs["tag"].wrap(kwargs["body_tag"].new_tag(
|
||||||
kwargs["rule"]["tag_to_wrap"]))
|
kwargs["rule"]["tag_to_wrap"]["name"]))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_attrs_to_parent(tag, parent_tag):
|
def set_attrs_to_parent(tag, parent_tag):
|
||||||
@@ -98,24 +98,31 @@ class HtmlPresetsProcessor:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _replace_tag(**kwargs):
|
def _replace_tag(**kwargs):
|
||||||
tag_to_replace: str = kwargs["rule"]["tag_to_replace"]
|
tag_to_replace: str = kwargs["rule"]["tag_to_replace"]["name"]
|
||||||
kwargs["tag"].name = tag_to_replace
|
kwargs["tag"].name = tag_to_replace
|
||||||
|
if kwargs["rule"]["tag_to_replace"].get("attrs"):
|
||||||
|
dict_attributes = {attr["name"]: attr["value"]
|
||||||
|
for attr in kwargs["rule"]["tag_to_replace"]["attrs"]}
|
||||||
|
kwargs["tag"].attrs = dict_attributes
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _replace_attr(**kwargs):
|
def _replace_attr(**kwargs):
|
||||||
attr, attr_value =\
|
attr = kwargs["rule"]["condition"]["attrs"][0]
|
||||||
kwargs["rule"]["attr"]["name"], kwargs["rule"]["attr"]["value"]
|
attr_name, attr_value =\
|
||||||
|
attr["name"], attr["value"]
|
||||||
attr_to_replace, attr_value_to_replace =\
|
attr_to_replace, attr_value_to_replace =\
|
||||||
kwargs["rule"]["attr_to_replace"]["name"], kwargs["rule"]["attr_to_replace"]["value"]
|
kwargs["rule"]["attr_to_replace"]["name"], kwargs["rule"]["attr_to_replace"]["value"]
|
||||||
if attr_to_replace:
|
if attr_to_replace:
|
||||||
kwargs["tag"][attr_to_replace] = kwargs["tag"][attr]
|
kwargs["tag"][attr_to_replace] = kwargs["tag"][attr_name] \
|
||||||
|
if kwargs["tag"].get(attr_name)\
|
||||||
|
else ""
|
||||||
if attr_value_to_replace:
|
if attr_value_to_replace:
|
||||||
kwargs["tag"].attrs[attr_to_replace] = attr_value_to_replace
|
kwargs["tag"].attrs[attr_to_replace] = attr_value_to_replace
|
||||||
del kwargs["tag"][attr]
|
del kwargs["tag"][attr_name]
|
||||||
elif attr_value_to_replace:
|
elif attr_value_to_replace:
|
||||||
kwargs["tag"].attrs[attr] = attr_value_to_replace
|
kwargs["tag"].attrs[attr_name] = attr_value_to_replace
|
||||||
elif attr:
|
elif attr_name:
|
||||||
del kwargs["tag"][attr]
|
del kwargs["tag"][attr_name]
|
||||||
|
|
||||||
def _unwrap_tag(self, **kwargs):
|
def _unwrap_tag(self, **kwargs):
|
||||||
if kwargs["tag"].parent:
|
if kwargs["tag"].parent:
|
||||||
@@ -124,8 +131,11 @@ class HtmlPresetsProcessor:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _insert_tag(**kwargs):
|
def _insert_tag(**kwargs):
|
||||||
|
dict_attributes = {attr["name"]: attr["value"]
|
||||||
|
for attr in kwargs["rule"]["tag_to_insert"]["attrs"]}
|
||||||
tag_to_insert = \
|
tag_to_insert = \
|
||||||
kwargs["body_tag"].new_tag(kwargs["rule"]["tag_to_insert"])
|
kwargs["body_tag"].new_tag(
|
||||||
|
kwargs["rule"]["tag_to_insert"]["name"], attrs=dict_attributes)
|
||||||
# insert all items that was in tag to subtag and remove from tag
|
# insert all items that was in tag to subtag and remove from tag
|
||||||
for content in reversed(kwargs["tag"].contents):
|
for content in reversed(kwargs["tag"].contents):
|
||||||
tag_to_insert.insert(0, content.extract())
|
tag_to_insert.insert(0, content.extract())
|
||||||
|
|||||||
Reference in New Issue
Block a user