mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
ignore sound: tags when rendering furigana
This commit is contained in:
parent
fdb69b2ca9
commit
ad661add7c
2 changed files with 26 additions and 3 deletions
|
@ -9,14 +9,23 @@ from anki.hooks import addHook
|
|||
r = r' ?([^ ]+?)\[(.+?)\]'
|
||||
ruby = r'<ruby><rb>\1</rb><rt>\2</rt></ruby>'
|
||||
|
||||
def noSound(repl):
|
||||
def func(match):
|
||||
if match.group(2).startswith("sound:"):
|
||||
# return without modification
|
||||
return match.group(0)
|
||||
else:
|
||||
return re.sub(r, repl, match.group(0))
|
||||
return func
|
||||
|
||||
def kanji(txt, *args):
|
||||
return re.sub(r, r'\1', txt)
|
||||
return re.sub(r, noSound(r'\1'), txt)
|
||||
|
||||
def kana(txt, *args):
|
||||
return re.sub(r, r'\2', txt)
|
||||
return re.sub(r, noSound(r'\2'), txt)
|
||||
|
||||
def furigana(txt, *args):
|
||||
return re.sub(r, ruby, txt)
|
||||
return re.sub(r, noSound(ruby), txt)
|
||||
|
||||
def install():
|
||||
addHook('fmod_kanji', kanji)
|
||||
|
|
|
@ -143,3 +143,17 @@ def test_timestamps():
|
|||
addBasicModel(deck)
|
||||
assert len(deck.models.models) == 102
|
||||
|
||||
def test_furigana():
|
||||
deck = getEmptyDeck()
|
||||
mm = deck.models
|
||||
m = mm.current()
|
||||
m['tmpls'][0]['qfmt'] = '{{kana:Front}}'
|
||||
mm.save(m)
|
||||
n = deck.newNote()
|
||||
n['Front'] = 'foo[abc]'
|
||||
deck.addNote(n)
|
||||
c = n.cards()[0]
|
||||
assert c.q().endswith("abc")
|
||||
n['Front'] = 'foo[sound:abc.mp3]'
|
||||
n.flush()
|
||||
assert "sound:" in c.q(reload=True)
|
||||
|
|
Loading…
Reference in a new issue