mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 15:17:12 -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
|
import collections
|
||||||
from anki.utils import stripHTML
|
from anki.utils import stripHTML
|
||||||
from anki.hooks import runFilter
|
from anki.hooks import runFilter
|
||||||
|
from anki.template import furigana; furigana.install()
|
||||||
|
|
||||||
clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}"
|
clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}"
|
||||||
|
|
||||||
|
|
||||||
modifiers = {}
|
modifiers = {}
|
||||||
def modifier(symbol):
|
def modifier(symbol):
|
||||||
"""Decorator for associating a function with a Mustache tag modifier.
|
"""Decorator for associating a function with a Mustache tag modifier.
|
||||||
|
|
@ -185,8 +185,8 @@ class Template(object):
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
# hook-based modifier
|
# hook-based field modifier
|
||||||
txt = runFilter('fieldModifier_' + mod, txt, extra, context, tag, tag_name);
|
txt = runFilter('fmod_' + mod, txt, extra, context, tag, tag_name);
|
||||||
if txt is None:
|
if txt is None:
|
||||||
return '{unknown field %s}' % tag_name
|
return '{unknown field %s}' % tag_name
|
||||||
return txt
|
return txt
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue