epub converter: update

This commit is contained in:
shirshasa
2021-04-23 15:21:24 +03:00
parent d5dc3529b7
commit 6cd4f9401d
4 changed files with 16 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import codecs
import json
from os.path import dirname, normpath, join
from collections import defaultdict
from typing import Dict, Union
@@ -89,8 +90,12 @@ class EpubPostprocessor:
css_href = tag.attrs.get('href')
self.html_href2css_href[item.file_name] = css_href
if css_href not in self.css_href2content:
print(css_href)
css_content: str = self.ebooklib_book.get_item_with_href(css_href).get_content().decode()
path_to_css_from_html = css_href
html_folder = dirname(item.file_name)
path_to_css_from_root = normpath(join(html_folder, path_to_css_from_html))
css_obj = self.ebooklib_book.get_item_with_href(path_to_css_from_root)
assert css_obj, f'Css style {css_href} was not in manifest.'
css_content: str = css_obj.get_content().decode()
self.css_href2content[css_href] = clean_css(css_content)
for i, tag in enumerate(soup.find_all('style')):