diff --git a/pylib/anki/sound.py b/pylib/anki/sound.py index 0d5f6d736..ca05a6c21 100644 --- a/pylib/anki/sound.py +++ b/pylib/anki/sound.py @@ -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) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index d8e9ff8cb..36041650d 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -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) diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index 0a7d02e11..2e4fe5ae2 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -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: """ - return AV_FLAG_RE.sub(repl, text) + return AV_REF_RE.sub(repl, text) def play_clicked_audio(pycmd: str, card: Card) -> None: