mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
use pystache for template rendering; autoconvert old style for now
This commit is contained in:
parent
5c3a63d84b
commit
ac8f613aca
1 changed files with 6 additions and 5 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue