From 15e4b64162bfbc1af8874d5d74edadeb59263c01 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 18 Nov 2011 05:15:15 +0900 Subject: [PATCH] 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. --- anki/models.py | 29 +---------------------------- anki/upgrade.py | 11 +++++++---- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/anki/models.py b/anki/models.py index b8675cadd..0e1d8027c 100644 --- a/anki/models.py +++ b/anki/models.py @@ -53,7 +53,6 @@ defaultTemplate = { 'ord': None, 'qfmt': "", 'afmt': "", - 'hideQ': False, 'align': 0, 'bg': "#fff", '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()]) 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 - 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']), ("center", "left", "right")[t['align']], t['bg']) for t in m['tmpls']) 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 ################################################## diff --git a/anki/upgrade.py b/anki/upgrade.py index ee3d14af9..b5483a052 100644 --- a/anki/upgrade.py +++ b/anki/upgrade.py @@ -388,11 +388,14 @@ order by ordinal""", mid)): conf['actv'], conf['qfmt'], conf['afmt'], - conf['hideQ'], + hideq, conf['align'], conf['bg'], conf['typeAns']) = row conf['ord'] = c + # q fields now in a + if not hideq: + conf['afmt'] = conf['qfmt'] + "\n\n
\n\n" + conf['afmt'] # convert the field name to an ordinal ordN = None for (ord, fm) in enumerate(flds): @@ -439,13 +442,13 @@ order by ordinal""", mid)): # then for each template for t in m['tmpls']: def repl(match): - field = match.group(1) + field = match.group(2) if field in styles: - return styles[field] + return match.group(1) + styles[field] # special or non-existant field; leave alone return match.group(0) for k in 'qfmt', 'afmt': - t[k] = re.sub("(?:^|[^{]){{([^{}]+)?}}", repl, t[k]) + t[k] = re.sub("(^|[^{]){{([^{}]+)?}}", repl, t[k]) # save model d.models.save(m)