mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
new approach to hideQ
Instead of a separate option to hide question, embed the question into the answer format by default. Users who don't want to see the question can remove the question fields, and users who want a separator between the question and answer (or not) can control it in HTML now. Also, remove obsolete field CSS, and don't accidentally chomp a character on upgrade.
This commit is contained in:
parent
c76c08069e
commit
15e4b64162
2 changed files with 8 additions and 32 deletions
|
@ -53,7 +53,6 @@ defaultTemplate = {
|
||||||
'ord': None,
|
'ord': None,
|
||||||
'qfmt': "",
|
'qfmt': "",
|
||||||
'afmt': "",
|
'afmt': "",
|
||||||
'hideQ': False,
|
|
||||||
'align': 0,
|
'align': 0,
|
||||||
'bg': "#fff",
|
'bg': "#fff",
|
||||||
'typeAns': None,
|
'typeAns': None,
|
||||||
|
@ -204,39 +203,13 @@ select id from cards where fid in (select id from facts where mid = ?)""",
|
||||||
return "\n".join([m['css'] for m in self.all()])
|
return "\n".join([m['css'] for m in self.all()])
|
||||||
|
|
||||||
def _css(self, m):
|
def _css(self, m):
|
||||||
# fields
|
|
||||||
css = "".join(self._fieldCSS(
|
|
||||||
".fm%s-%s" % (hexifyID(m['id']), hexifyID(f['ord'])),
|
|
||||||
(f['font'], f['qsize'], f['qcol'], f['rtl'], f['pre']))
|
|
||||||
for f in m['flds'])
|
|
||||||
# templates
|
# templates
|
||||||
css += "".join(".cm%s-%s {text-align:%s;background:%s}\n" % (
|
css = "".join(".cm%s-%s {text-align:%s;background:%s}\n" % (
|
||||||
hexifyID(m['id']), hexifyID(t['ord']),
|
hexifyID(m['id']), hexifyID(t['ord']),
|
||||||
("center", "left", "right")[t['align']], t['bg'])
|
("center", "left", "right")[t['align']], t['bg'])
|
||||||
for t in m['tmpls'])
|
for t in m['tmpls'])
|
||||||
return css
|
return css
|
||||||
|
|
||||||
def _rewriteFont(self, font):
|
|
||||||
"Convert a platform font to a multiplatform list."
|
|
||||||
font = font.lower()
|
|
||||||
for family in self.deck.conf['fontFamilies']:
|
|
||||||
for font2 in family:
|
|
||||||
if font == font2.lower():
|
|
||||||
return ",".join(family)
|
|
||||||
return font
|
|
||||||
|
|
||||||
def _fieldCSS(self, prefix, row):
|
|
||||||
(fam, siz, col, rtl, pre) = row
|
|
||||||
t = 'font-family:"%s";' % self._rewriteFont(fam)
|
|
||||||
t += 'font-size:%dpx;' % siz
|
|
||||||
t += 'color:%s;' % col
|
|
||||||
if rtl:
|
|
||||||
t += "direction:rtl;unicode-bidi:embed;"
|
|
||||||
if pre:
|
|
||||||
t += "white-space:pre-wrap;"
|
|
||||||
t = "%s {%s}\n" % (prefix, t)
|
|
||||||
return t
|
|
||||||
|
|
||||||
# Fields
|
# Fields
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
|
|
|
@ -388,11 +388,14 @@ order by ordinal""", mid)):
|
||||||
conf['actv'],
|
conf['actv'],
|
||||||
conf['qfmt'],
|
conf['qfmt'],
|
||||||
conf['afmt'],
|
conf['afmt'],
|
||||||
conf['hideQ'],
|
hideq,
|
||||||
conf['align'],
|
conf['align'],
|
||||||
conf['bg'],
|
conf['bg'],
|
||||||
conf['typeAns']) = row
|
conf['typeAns']) = row
|
||||||
conf['ord'] = c
|
conf['ord'] = c
|
||||||
|
# q fields now in a
|
||||||
|
if not hideq:
|
||||||
|
conf['afmt'] = conf['qfmt'] + "\n\n<hr>\n\n" + conf['afmt']
|
||||||
# convert the field name to an ordinal
|
# convert the field name to an ordinal
|
||||||
ordN = None
|
ordN = None
|
||||||
for (ord, fm) in enumerate(flds):
|
for (ord, fm) in enumerate(flds):
|
||||||
|
@ -439,13 +442,13 @@ order by ordinal""", mid)):
|
||||||
# then for each template
|
# then for each template
|
||||||
for t in m['tmpls']:
|
for t in m['tmpls']:
|
||||||
def repl(match):
|
def repl(match):
|
||||||
field = match.group(1)
|
field = match.group(2)
|
||||||
if field in styles:
|
if field in styles:
|
||||||
return styles[field]
|
return match.group(1) + styles[field]
|
||||||
# special or non-existant field; leave alone
|
# special or non-existant field; leave alone
|
||||||
return match.group(0)
|
return match.group(0)
|
||||||
for k in 'qfmt', 'afmt':
|
for k in 'qfmt', 'afmt':
|
||||||
t[k] = re.sub("(?:^|[^{]){{([^{}]+)?}}", repl, t[k])
|
t[k] = re.sub("(^|[^{]){{([^{}]+)?}}", repl, t[k])
|
||||||
# save model
|
# save model
|
||||||
d.models.save(m)
|
d.models.save(m)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue