From 2e54d315e12ebd8066e85399b9bb196379c2e304 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Thu, 12 Mar 2020 21:17:32 -0300 Subject: [PATCH] Fixed BeautifulSoup breaking string paths https://anki.tenderapp.com/discussions/ankidesktop/39543-anki-is-replacing-the-character-by-when-i-exit-the-html-edit-mode-ctrlshiftx --- pylib/anki/importing/supermemo_xml.py | 5 +++++ qt/aqt/editor.py | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pylib/anki/importing/supermemo_xml.py b/pylib/anki/importing/supermemo_xml.py index a5ddd582e..fb9461ae7 100644 --- a/pylib/anki/importing/supermemo_xml.py +++ b/pylib/anki/importing/supermemo_xml.py @@ -150,6 +150,11 @@ class SupermemoXmlImporter(NoteImporter): # my sm2004 also ecaped & char in escaped sequences. html = re.sub("&", "&", html) + + # https://anki.tenderapp.com/discussions/ankidesktop/39543-anki-is-replacing-the-character-by-when-i-exit-the-html-edit-mode-ctrlshiftx + if html.find(">") < 0: + return html + # unescaped solitary chars < or > that were ok for minidom confuse btfl soup # html = re.sub(u'>',u'>',html) # html = re.sub(u'<',u'<',html) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 74e52fa09..e53a6ffd5 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -495,11 +495,13 @@ class Editor: form.textEdit.moveCursor(QTextCursor.End) d.exec_() html = form.textEdit.toPlainText() - # filter html through beautifulsoup so we can strip out things like a - # leading - with warnings.catch_warnings() as w: - warnings.simplefilter("ignore", UserWarning) - html = str(BeautifulSoup(html, "html.parser")) + # 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 + with warnings.catch_warnings() as w: + warnings.simplefilter("ignore", UserWarning) + html = str(BeautifulSoup(html, "html.parser")) self.note.fields[field] = html self.note.flush() self.loadNote(focusTo=field) @@ -806,6 +808,10 @@ to a cloze type first, via Edit>Change Note Type.""" removeTags = ["script", "iframe", "object", "style"] def _pastePreFilter(self, html, internal): + # https://anki.tenderapp.com/discussions/ankidesktop/39543-anki-is-replacing-the-character-by-when-i-exit-the-html-edit-mode-ctrlshiftx + if html.find(">") < 0: + return html + with warnings.catch_warnings() as w: warnings.simplefilter("ignore", UserWarning) doc = BeautifulSoup(html, "html.parser")