mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
wrap clozes in a classed span instead of bold
This commit is contained in:
parent
03d00228aa
commit
0fdb966766
2 changed files with 16 additions and 15 deletions
|
@ -177,15 +177,15 @@ class Template(object):
|
|||
# replace chosen cloze with type
|
||||
if type == "q":
|
||||
if m.group(2):
|
||||
txt = re.sub(reg%ord, "<b>...(\\3)</b>", txt)
|
||||
txt = re.sub(reg%ord, "<span class=cloze>...(\\3)</span>", txt)
|
||||
else:
|
||||
txt = re.sub(reg%ord, "<b>...</b>", txt)
|
||||
txt = re.sub(reg%ord, "<span class=cloze>...</span>", txt)
|
||||
elif type == "actx":
|
||||
txt = re.sub(reg%ord, "<b>\\1</b>", txt)
|
||||
txt = re.sub(reg%ord, "<span class=cloze>\\1</span>", txt)
|
||||
else:
|
||||
# just the answers
|
||||
ans = re.findall(reg%ord, txt)
|
||||
ans = ["<b>"+a[0]+"</b>" for a in ans]
|
||||
ans = ["<span class=cloze>"+a[0]+"</span>" for a in ans]
|
||||
return ", ".join(ans)
|
||||
# and display other clozes normally
|
||||
return re.sub(reg%".*?", "\\1", txt)
|
||||
|
|
|
@ -119,35 +119,36 @@ def test_cloze():
|
|||
# try with one cloze
|
||||
f['Text'] = "hello {{c1::world}}"
|
||||
assert d.addFact(f) == 1
|
||||
assert "hello <b>...</b>" in f.cards()[0].q()
|
||||
assert "hello <span class=cloze>...</span>" in f.cards()[0].q()
|
||||
# the default is no context
|
||||
assert "<b>world</b>" in f.cards()[0].a()
|
||||
assert "hello <b>world</b>" not 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()
|
||||
# check context works too
|
||||
f.model().conf['clozectx'] = True
|
||||
assert "hello <b>world</b>" in f.cards()[0].a()
|
||||
assert "hello <span class=cloze>world</span>" in f.cards()[0].a()
|
||||
# and with a comment
|
||||
f = d.newFact()
|
||||
f['Text'] = "hello {{c1::world::typical}}"
|
||||
assert d.addFact(f) == 1
|
||||
assert "<b>...(typical)</b>" in f.cards()[0].q()
|
||||
assert "<b>world</b>" in f.cards()[0].a()
|
||||
assert "<span class=cloze>...(typical)</span>" in f.cards()[0].q()
|
||||
assert "<span class=cloze>world</span>" in f.cards()[0].a()
|
||||
# and with 2 clozes
|
||||
f = d.newFact()
|
||||
f['Text'] = "hello {{c1::world}} {{c2::bar}}"
|
||||
assert d.addFact(f) == 2
|
||||
(c1, c2) = f.cards()
|
||||
assert "<b>...</b> bar" in c1.q()
|
||||
assert "<b>world</b> bar" in c1.a()
|
||||
assert "world <b>...</b>" in c2.q()
|
||||
assert "world <b>bar</b>" in c2.a()
|
||||
assert "<span class=cloze>...</span> bar" in c1.q()
|
||||
assert "<span class=cloze>world</span> bar" in c1.a()
|
||||
assert "world <span class=cloze>...</span>" in c2.q()
|
||||
assert "world <span class=cloze>bar</span>" in c2.a()
|
||||
# if there are multiple answers for a single cloze, they are given in a
|
||||
# list
|
||||
f.model().conf['clozectx'] = False
|
||||
f = d.newFact()
|
||||
f['Text'] = "a {{c1::b}} {{c1::c}}"
|
||||
assert d.addFact(f) == 1
|
||||
assert "<b>b</b>, <b>c</b>" in f.cards()[0].a()
|
||||
assert "<span class=cloze>b</span>, <span class=cloze>c</span>" in (
|
||||
f.cards()[0].a())
|
||||
# clozes should be supported in sections too
|
||||
m = d.currentModel()
|
||||
m.templates[0]['qfmt'] = "{{#cloze:1:Text}}{{Notes}}{{/cloze:1:Text}}"
|
||||
|
|
Loading…
Reference in a new issue