mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 13:26:56 -05:00
remove clozectx, add styling to stdmodels
This commit is contained in:
parent
918bfa2e62
commit
0a279f6a26
8 changed files with 37 additions and 39 deletions
|
|
@ -443,11 +443,7 @@ select id from notes where id in %s and id not in (select nid from cards)""" %
|
|||
if type == "q":
|
||||
format = format.replace("cloze:", "cq:")
|
||||
else:
|
||||
if model['clozectx']:
|
||||
name = "cactx:"
|
||||
else:
|
||||
name = "ca:"
|
||||
format = format.replace("cloze:", name)
|
||||
format = format.replace("cloze:", "ca:")
|
||||
fields = runFilter("mungeFields", fields, model, data, self)
|
||||
html = anki.template.render(format, fields)
|
||||
d[type] = runFilter(
|
||||
|
|
|
|||
|
|
@ -224,17 +224,21 @@ class DeckManager(object):
|
|||
|
||||
def didsForConf(self, conf):
|
||||
dids = []
|
||||
for deck in self.decks:
|
||||
for deck in self.decks.values():
|
||||
if deck['conf'] == conf['id']:
|
||||
dids.append(deck['id'])
|
||||
return dids
|
||||
|
||||
def restoreToDefault(self, conf):
|
||||
oldOrder = conf['new']['order']
|
||||
new = copy.deepcopy(defaultConf)
|
||||
new['id'] = conf['id']
|
||||
new['name'] = conf['name']
|
||||
self.dconf[str(conf['id'])] = new
|
||||
self.save(new)
|
||||
# if it was previously randomized, resort
|
||||
if not oldOrder:
|
||||
self.col.sched.resortConf(new)
|
||||
|
||||
# Deck utils
|
||||
#############################################################
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ from anki.consts import *
|
|||
defaultModel = {
|
||||
'sortf': 0,
|
||||
'did': 1,
|
||||
'clozectx': False,
|
||||
'latexPre': """\
|
||||
\\documentclass[12pt]{article}
|
||||
\\special{papersize=3in,5in}
|
||||
|
|
|
|||
|
|
@ -6,19 +6,32 @@ from anki.lang import _
|
|||
|
||||
models = []
|
||||
|
||||
_header = """\
|
||||
<style>
|
||||
.card {
|
||||
text-align:center;
|
||||
background-color:white;
|
||||
}
|
||||
</style>\n\n"""
|
||||
|
||||
def _field(name):
|
||||
return """\
|
||||
<span style="font-family:arial;font-size:12px;color:black;\
|
||||
white-space:pre-wrap;">{{%s}}</span>\n""" % name
|
||||
|
||||
# Basic
|
||||
##########################################################################
|
||||
|
||||
def addBasicModel(col):
|
||||
mm = col.models
|
||||
m = mm.new(_("Basic"))
|
||||
m = mm.new(_("Basic")) #2 field note"))
|
||||
fm = mm.newField(_("Front"))
|
||||
mm.addField(m, fm)
|
||||
fm = mm.newField(_("Back"))
|
||||
mm.addField(m, fm)
|
||||
t = mm.newTemplate(_("Forward"))
|
||||
t['qfmt'] = "{{" + _("Front") + "}}"
|
||||
t['afmt'] = "{{" + _("Back") + "}}"
|
||||
t['qfmt'] = _header + _field(_("Front"))
|
||||
t['afmt'] = t['qfmt'] + "\n\n<hr id=answerStart>\n\n" + _field(_("Back"))
|
||||
mm.addTemplate(m, t)
|
||||
mm.add(m)
|
||||
return m
|
||||
|
|
@ -31,17 +44,17 @@ models.append((_("Basic"), addBasicModel))
|
|||
def addClozeModel(col):
|
||||
mm = col.models
|
||||
m = mm.new(_("Cloze"))
|
||||
fm = mm.newField(_("Text"))
|
||||
fm = mm.newField(("Text"))
|
||||
mm.addField(m, fm)
|
||||
fm = mm.newField(_("Notes"))
|
||||
mm.addField(m, fm)
|
||||
for i in range(8):
|
||||
n = i+1
|
||||
t = mm.newTemplate(_("Cloze") + " %d" % n)
|
||||
t['qfmt'] = ("{{#cloze:%d:Text}}<br>{{cloze:%d:%s}}<br>"+
|
||||
"{{/cloze:%d:Text}}") % (n, n, _("Text"), n)
|
||||
t['afmt'] = ("{{cloze:%d:" + _("Text") + "}}") % n
|
||||
t['afmt'] += "<br>{{" + _("Notes") + "}}"
|
||||
t['qfmt'] = _header + ("{{#cloze:%d:Text}}\n"+
|
||||
_field("cloze:%d:Text" % n)+
|
||||
"{{/cloze:%d:Text}}") % (n, n)
|
||||
t['afmt'] = t['qfmt'] + "<br>\n"+_field("Notes")
|
||||
mm.addTemplate(m, t)
|
||||
mm.add(m)
|
||||
return m
|
||||
|
|
|
|||
|
|
@ -162,8 +162,7 @@ class Template(object):
|
|||
# to process
|
||||
return "[[%s]]" % tag_name
|
||||
elif (tag_name.startswith("cq:") or
|
||||
tag_name.startswith("ca:") or
|
||||
tag_name.startswith("cactx:")):
|
||||
tag_name.startswith("ca:")):
|
||||
m = re.match("c(.+):(\d+):(.+)", tag_name)
|
||||
(type, ord, tag) = (m.group(1), m.group(2), m.group(3))
|
||||
txt = get_or_attr(context, tag)
|
||||
|
|
@ -184,15 +183,8 @@ class Template(object):
|
|||
txt = re.sub(reg%ord, "<span class=cloze>[...(\\3)]</span>", txt)
|
||||
else:
|
||||
txt = re.sub(reg%ord, "<span class=cloze>[...]</span>", txt)
|
||||
elif type == "actx":
|
||||
elif type == "a":
|
||||
txt = re.sub(reg%ord, "<span class=cloze>\\1</span>", txt)
|
||||
else:
|
||||
# just the answers
|
||||
ans = re.findall(reg%ord, txt)
|
||||
ans = ["<span class=cloze>"+a[0]+"</span>" for a in ans]
|
||||
ans = ", ".join(ans)
|
||||
# but we want to preserve the outer field styling
|
||||
return ans
|
||||
# and display other clozes normally
|
||||
return re.sub(reg%".*?", "\\1", txt)
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ def test_noteAddDelete():
|
|||
assert deck.cardCount() == 4
|
||||
# check q/a generation
|
||||
c0 = f.cards()[0]
|
||||
assert re.sub("</?.+?>", "", c0.q()) == u"three"
|
||||
assert "three" in c0.q()
|
||||
# it should not be a duplicate
|
||||
assert not f.dupeOrEmpty()
|
||||
# now let's make a duplicate
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ def test_fields():
|
|||
m = d.models.current()
|
||||
# make sure renaming a field updates the templates
|
||||
d.models.renameField(m, m['flds'][0], "NewFront")
|
||||
assert m['tmpls'][0]['qfmt'] == "{{NewFront}}"
|
||||
assert "{{NewFront}}" in m['tmpls'][0]['qfmt']
|
||||
h = d.models.scmhash(m)
|
||||
# add a field
|
||||
f = d.models.newField(m)
|
||||
|
|
@ -127,11 +127,6 @@ def test_cloze():
|
|||
f['Text'] = "hello {{c1::world}}"
|
||||
assert d.addNote(f) == 1
|
||||
assert "hello <span class=cloze>[...]</span>" in f.cards()[0].q()
|
||||
# the default is no context
|
||||
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()['clozectx'] = True
|
||||
assert "hello <span class=cloze>world</span>" in f.cards()[0].a()
|
||||
# and with a comment
|
||||
f = d.newNote()
|
||||
|
|
@ -150,11 +145,10 @@ def test_cloze():
|
|||
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()['clozectx'] = False
|
||||
f = d.newNote()
|
||||
f['Text'] = "a {{c1::b}} {{c1::c}}"
|
||||
assert d.addNote(f) == 1
|
||||
assert "<span class=cloze>b</span>, <span class=cloze>c</span>" in (
|
||||
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.models.current()
|
||||
|
|
@ -196,14 +190,14 @@ def test_modelChange():
|
|||
# switch cards
|
||||
c0 = f.cards()[0]
|
||||
c1 = f.cards()[1]
|
||||
assert stripHTML(c0.q()) == "b"
|
||||
assert stripHTML(c1.q()) == "f"
|
||||
assert ">b<" in c0.q()
|
||||
assert "f" in c1.q()
|
||||
assert c0.ord == 0
|
||||
assert c1.ord == 1
|
||||
deck.models.change(basic, [f.id], basic, None, map)
|
||||
f.load(); c0.load(); c1.load()
|
||||
assert stripHTML(c0.q()) == "f"
|
||||
assert stripHTML(c1.q()) == "b"
|
||||
assert "f" in c0.q()
|
||||
assert ">b<" in c1.q()
|
||||
assert c0.ord == 1
|
||||
assert c1.ord == 0
|
||||
# .cards() returns cards in order
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ def test_new():
|
|||
qs = ("2", "3", "2", "3")
|
||||
for n in range(4):
|
||||
c = d.sched.getCard()
|
||||
assert(stripHTML(c.q()) == qs[n])
|
||||
assert qs[n] in c.q()
|
||||
d.sched.answerCard(c, 2)
|
||||
|
||||
def test_newLimits():
|
||||
|
|
|
|||
Loading…
Reference in a new issue