add [] to cloze

This commit is contained in:
Damien Elmes 2011-04-29 11:43:06 +09:00
parent a4f644e780
commit ddcf83bc7f
2 changed files with 6 additions and 6 deletions

View file

@ -177,9 +177,9 @@ class Template(object):
# replace chosen cloze with type # replace chosen cloze with type
if type == "q": if type == "q":
if m.group(2): if m.group(2):
txt = re.sub(reg%ord, "<span class=cloze>...(\\3)</span>", txt) txt = re.sub(reg%ord, "<span class=cloze>[...(\\3)]</span>", txt)
else: else:
txt = re.sub(reg%ord, "<span class=cloze>...</span>", txt) txt = re.sub(reg%ord, "<span class=cloze>[...]</span>", txt)
elif type == "actx": elif type == "actx":
txt = re.sub(reg%ord, "<span class=cloze>\\1</span>", txt) txt = re.sub(reg%ord, "<span class=cloze>\\1</span>", txt)
else: else:

View file

@ -119,7 +119,7 @@ def test_cloze():
# try with one cloze # try with one cloze
f['Text'] = "hello {{c1::world}}" f['Text'] = "hello {{c1::world}}"
assert d.addFact(f) == 1 assert d.addFact(f) == 1
assert "hello <span class=cloze>...</span>" in f.cards()[0].q() assert "hello <span class=cloze>[...]</span>" in f.cards()[0].q()
# the default is no context # the default is no context
assert "<span class=cloze>world</span>" in f.cards()[0].a() assert "<span class=cloze>world</span>" in f.cards()[0].a()
assert "hello <span class=cloze>world</span>" not in f.cards()[0].a() assert "hello <span class=cloze>world</span>" not in f.cards()[0].a()
@ -130,16 +130,16 @@ def test_cloze():
f = d.newFact() f = d.newFact()
f['Text'] = "hello {{c1::world::typical}}" f['Text'] = "hello {{c1::world::typical}}"
assert d.addFact(f) == 1 assert d.addFact(f) == 1
assert "<span class=cloze>...(typical)</span>" in f.cards()[0].q() assert "<span class=cloze>[...(typical)]</span>" in f.cards()[0].q()
assert "<span class=cloze>world</span>" in f.cards()[0].a() assert "<span class=cloze>world</span>" in f.cards()[0].a()
# and with 2 clozes # and with 2 clozes
f = d.newFact() f = d.newFact()
f['Text'] = "hello {{c1::world}} {{c2::bar}}" f['Text'] = "hello {{c1::world}} {{c2::bar}}"
assert d.addFact(f) == 2 assert d.addFact(f) == 2
(c1, c2) = f.cards() (c1, c2) = f.cards()
assert "<span class=cloze>...</span> bar" in c1.q() assert "<span class=cloze>[...]</span> bar" in c1.q()
assert "<span class=cloze>world</span> bar" in c1.a() assert "<span class=cloze>world</span> bar" in c1.a()
assert "world <span class=cloze>...</span>" in c2.q() assert "world <span class=cloze>[...]</span>" in c2.q()
assert "world <span class=cloze>bar</span>" in c2.a() assert "world <span class=cloze>bar</span>" in c2.a()
# if there are multiple answers for a single cloze, they are given in a # if there are multiple answers for a single cloze, they are given in a
# list # list