From 229df85397a402c93f06138e1e3068a36563b793 Mon Sep 17 00:00:00 2001 From: Kiryl Date: Fri, 13 May 2022 13:35:25 +0300 Subject: [PATCH] Add ability to get file from import in css --- src/epub_converter/css_reader.py | 4 +++- src/epub_converter/epub_converter.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/epub_converter/css_reader.py b/src/epub_converter/css_reader.py index 2f6996f..6665725 100644 --- a/src/epub_converter/css_reader.py +++ b/src/epub_converter/css_reader.py @@ -165,7 +165,7 @@ LIVECARTA_STYLE_ATTRS_SHOULD_BE_TAG = { } -def check_style_to_be_tag(style) -> List[tuple]: +def check_style_to_be_tag(style: str) -> List[tuple]: """ Function searches style properties that can be converted to tags. It searches for them and prepare list of properties to be removed from style string @@ -511,6 +511,8 @@ def convert_html_soup_with_css_style(html_soup: BeautifulSoup, css_text: str) -> tags_with_possible_style_attr = html_soup.find_all( could_have_style_in_livecarta_regexp) for i, x in enumerate(tags_with_possible_style_attr): + if i == 2: + pass x.attrs['livecarta_id'] = i livecarta_tmp_ids.append(i) diff --git a/src/epub_converter/epub_converter.py b/src/epub_converter/epub_converter.py index 2a538fd..17f41a2 100644 --- a/src/epub_converter/epub_converter.py +++ b/src/epub_converter/epub_converter.py @@ -121,6 +121,9 @@ class EpubConverter: path_to_css_from_root = normpath( join(html_folder, path_to_css_from_html)).replace('\\', '/') css_obj = self.ebooklib_book.get_item_with_href(path_to_css_from_root) + if "@import" in str(css_obj.content): + path_to_css_from_root = "css/" + re.search('"(.*)"', str(css_obj.content)).group(1) + 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() return css_content