quick fix

This commit is contained in:
shirshasa
2020-08-28 13:44:43 +03:00
parent f27eefb96b
commit b66ef6296f
3 changed files with 14 additions and 18 deletions

View File

@@ -5,7 +5,7 @@ import re
from shutil import copyfile
from bs4 import BeautifulSoup, NavigableString
from config import BookConfig, BookLogger, BookApiWrapper
from config import LawCartaConfig, BookLogger, BookApiWrapper
class HTMLPreprocessor:
@@ -49,8 +49,8 @@ class HTMLPreprocessor:
@classmethod
def convert_pt_to_px(cls, value):
value = int(value)
if value == BookConfig.WORD_DEFAULT_FONT_SIZE:
return BookConfig.LAWCARTA_DEFAULT_FONT_SIZE
if value == LawCartaConfig.WORD_DEFAULT_FONT_SIZE:
return LawCartaConfig.LAWCARTA_DEFAULT_FONT_SIZE
else:
return value
@@ -70,7 +70,7 @@ class HTMLPreprocessor:
size = size.group(1)
new_size = cls.convert_pt_to_px(size)
if new_size == BookConfig.LAWCARTA_DEFAULT_FONT_SIZE:
if new_size == LawCartaConfig.LAWCARTA_DEFAULT_FONT_SIZE:
return ""
return re.sub(size + "pt", str(new_size) + "px", style)
@@ -178,7 +178,7 @@ class HTMLPreprocessor:
p.attrs = {}
style = ''
if align is not None and align != BookConfig.DEFAULT_ALIGN_STYLE:
if align is not None and align != LawCartaConfig.DEFAULT_ALIGN_STYLE:
style += f'text-align: {align};'
if indent is not None:
@@ -280,10 +280,6 @@ class HTMLPreprocessor:
tag.string = tag.text.replace('\u200c', '')
tag['href'] = tag.attrs.get('href').replace('%E2%80%8C', '')
# %E2%80%8C
for tag in a_tags_with_href:
print(tag)
@staticmethod
def _clean_footnote_content(content):
content = content.strip()
@@ -433,7 +429,7 @@ class HTMLPreprocessor:
"""
Function to convert all lower level headings to p tags
"""
pattern = f'^h[{BookConfig.SUPPORTED_LEVELS + 1}-9]$'
pattern = f'^h[{LawCartaConfig.SUPPORTED_LEVELS + 1}-9]$'
header_tags = self.body_tag.find_all(re.compile(pattern))
for tag in header_tags:
tag.name = 'p'
@@ -521,8 +517,8 @@ class HTMLPreprocessor:
if title == "":
tag.unwrap()
else:
assert tag.name in BookConfig.SUPPORTED_HEADERS, \
f'Preprocessing went wrong, there is still h{BookConfig.SUPPORTED_LEVELS + 1}-h9 headings.'
assert tag.name in LawCartaConfig.SUPPORTED_HEADERS, \
f'Preprocessing went wrong, there is still h{LawCartaConfig.SUPPORTED_LEVELS + 1}-h9 headings.'
# if tag.name in ["h4", "h5", "h6"]:
# tag.name = "h3" # All the lower level headings will be transformed to h3 headings