From e2d133525e40685caa5ac35707b80ef23a5a33d4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 24 Sep 2018 17:44:34 +1000 Subject: [PATCH] support newlines in type:cloze, and convert them to spaces https://anki.tenderapp.com/discussions/ankidesktop/29747-empty-cards-when-trying-to-type-in-cloze-deletions --- aqt/reviewer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aqt/reviewer.py b/aqt/reviewer.py index 53aff2d36..088146935 100644 --- a/aqt/reviewer.py +++ b/aqt/reviewer.py @@ -354,11 +354,14 @@ Please run Tools>Empty Cards""") hadHR = len(buf) != origSize # munge correct value parser = html.parser.HTMLParser() - cor = stripHTML(self.mw.col.media.strip(self.typeCorrect)) + cor = self.mw.col.media.strip(self.typeCorrect) + cor = re.sub("(\n|
|)+", " ", cor) + cor = stripHTML(cor) # ensure we don't chomp multiple whitespace cor = cor.replace(" ", " ") cor = parser.unescape(cor) cor = cor.replace("\xa0", " ") + cor = cor.strip() given = self.typedAnswer # compare with typed answer res = self.correct(given, cor, showBad=False) @@ -377,7 +380,7 @@ Please run Tools>Empty Cards""") return re.sub(self.typeAnsPat, repl, buf) def _contentForCloze(self, txt, idx): - matches = re.findall("\{\{c%s::(.+?)\}\}"%idx, txt) + matches = re.findall("\{\{c%s::(.+?)\}\}"%idx, txt, re.DOTALL) if not matches: return None def noHint(txt):