5 Commits

Author SHA1 Message Date
AaronBenDaniel 3f5cd7985d fix(api): Carry over paragraph styling (#51) 2025-04-12 23:22:14 +05:30
AaronBenDaniel 52faaf54c2 fix(api): Stopped extra newlines from appearing with bold/italics (#40) 2025-04-04 07:46:05 +05:30
AaronBenDaniel e79453ab5f fix(api): Strip control characters from chapter titles (#47) 2025-02-15 16:34:28 +05:30
AaronBenDaniel d30f15a254 fix(api): Remove unused class (#43 - @AaronBenDaniel)
* fix(api): Typo fix

* fix(api): Remove chapitre/chapter class
2025-01-24 17:20:21 +05:30
AaronBenDaniel 08ff95d686 fix(api): Fix PDF ToC page number formatting 2025-01-01 06:07:36 +05:30
2 changed files with 26 additions and 30 deletions
+24 -30
View File
@@ -133,7 +133,7 @@ def generate_clean_part_html(part: Part, content: str) -> bs4.Tag:
clean = BeautifulSoup( clean = BeautifulSoup(
f""" f"""
<section id="section_{chapter_id}" class="chapitre"> <section id="section_{chapter_id}">
<h1 id="{chapter_id}" class="chapter-title">{chapter_title}</h1> <h1 id="{chapter_id}" class="chapter-title">{chapter_title}</h1>
</section> </section>
""", """,
@@ -151,6 +151,14 @@ def generate_clean_part_html(part: Part, content: str) -> bs4.Tag:
raise Exception() raise Exception()
for child in html.find_all("p"): for child in html.find_all("p"):
current_paragraph = clean.new_tag("p")
# Attempt to carry over paragraph styling
try:
current_paragraph["style"] = child["style"]
except:
current_paragraph["style"] = "text-align: left;"
for p_child in list(child.children): for p_child in list(child.children):
if not p_child: if not p_child:
continue continue
@@ -161,37 +169,22 @@ def generate_clean_part_html(part: Part, content: str) -> bs4.Tag:
src = p_child["src"] src = p_child["src"]
img_tag = clean.new_tag("img") img_tag = clean.new_tag("img")
img_tag["src"] = src img_tag["src"] = src
break_tag = clean.new_tag("br")
section.append(img_tag) section.append(img_tag)
section.append(break_tag) section.append(clean.new_tag("br"))
elif p_child.name == "b": elif p_child.name in ["b", "i"]:
content = p_child.text styled_tag = clean.new_tag(p_child.name)
p_tag = clean.new_tag("p") styled_content = clean.new_string(p_child.text)
bold_tag = clean.new_tag("b") styled_tag.append(styled_content)
bold_content = clean.new_string(content) current_paragraph.append(styled_tag)
else:
bold_tag.append(bold_content) # Append any other tags as-is
p_tag.append(bold_tag) current_paragraph.append(p_child)
section.append(p_tag)
elif p_child.name == "i":
content = p_child.text
p_tag = clean.new_tag("p")
italic_tag = clean.new_tag("i")
italic_content = clean.new_string(content)
italic_tag.append(italic_content)
p_tag.append(italic_tag)
section.append(p_tag)
elif isinstance(p_child, bs4.element.NavigableString): elif isinstance(p_child, bs4.element.NavigableString):
content = p_child.text content = clean.new_string(p_child)
p_tag = clean.new_tag("p") current_paragraph.append(content)
p_content = clean.new_string(content)
p_tag.append(p_content) if current_paragraph.contents:
section.append(p_tag) section.append(current_paragraph)
if not list(child.children): if not list(child.children):
# Some p tags only contain brs, once brs are removed, they are empty and can be removed as well. # Some p tags only contain brs, once brs are removed, they are empty and can be removed as well.
@@ -461,6 +454,7 @@ class EPUBGenerator:
for cidx, (part, content) in enumerate(zip(self.data["parts"], contents)): for cidx, (part, content) in enumerate(zip(self.data["parts"], contents)):
title = part["title"] title = part["title"]
title = re.sub(r'[\x00-\x1F\x7F]', '', title) # Remove control characters
# Thanks https://eu17.proxysite.com/process.php?d=5VyWYcoQl%2BVF0BYOuOavtvjOloFUZz2BJ%2Fepiusk6Nz7PV%2B9i8rs7cFviGftrBNll%2B0a3qO7UiDkTt4qwCa0fDES&b=1 # Thanks https://eu17.proxysite.com/process.php?d=5VyWYcoQl%2BVF0BYOuOavtvjOloFUZz2BJ%2Fepiusk6Nz7PV%2B9i8rs7cFviGftrBNll%2B0a3qO7UiDkTt4qwCa0fDES&b=1
chapter = epub.EpubHtml( chapter = epub.EpubHtml(
+2
View File
@@ -205,6 +205,8 @@ section {
#contents a { #contents a {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
display: flex;
justify-content: space-between;
} }
#contents a::before { #contents a::before {
content: target-counter(attr(href), h2-counter) '. ' target-text(attr(href)); content: target-counter(attr(href), h2-counter) '. ' target-text(attr(href));