forked from LiveCarta/BookConverter
Add htm support in processing anchors
This commit is contained in:
@@ -468,10 +468,11 @@ def wrap_block_tag_with_table(main_tag, old_tag, width='95', border='1px', bg_co
|
||||
return table
|
||||
|
||||
|
||||
def _clean_wiley_block(block):
|
||||
def clean_wiley_block(block):
|
||||
hrs = block.find_all("p", attrs={"class": re.compile(".+ hr")})
|
||||
for hr in hrs:
|
||||
hr.extract()
|
||||
print(hr)
|
||||
h = block.find(re.compile("h[1-9]"))
|
||||
if h:
|
||||
h.name = "p"
|
||||
@@ -481,7 +482,7 @@ def _clean_wiley_block(block):
|
||||
def preprocess_block_tags(chapter_tag):
|
||||
for block in chapter_tag.find_all("blockquote"):
|
||||
if block.attrs.get('class') in ['feature1', 'feature2', 'feature3', 'feature4']:
|
||||
_clean_wiley_block(block)
|
||||
clean_wiley_block(block)
|
||||
|
||||
color = '#DDDDDD' if block.attrs.get('class') == 'feature1' else None
|
||||
color = '#EEEEEE' if block.attrs.get('class') == 'feature2' else color
|
||||
@@ -490,13 +491,13 @@ def preprocess_block_tags(chapter_tag):
|
||||
block.unwrap()
|
||||
|
||||
for future_block in chapter_tag.find_all("p", attrs={"class": re.compile("feature[1234]")}):
|
||||
_clean_wiley_block(future_block)
|
||||
clean_wiley_block(future_block)
|
||||
color = '#DDDDDD' if future_block.attrs.get('class') == 'feature1' else None
|
||||
color = '#EEEEEE' if future_block.attrs.get('class') == 'feature2' else color
|
||||
wrap_block_tag_with_table(chapter_tag, future_block, bg_color=color)
|
||||
|
||||
|
||||
def _prepare_formatted(text):
|
||||
def prepare_formatted(text):
|
||||
# replace <,> to save them as is in html code
|
||||
text = text.replace("<", "\x3C")
|
||||
text = text.replace(">", "\x3E")
|
||||
@@ -515,7 +516,7 @@ def preprocess_pre_tags(chapter_tag):
|
||||
|
||||
for child in pre.children:
|
||||
if isinstance(child, NavigableString):
|
||||
cleaned_text = _prepare_formatted(str(child))
|
||||
cleaned_text = prepare_formatted(str(child))
|
||||
sub_strings = re.split('\r\n|\n|\r', cleaned_text)
|
||||
for string in sub_strings:
|
||||
new_tag.append(NavigableString(string))
|
||||
@@ -523,10 +524,10 @@ def preprocess_pre_tags(chapter_tag):
|
||||
else:
|
||||
for sub_child in child.children:
|
||||
if isinstance(sub_child, NavigableString):
|
||||
cleaned_text2 = _prepare_formatted(str(sub_child))
|
||||
cleaned_text2 = prepare_formatted(str(sub_child))
|
||||
sub_child.replace_with(NavigableString(cleaned_text2))
|
||||
else:
|
||||
sub_child.string = _prepare_formatted(sub_child.text)
|
||||
sub_child.string = prepare_formatted(sub_child.text)
|
||||
cleaned_tag = child.extract()
|
||||
new_tag.append(cleaned_tag)
|
||||
if to_add_br:
|
||||
|
||||
Reference in New Issue
Block a user