(un)escape image references in HTML editor to fix ampersand handling

https://anki.tenderapp.com/discussions/ankidesktop/41479-image-names-with-are-breaking
This commit is contained in:
Damien Elmes 2020-06-09 11:21:48 +10:00
parent 5f2987d0f8
commit 43da12a445

View file

@ -532,13 +532,14 @@ class Editor:
form.textEdit.moveCursor(QTextCursor.End)
d.exec_()
html = form.textEdit.toPlainText()
# https://anki.tenderapp.com/discussions/ankidesktop/39543-anki-is-replacing-the-character-by-when-i-exit-the-html-edit-mode-ctrlshiftx
if html.find(">") > -1:
# filter html through beautifulsoup so we can strip out things like a
# leading </div>
html_escaped = self.mw.col.media.escapeImages(html)
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
html = str(BeautifulSoup(html, "html.parser"))
html_escaped = str(BeautifulSoup(html_escaped, "html.parser"))
html = self.mw.col.media.escapeImages(html_escaped, unescape=True)
self.note.fields[field] = html
if not self.addMode:
self.note.flush()