move strip_av_refs() into anki.sound

This commit is contained in:
Damien Elmes 2020-01-24 15:48:40 +10:00
parent f900f24f60
commit f6ef553ba5
3 changed files with 11 additions and 9 deletions

View file

@ -9,6 +9,7 @@ These can be accessed via eg card.question_av_tags()
from __future__ import annotations
import re
from dataclasses import dataclass
from typing import List, Union
@ -39,3 +40,9 @@ class SoundOrVideoTag:
# note this does not include image tags, which are handled with HTML.
AVTag = Union[SoundOrVideoTag, TTSTag]
AV_REF_RE = re.compile(r"\[anki:(play:(.):(\d+))\]")
def strip_av_refs(text: str) -> str:
return AV_REF_RE.sub("", text)

View file

@ -15,6 +15,7 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple
from send2trash import send2trash
import anki
import aqt
import aqt.mediasrv
import aqt.mpv
@ -405,7 +406,7 @@ close the profile or restart Anki."""
if self.pm.profile.get("showPlayButtons", True):
return aqt.sound.av_refs_to_play_icons(text)
else:
return aqt.sound.strip_av_refs(text)
return anki.sound.strip_av_refs(text)
def prepare_card_text_for_display(self, text: str) -> str:
text = self.col.media.escapeImages(text)

View file

@ -19,7 +19,7 @@ import pyaudio
import aqt
from anki.cards import Card
from anki.lang import _
from anki.sound import AVTag, SoundOrVideoTag
from anki.sound import AV_REF_RE, AVTag, SoundOrVideoTag
from anki.utils import isLin, isMac, isWin
from aqt import gui_hooks
from aqt.mpv import MPV, MPVBase
@ -580,12 +580,6 @@ for (k, v) in _exports:
# Tag handling
##########################################################################
AV_FLAG_RE = re.compile(r"\[anki:(play:.:\d+)\]")
def strip_av_refs(text: str) -> str:
return AV_FLAG_RE.sub("", text)
def av_refs_to_play_icons(text: str) -> str:
"""Add play icons into the HTML.
@ -599,7 +593,7 @@ def av_refs_to_play_icons(text: str) -> str:
<img class=playImage src='/_anki/imgs/play.png'>
</a>"""
return AV_FLAG_RE.sub(repl, text)
return AV_REF_RE.sub(repl, text)
def play_clicked_audio(pycmd: str, card: Card) -> None: