From 43da12a4456d5536235f7d8b827cc091c73fe311 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 9 Jun 2020 11:21:48 +1000 Subject: [PATCH] (un)escape image references in HTML editor to fix ampersand handling https://anki.tenderapp.com/discussions/ankidesktop/41479-image-names-with-are-breaking --- qt/aqt/editor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 3cb46f7c0..8269af901 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -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 + 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()