mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 07:07:13 -05:00
integrate furigana field modifiers
This commit is contained in:
parent
bbac32b477
commit
5d3e31ca5d
2 changed files with 27 additions and 3 deletions
24
anki/template/furigana.py
Normal file
24
anki/template/furigana.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
# Based off Kieran Clancy's initial implementation.
|
||||
|
||||
import re
|
||||
from anki.hooks import addHook
|
||||
|
||||
r = r' ?([^ ]+?)\[(.+?)\]'
|
||||
ruby = r'<ruby><rb>\1</rb><rt>\2</rt></ruby>'
|
||||
|
||||
def kanji(txt, *args):
|
||||
return re.sub(r, r'\1', txt)
|
||||
|
||||
def kana(txt, *args):
|
||||
return re.sub(r, r'\2', txt)
|
||||
|
||||
def furigana(txt, *args):
|
||||
return re.sub(r, ruby, txt)
|
||||
|
||||
def install():
|
||||
addHook('fmod_kanji', kanji)
|
||||
addHook('fmod_kana', kana)
|
||||
addHook('fmod_furigana', furigana)
|
||||
|
|
@ -3,10 +3,10 @@ import cgi
|
|||
import collections
|
||||
from anki.utils import stripHTML
|
||||
from anki.hooks import runFilter
|
||||
from anki.template import furigana; furigana.install()
|
||||
|
||||
clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}"
|
||||
|
||||
|
||||
modifiers = {}
|
||||
def modifier(symbol):
|
||||
"""Decorator for associating a function with a Mustache tag modifier.
|
||||
|
|
@ -185,8 +185,8 @@ class Template(object):
|
|||
else:
|
||||
return ""
|
||||
else:
|
||||
# hook-based modifier
|
||||
txt = runFilter('fieldModifier_' + mod, txt, extra, context, tag, tag_name);
|
||||
# hook-based field modifier
|
||||
txt = runFilter('fmod_' + mod, txt, extra, context, tag, tag_name);
|
||||
if txt is None:
|
||||
return '{unknown field %s}' % tag_name
|
||||
return txt
|
||||
|
|
|
|||
Loading…
Reference in a new issue