This commit is contained in:
Kovid Goyal 2025-02-20 12:58:28 +05:30
parent d5aa4da720
commit d8a744ceea
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 4 deletions

View File

@ -16,7 +16,7 @@ import re
from lxml import etree
from calibre.ebooks.oeb.base import XHTML, XPath
from calibre.ebooks.oeb.base import XHTML, XPath, serialize
from calibre.ebooks.oeb.parse_utils import barename, merge_multiple_html_heads_and_bodies
from calibre.ebooks.oeb.polish.parsing import parse
from calibre.ebooks.oeb.polish.tts import lang_for_elem
@ -177,6 +177,10 @@ def remove_kobo_markup_from_html(root):
unwrap_body_contents(body)
def serialize_html(root) -> bytes:
return serialize(root, 'text/html')
def kepubify_parsed_html(root, metadata_lang: str = 'en'):
remove_kobo_markup_from_html(root)
merge_multiple_html_heads_and_bodies(root)

View File

@ -2,8 +2,7 @@
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
from calibre.ebooks.oeb.base import serialize
from calibre.ebooks.oeb.polish.kepubify import kepubify_html_data
from calibre.ebooks.oeb.polish.kepubify import kepubify_html_data, serialize_html
from calibre.ebooks.oeb.polish.tests.base import BaseTest
@ -53,6 +52,6 @@ div#book-inner { margin-top: 0; margin-bottom: 0; }</style></head><body><div id=
}.items():
with self.subTest(src=src):
root = kepubify_html_data(src)
actual = serialize(root, 'text/html').decode('utf-8')
actual = serialize_html(root).decode('utf-8')
actual = actual[len(prefix):-len(suffix)]
self.assertEqual(expected, actual)