From 6559020d1f56dd119ccf5b81643e060a7228ff7f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 20 Jun 2012 10:20:42 +0900 Subject: [PATCH] add {{hint:Field}} --- anki/template/hint.py | 20 ++++++++++++++++++++ anki/template/template.py | 1 + 2 files changed, 21 insertions(+) create mode 100644 anki/template/hint.py diff --git a/anki/template/hint.py b/anki/template/hint.py new file mode 100644 index 000000000..e522673c4 --- /dev/null +++ b/anki/template/hint.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright: Damien Elmes +# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +import re +from anki.hooks import addHook + +def hint(txt, extra, context, tag, fullname): + if not txt.strip(): + return "" + # random id + domid = "hint%d" % id(txt) + return """ + +%s +""" % (domid, _("Show %s") % tag, domid, txt) + +def install(): + addHook('fmod_hint', hint) diff --git a/anki/template/template.py b/anki/template/template.py index 7456b5a06..fb6471aeb 100644 --- a/anki/template/template.py +++ b/anki/template/template.py @@ -4,6 +4,7 @@ import collections from anki.utils import stripHTML from anki.hooks import runFilter from anki.template import furigana; furigana.install() +from anki.template import hint; hint.install() from anki.lang import _ clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}"