forked from LiveCarta/BookConverter
Add bg-color to code tags
This commit is contained in:
@@ -526,7 +526,7 @@ def preprocess_block_tags(chapter_tag):
|
|||||||
wrap_block_tag_with_table(chapter_tag, future_block, bg_color=color)
|
wrap_block_tag_with_table(chapter_tag, future_block, bg_color=color)
|
||||||
|
|
||||||
|
|
||||||
def prepare_formatted(text):
|
def prepare_formatted(text: str) -> str:
|
||||||
"""Function replaces special symbols with their Unicode representation"""
|
"""Function replaces special symbols with their Unicode representation"""
|
||||||
text = text.replace("<", "\x3C")
|
text = text.replace("<", "\x3C")
|
||||||
text = text.replace(">", "\x3E")
|
text = text.replace(">", "\x3E")
|
||||||
@@ -554,7 +554,19 @@ def wrap_preformatted_span_with_table(main_tag, old_tag):
|
|||||||
|
|
||||||
|
|
||||||
def preprocess_pre_tags(chapter_tag):
|
def preprocess_pre_tags(chapter_tag):
|
||||||
"""Function preprocessing <pre> tags"""
|
"""Function preprocessing <pre> tags
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
chapter_tag: BeautifulSoup
|
||||||
|
|
||||||
|
Steps
|
||||||
|
----------
|
||||||
|
1. cleaning \n
|
||||||
|
2. heading removal
|
||||||
|
3. processing tags
|
||||||
|
4. class removal
|
||||||
|
"""
|
||||||
|
|
||||||
for pre in chapter_tag.find_all("pre"):
|
for pre in chapter_tag.find_all("pre"):
|
||||||
new_tag = BeautifulSoup(features='lxml').new_tag("span")
|
new_tag = BeautifulSoup(features='lxml').new_tag("span")
|
||||||
new_tag.attrs = pre.attrs.copy()
|
new_tag.attrs = pre.attrs.copy()
|
||||||
@@ -592,19 +604,23 @@ def preprocess_pre_tags(chapter_tag):
|
|||||||
table.insert_after(p_for_br)
|
table.insert_after(p_for_br)
|
||||||
|
|
||||||
|
|
||||||
def preprocess_code_tags(chapter_tag):
|
def preprocess_code_tags(chapter_tag: Tag):
|
||||||
"""Function that emulates style of <code>, <kdb>, <var>"""
|
"""Function that
|
||||||
for parent_tag in chapter_tag.find_all(re.compile("pre|p")):
|
- transform <code>, <kdb>, <var> tags into span
|
||||||
for code in parent_tag.find_all(re.compile("code|kbd|var")):
|
- add code style to this tags
|
||||||
# if code.name == "code":
|
"""
|
||||||
# parent_tag.name = "pre"
|
|
||||||
|
for code in chapter_tag.find_all(re.compile("code|kbd|var")):
|
||||||
code.name = "span"
|
code.name = "span"
|
||||||
if parent_tag.name == "pre":
|
if code.parent.name == "pre":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# if tags aren't in pre
|
# if tags aren't in pre
|
||||||
|
if not code.attrs.get('style'):
|
||||||
code.attrs['style'] = 'font-size: 14px; font-family: courier new,courier,monospace;'
|
code.attrs['style'] = 'font-size: 14px; font-family: courier new,courier,monospace;'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_title(title_of_chapter: str) -> str:
|
def prepare_title(title_of_chapter: str) -> str:
|
||||||
"""Function finalise processing/cleaning title"""
|
"""Function finalise processing/cleaning title"""
|
||||||
title_str = BeautifulSoup(title_of_chapter, features='lxml').string
|
title_str = BeautifulSoup(title_of_chapter, features='lxml').string
|
||||||
@@ -633,7 +649,8 @@ def prepare_content(title_str: str, content_tag: BeautifulSoup, remove_title_fro
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
prepared content: str
|
content_tag: str
|
||||||
|
prepared content
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 0. cleaning \n
|
# 0. cleaning \n
|
||||||
|
|||||||
Reference in New Issue
Block a user