mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
d5aa4da720
commit
d8a744ceea
@ -16,7 +16,7 @@ import re
|
|||||||
|
|
||||||
from lxml import etree
|
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.parse_utils import barename, merge_multiple_html_heads_and_bodies
|
||||||
from calibre.ebooks.oeb.polish.parsing import parse
|
from calibre.ebooks.oeb.polish.parsing import parse
|
||||||
from calibre.ebooks.oeb.polish.tts import lang_for_elem
|
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)
|
unwrap_body_contents(body)
|
||||||
|
|
||||||
|
|
||||||
|
def serialize_html(root) -> bytes:
|
||||||
|
return serialize(root, 'text/html')
|
||||||
|
|
||||||
|
|
||||||
def kepubify_parsed_html(root, metadata_lang: str = 'en'):
|
def kepubify_parsed_html(root, metadata_lang: str = 'en'):
|
||||||
remove_kobo_markup_from_html(root)
|
remove_kobo_markup_from_html(root)
|
||||||
merge_multiple_html_heads_and_bodies(root)
|
merge_multiple_html_heads_and_bodies(root)
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
|
# 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, serialize_html
|
||||||
from calibre.ebooks.oeb.polish.kepubify import kepubify_html_data
|
|
||||||
from calibre.ebooks.oeb.polish.tests.base import BaseTest
|
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():
|
}.items():
|
||||||
with self.subTest(src=src):
|
with self.subTest(src=src):
|
||||||
root = kepubify_html_data(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)]
|
actual = actual[len(prefix):-len(suffix)]
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user