From 3382af2877aa50f0570587741512b1528d74eba9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 25 May 2012 09:12:19 +0900 Subject: [PATCH] allow empty clozes instead of considering a cloze note with no clozes marked as invalid, treat it as the first card and show a warning during review --- anki/consts.py | 2 ++ anki/models.py | 3 +++ anki/template/template.py | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/anki/consts.py b/anki/consts.py index 76ff39838..e18e63b8f 100644 --- a/anki/consts.py +++ b/anki/consts.py @@ -46,6 +46,8 @@ SYNC_ZIP_SIZE = int(2.5*1024*1024) SYNC_URL = os.environ.get("SYNC_URL") or "https://beta.ankiweb.net/sync/" SYNC_VER = 5 +HELP_SITE="http://ankisrs.net/docs/dev/manual.html" + # Labels ########################################################################## diff --git a/anki/models.py b/anki/models.py index a2320ad2a..eefa15699 100644 --- a/anki/models.py +++ b/anki/models.py @@ -544,6 +544,9 @@ select id from notes where mid = ?)""" % " ".join(map), "{{c(\d+)::[^}]*?}}", sflds[ord])]) if -1 in ords: ords.remove(-1) + if not ords: + # empty clozes use first ord + return [0] return list(ords) # Sync handling diff --git a/anki/template/template.py b/anki/template/template.py index f3bec9e66..95910c85a 100644 --- a/anki/template/template.py +++ b/anki/template/template.py @@ -4,6 +4,7 @@ import collections from anki.utils import stripHTML from anki.hooks import runFilter from anki.template import furigana; furigana.install() +from anki.consts import HELP_SITE clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}" @@ -196,8 +197,11 @@ class Template(object): reg = clozeReg m = re.search(reg%ord, txt) if not m: - # cloze doesn't exist; return empty - return "" + # cloze doesn't exist; return whole text + return (txt + "

" + _( + "No cloze deletions found; showing whole field. (%s)") % ( + "%s" % (HELP_SITE, _("help"))) + + "") # replace chosen cloze with type if type == "q": if m.group(3):