Skip to content

Commit 61a753b

Browse files
fix: don't remove image in html in anki
1 parent e056365 commit 61a753b

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

WDoc/utils/misc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,17 @@ def _file_hasher(abs_path: str, stats: List[Union[int, float]]) -> str:
266266

267267

268268
@optional_typecheck
269-
def html_to_text(html: str) -> str:
269+
def html_to_text(html: str, remove_image: bool = False) -> str:
270270
"""used to strip any html present in the text files"""
271271
html = html.replace("</li><li>", "<br>") # otherwise they might get joined
272272
html = html.replace("</ul><ul>", "<br>") # otherwise they might get joined
273273
soup = BeautifulSoup(html, 'html.parser')
274274
text = soup.get_text()
275-
if "<img" in text:
276-
text = re.sub("<img src=.*?>", "[IMAGE]", text, flags=re.M | re.DOTALL)
275+
if remove_image:
277276
if "<img" in text:
278-
red("Failed to remove <img from anki card")
277+
text = re.sub("<img src=.*?>", "[IMAGE]", text, flags=re.M | re.DOTALL)
278+
if "<img" in text:
279+
red("Failed to remove <img from anki card")
279280
return text
280281

281282

0 commit comments

Comments
 (0)