use pystache for template rendering; autoconvert old style for now

This commit is contained in:
Damien Elmes 2010-11-28 02:06:54 +09:00
parent 5c3a63d84b
commit ac8f613aca

View file

@ -12,7 +12,7 @@ Model - define the way in which facts are added and shown
""" """
import time import time, re, pystache
from sqlalchemy.ext.orderinglist import ordering_list from sqlalchemy.ext.orderinglist import ordering_list
from anki.db import * from anki.db import *
from anki.utils import genID, canonifyTags from anki.utils import genID, canonifyTags
@ -149,10 +149,11 @@ def formatQA(cid, mid, fact, tags, cm):
ret = [] ret = []
for (type, format) in (("question", cm.qformat), for (type, format) in (("question", cm.qformat),
("answer", cm.aformat)): ("answer", cm.aformat)):
try: # convert old style
html = format % fields format = re.sub("%\((.+?)\)s", "{{\\1}}", format)
except (KeyError, TypeError, ValueError): # allow custom rendering functions & info
html = _("[invalid question/answer format]") fields = runFilter("prepareFields", fields, cid, mid, fact, tags, cm)
html = pystache.render(format, fields)
d[type] = runFilter("formatQA", html, type, cid, mid, fact, tags, cm) d[type] = runFilter("formatQA", html, type, cid, mid, fact, tags, cm)
return d return d