replace clozes individually so hints aren't shared

This commit is contained in:
Damien Elmes 2012-07-05 03:17:16 +09:00
parent 5212f62198
commit 50bfb9dd4b

View file

@ -196,19 +196,16 @@ class Template(object):
def clozeText(self, txt, ord, type): def clozeText(self, txt, ord, type):
reg = clozeReg reg = clozeReg
m = re.search(reg%ord, txt) def repl(m):
if not m: # replace chosen cloze with type
return "" if type == "q":
# replace chosen cloze with type if m.group(3):
if type == "q": return "<span class=cloze>[%s...]</span>" % m.group(3)
if m.group(3): else:
txt = re.sub( return "<span class=cloze>[...]</span>"
reg%ord, "<span class=cloze>[%s...]</span>" % m.group(3),
txt)
else: else:
txt = re.sub(reg%ord, "<span class=cloze>[...]</span>", txt) return "<span class=cloze>%s</span>" % m.group(1)
elif type == "a": txt = re.sub(reg%ord, repl, txt)
txt = re.sub(reg%ord, "<span class=cloze>\\1</span>", txt)
# and display other clozes normally # and display other clozes normally
return re.sub(reg%".*?", "\\1", txt) return re.sub(reg%".*?", "\\1", txt)