add list preprocessing

This commit is contained in:
shirshasa
2020-05-26 14:52:36 +03:00
parent c8fbe3c520
commit c335561b26

View File

@@ -722,6 +722,18 @@ class Book:
new_tag.string = title
tag.replace_with(new_tag)
def _process_lists(self):
"""
Function to process tags <ul>.
Unwrap <p> tags.
"""
list_tags = self.body_tag.find_all("ul")
for tag in list_tags:
for il_tag in tag.find_all("li"):
il_tag.attrs.update(il_tag.p.attrs)
il_tag.p.unwrap()
def write_html_from_list(self, file_name='url_test.html'):
folder_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
file_path = pathlib.Path(os.path.join(folder_path, file_name))
@@ -779,6 +791,8 @@ class Book:
# delete text before table of content if exists
self.delete_content_before_toc()
self._process_lists()
except Exception as exc:
self.log('Error has occurred while processing html.', logging.ERROR)
self.log_error_to_main_log()