mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
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
This commit is contained in:
parent
9ba8f9784d
commit
e2d133525e
1 changed files with 5 additions and 2 deletions
|
@ -354,11 +354,14 @@ Please run Tools>Empty Cards""")
|
||||||
hadHR = len(buf) != origSize
|
hadHR = len(buf) != origSize
|
||||||
# munge correct value
|
# munge correct value
|
||||||
parser = html.parser.HTMLParser()
|
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|<br ?/?>|</?div>)+", " ", cor)
|
||||||
|
cor = stripHTML(cor)
|
||||||
# ensure we don't chomp multiple whitespace
|
# ensure we don't chomp multiple whitespace
|
||||||
cor = cor.replace(" ", " ")
|
cor = cor.replace(" ", " ")
|
||||||
cor = parser.unescape(cor)
|
cor = parser.unescape(cor)
|
||||||
cor = cor.replace("\xa0", " ")
|
cor = cor.replace("\xa0", " ")
|
||||||
|
cor = cor.strip()
|
||||||
given = self.typedAnswer
|
given = self.typedAnswer
|
||||||
# compare with typed answer
|
# compare with typed answer
|
||||||
res = self.correct(given, cor, showBad=False)
|
res = self.correct(given, cor, showBad=False)
|
||||||
|
@ -377,7 +380,7 @@ Please run Tools>Empty Cards""")
|
||||||
return re.sub(self.typeAnsPat, repl, buf)
|
return re.sub(self.typeAnsPat, repl, buf)
|
||||||
|
|
||||||
def _contentForCloze(self, txt, idx):
|
def _contentForCloze(self, txt, idx):
|
||||||
matches = re.findall("\{\{c%s::(.+?)\}\}"%idx, txt)
|
matches = re.findall("\{\{c%s::(.+?)\}\}"%idx, txt, re.DOTALL)
|
||||||
if not matches:
|
if not matches:
|
||||||
return None
|
return None
|
||||||
def noHint(txt):
|
def noHint(txt):
|
||||||
|
|
Loading…
Reference in a new issue