diff --git a/src/docx_converter/html_docx_preprocessor.py b/src/docx_converter/html_docx_preprocessor.py
index c264d17..046166f 100644
--- a/src/docx_converter/html_docx_preprocessor.py
+++ b/src/docx_converter/html_docx_preprocessor.py
@@ -173,11 +173,8 @@ class HTMLDocxPreprocessor:
margin_bottom = re.search(
r'margin-bottom: ([\d.]{1,4})in', style)
else:
- indent = None
- margin_left = None
- margin_right = None
- margin_top = None
- margin_bottom = None
+ indent = margin_left = margin_right = \
+ margin_top = margin_bottom = None
if margin_left and margin_right and margin_top and margin_bottom and \
margin_left.group(1) == '0.6' and margin_right.group(1) == '0.6' and \
@@ -328,23 +325,23 @@ class HTMLDocxPreprocessor:
"a", {'name': re.compile(r'^_Toc\d+')})
headers = [link.parent for link in toc_links]
outline_level = "1" # All the unknown outlines will be predicted as
- for tag in headers:
- if re.search(r"^h\d$", tag.name):
- tag.a.unwrap()
+ for h_tag in headers:
+ if re.search(r"^h\d$", h_tag.name):
+ h_tag.a.unwrap()
# outline_level = tag.name[-1] # TODO: add prediction of the outline level
- elif tag.name == "p":
- exist_in_toc = self._check_parent_link_exist_in_toc(tag)
- if tag in self.body_tag.find_all("p") and exist_in_toc:
+ elif h_tag.name == "p":
+ exist_in_toc = self._check_parent_link_exist_in_toc(h_tag)
+ if h_tag in self.body_tag.find_all("p") and exist_in_toc:
new_tag = BeautifulSoup(
features="lxml").new_tag("h" + outline_level)
- text = tag.text
- tag.replaceWith(new_tag)
+ text = h_tag.text
+ h_tag.replaceWith(new_tag)
new_tag.string = text
else:
# rethink document structure when you have toc_links, other cases?
self.logger_object.log(f'Something went wrong in processing toc_links.'
f' Check the structure of the file. '
- f'Tag name: {tag.name}')
+ f'Tag name: {h_tag.name}')
@staticmethod
def clean_title_from_numbering(title: str):
@@ -568,7 +565,7 @@ class HTMLDocxPreprocessor:
ind = self.content.index(toc_tag) + 1
self.content = self.content[ind:]
- def process_html(self, access=None, html_path='', book_id='local'):
+ def process_html(self, access=None, html_path='', book_id=0):
"""Process html code to satisfy LiveCarta formatting."""
self.logger_object.log('Beginning of processing .html file.')
try:
@@ -600,7 +597,8 @@ class HTMLDocxPreprocessor:
f'{len(self.footnotes)} footnotes have been processed.')
self.logger_object.log('Image processing.')
- self.images = process_images(self.body_tag, access=access, html_path=html_path, book_id=book_id)
+ self.images = process_images(access=access, html_path=html_path,
+ book_id=book_id, body_tag=self.body_tag)
self.logger_object.log(
f'{len(self.images)} images have been processed.')