mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
prepareQA hook
see updated docs on https://apps.ankiweb.net/docs/addons21.html
This commit is contained in:
parent
ca6412b6c9
commit
38688ef8ef
3 changed files with 11 additions and 3 deletions
|
@ -19,7 +19,7 @@ from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
|
|||
saveHeader, restoreHeader, saveState, restoreState, applyStyles, getTag, \
|
||||
showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA, \
|
||||
getOnlyText, MenuList, SubMenu
|
||||
from anki.hooks import runHook, addHook, remHook
|
||||
from anki.hooks import runHook, addHook, remHook, runFilter
|
||||
from aqt.webview import AnkiWebView
|
||||
from anki.consts import *
|
||||
from anki.sound import playFromText, clearAudioQueue
|
||||
|
@ -1356,6 +1356,8 @@ where id in %s""" % ids2str(sf))
|
|||
playFromText(txt)
|
||||
|
||||
txt = mungeQA(self.col, txt)
|
||||
txt = runFilter("prepareQA", txt, c,
|
||||
"preview"+self._previewState.capitalize())
|
||||
|
||||
self._previewWeb.eval(
|
||||
f"{func}({json.dumps(txt)},'{bodyclass}');")
|
||||
|
|
|
@ -15,6 +15,8 @@ from aqt.utils import saveGeom, restoreGeom, mungeQA,\
|
|||
from anki.utils import isMac, isWin, joinFields
|
||||
from aqt.webview import AnkiWebView
|
||||
import json
|
||||
from anki.hooks import runFilter
|
||||
|
||||
|
||||
class CardLayout(QDialog):
|
||||
|
||||
|
@ -296,8 +298,12 @@ Please create a new card type first."""))
|
|||
c = self.card
|
||||
ti = self.maybeTextInput
|
||||
bodyclass="card card%d" % (c.ord+1)
|
||||
|
||||
q = ti(mungeQA(self.mw.col, c.q(reload=True)))
|
||||
q = runFilter("prepareQA", q, c, "clayoutQuestion")
|
||||
|
||||
a = ti(mungeQA(self.mw.col, c.a()), type='a')
|
||||
a = runFilter("prepareQA", a, c, "clayoutAnswer")
|
||||
|
||||
# use _showAnswer to avoid the longer delay
|
||||
self.pform.frontWeb.eval("_showAnswer(%s,'%s');" % (json.dumps(q), bodyclass))
|
||||
|
|
|
@ -167,7 +167,7 @@ The front of this card is empty. Please run Tools>Empty Cards.""")
|
|||
playFromText(q)
|
||||
# render & update bottom
|
||||
q = self._mungeQA(q)
|
||||
q = runFilter("prepareQuestion", q)
|
||||
q = runFilter("prepareQA", q, c, "reviewQuestion")
|
||||
|
||||
bodyclass = "card card%d" % (c.ord+1)
|
||||
|
||||
|
@ -211,7 +211,7 @@ The front of this card is empty. Please run Tools>Empty Cards.""")
|
|||
if self.autoplay(c):
|
||||
playFromText(a)
|
||||
a = self._mungeQA(a)
|
||||
a = runFilter("prepareAnswer", a)
|
||||
a = runFilter("prepareQA", a, c, "reviewAnswer")
|
||||
# render and update bottom
|
||||
self.web.eval("_showAnswer(%s);" % json.dumps(a))
|
||||
self._showEaseButtons()
|
||||
|
|
Loading…
Reference in a new issue