diff --git a/src/epub_converter/epub_solver.py b/src/epub_converter/epub_solver.py index 5a6a9b5..3106797 100644 --- a/src/epub_converter/epub_solver.py +++ b/src/epub_converter/epub_solver.py @@ -1,5 +1,6 @@ import json import codecs +import logging from src.book_solver import BookSolver from src.util.helpers import BookLogger @@ -30,11 +31,19 @@ class EpubBook(BookSolver): json for LiveCarta platform """ - html_preprocessor = HtmlPresetsProcessor( - logger=self.logger_object, preset_path="presets/epub_presets.json") style_preprocessor = StyleReader() - html_processor = HtmlEpubProcessor(logger=self.logger_object, - html_preprocessor=html_preprocessor) + # Parses and cleans html, gets list of tags, gets footnotes + try: + html_preprocessor = HtmlPresetsProcessor( + logger=self.logger_object, preset_path="presets/epub_presets.json") + html_processor = HtmlEpubProcessor(logger=self.logger_object, + html_preprocessor=html_preprocessor) + except Exception as exc: + self.logger_object.log( + "Error has occurred while processing .html", logging.ERROR) + self.logger_object.log_error_to_main_log() + self.status_wrapper.set_error() + raise exc json_converter = EpubConverter( self.book_path, access=self.access, logger=self.logger_object, style_processor=style_preprocessor, html_processor=html_processor) diff --git a/src/style_reader.py b/src/style_reader.py index daa2c3e..8831f9a 100644 --- a/src/style_reader.py +++ b/src/style_reader.py @@ -109,24 +109,27 @@ class StyleReader: return constraints_on_value, value_not_in_possible_values_list def update_inline_styles_to_livecarta_convention(self, split_style: list) -> list: - for i, style in reversed(list(enumerate(split_style))): - style_name, style_value = style.split(":") - if style_name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS: - # property not in LIVECARTA_STYLE_ATTRS, remove - split_style.remove(style) - continue + try: + for i, style in reversed(list(enumerate(split_style))): + style_name, style_value = style.split(":") + if style_name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS: + # property not in LIVECARTA_STYLE_ATTRS, remove + split_style.remove(style) + continue - cleaned_value = self.clean_value(style_value, style_name) - if all(self.style_conditions(cleaned_value, style_name)): - # there are constraints + value not in LIVECARTA_STYLE_ATTRS, remove - split_style.remove(style) - continue - else: - if style_name in self.LIVECARTA_STYLE_ATTRS_MAPPING: - # function that converts our data - func = self.LIVECARTA_STYLE_ATTRS_MAPPING[style_name] - style_value = func(cleaned_value) - split_style[i] = style_name + ":" + style_value + cleaned_value = self.clean_value(style_value, style_name) + if all(self.style_conditions(cleaned_value, style_name)): + # there are constraints + value not in LIVECARTA_STYLE_ATTRS, remove + split_style.remove(style) + continue + else: + if style_name in self.LIVECARTA_STYLE_ATTRS_MAPPING: + # function that converts our data + func = self.LIVECARTA_STYLE_ATTRS_MAPPING[style_name] + style_value = func(cleaned_value) + split_style[i] = style_name + ":" + style_value + except ValueError as ve: + print(f"Style value isn't correct.") return split_style def build_inline_style_content(self, style: str) -> str: