forked from LiveCarta/BookConverter
Add ability to replace tags based on parents/children
This commit is contained in:
@@ -142,12 +142,25 @@ def _wrap_tags_with_table(chapter_tag):
|
||||
|
||||
def _tags_to_correspond_livecarta_tag(chapter_tag):
|
||||
"""Function to replace all tags to correspond livecarta tags"""
|
||||
for reg_key, to_replace_value in LiveCartaConfig.REPLACE_REGEX_WITH_LIVECARTA_CORRESPOND_TAGS.items():
|
||||
for key in reg_key:
|
||||
tags = chapter_tag.find_all(re.compile(key))
|
||||
for tag in tags:
|
||||
# todo can cause appearance of \n <p><p>...</p></p> -> <p>\n</p> <p>...</p> <p>\n</p> (section)
|
||||
tag.name = to_replace_value
|
||||
for reg_keys, to_replace_value in LiveCartaConfig.REPLACE_TAG_WITH_LIVECARTA_CORRESPOND_TAGS.items():
|
||||
for key in reg_keys:
|
||||
if isinstance(key, tuple):
|
||||
replace = key[0]
|
||||
parent, child = key[1], key[2]
|
||||
for parent_tag in chapter_tag.select(parent):
|
||||
if replace == "parent":
|
||||
parent_tag.name = to_replace_value
|
||||
elif replace == "child":
|
||||
for child_tag in parent_tag.select(child):
|
||||
child_tag.name = to_replace_value
|
||||
if not child_tag.attrs.get("style"):
|
||||
child_tag.attrs["style"] =\
|
||||
"font-size: 14px; font-family: courier new,courier,monospace;"
|
||||
else:
|
||||
tags = chapter_tag.find_all(re.compile(key))
|
||||
for tag in tags:
|
||||
# todo can cause appearance of \n <p><p>...</p></p> -> <p>\n</p> <p>...</p> <p>\n</p> (section)
|
||||
tag.name = to_replace_value
|
||||
|
||||
|
||||
def _unwrap_tags(chapter_tag):
|
||||
|
||||
Reference in New Issue
Block a user