shigeyukey / Auto-Highlight-Cloze-in-Browser-Fork-by-Shige

🖌️Auto Highlight Cloze in Browser (Fork by Shige)
https://ankiweb.net/shared/info/210078606
Other
0 stars 0 forks source link

malfunctions when the result contains HTML elements (like italic or bold styles) #2

Closed shigeyukey closed 3 months ago

shigeyukey commented 3 months ago

https://forums.ankiweb.net/t/suggestion-highlight-cloze-in-card-when-selected-in-browser/45726

CravingCrates

The same function also malfunctions when the result contains HTML elements (like italic or bold styles). I’m not sure why this happens.

For me some cards like this didn’t work properly. Not sure why.

A(n) {{c1::<i>atrial</i>}} <b>pacemaker</b> will generate a spike followed by a P-wave, a {{c2::<u>normal</u>}} <b>PR-interval</b>, and a {{c3::<u>normal</u>}} <b>QRS complex</b>.

removing the element from the c1 made the highlight work fine though. They were all picked up fine by the regex, so I just assumed it had to be the WebView function that’s causing the issue.

shigeyukey commented 3 months ago

Highlighting doesn't work due to HTML, but it doesn't cause errors, so I think it would be better to upload it anyway and fix it later.

If there is a lot of HTML like this in a medical decks, etc., then fixing it would be a high priority. I have not looked into this yet.

shigeyukey commented 3 months ago

This issue was solved with advice from glutanimate. (AnkiForums)

https://forums.ankiweb.net/t/suggestion-highlight-cloze-in-card-when-selected-in-browser/45726/11?u=shigeyuki

glutanimate : Qt’s find text works on rendered text, so you will have to strip any markup from the query.

I took the advice and made a simple fix.

# browser.py
from bs4 import BeautifulSoup # <- add
# browser.py
   for field in note.fields:
        # cloze_deletions = re.findall(r"(\{\{c(\d+)::(.+?)(::(.*?))?\}\})", field, re.DOTALL)
        field = BeautifulSoup(field, "html.parser").get_text() # <- add
        cloze_deletions = re.findall(r"(\{\{c(\d+)::(.+?)(::(.*?))?\}\})", field, re.DOTALL)