From 769dd4bca65575d89576954c33351fcc3deee761 Mon Sep 17 00:00:00 2001 From: Robozinho <65715921+RobozinhoD@users.noreply.github.com> Date: Sun, 12 May 2024 15:52:25 -0300 Subject: [PATCH] fix tts in browser (#16347) * add tts tag test Co-authored-by: David Allison <62114487+david-allison@users.noreply.github.com> * fix tts tag in browser --------- Co-authored-by: David Allison <62114487+david-allison@users.noreply.github.com> --- .../java/com/ichi2/libanki/TemplateManager.kt | 14 +++++++----- .../java/com/ichi2/anki/CardBrowserTest.kt | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt index 537e664dff7a..2bbfdeb80161 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt @@ -173,21 +173,23 @@ class TemplateManager { ) } - var qtext = applyCustomFilters(partial.qnodes, this, frontSide = null) + val qtext = applyCustomFilters(partial.qnodes, this, frontSide = null) val qout = col.backend.extractAvTags(text = qtext, questionSide = true) + var qoutText = qout.text - var atext = applyCustomFilters(partial.anodes, this, frontSide = qout.text) + val atext = applyCustomFilters(partial.anodes, this, frontSide = qout.text) val aout = col.backend.extractAvTags(text = atext, questionSide = false) + var aoutText = aout.text if (!_browser) { val svg = noteType.optBoolean("latexsvg", false) - qtext = LaTeX.mungeQA(qout.text, col, svg) - atext = LaTeX.mungeQA(aout.text, col, svg) + qoutText = LaTeX.mungeQA(qout.text, col, svg) + aoutText = LaTeX.mungeQA(aout.text, col, svg) } return TemplateRenderOutput( - questionText = qtext, - answerText = atext, + questionText = qoutText, + answerText = aoutText, questionAvTags = avTagsToNative(qout.avTagsList), answerAvTags = avTagsToNative(aout.avTagsList), css = noteType().getString("css") diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt index 7b925f2326a5..a80085d91f63 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt @@ -41,6 +41,7 @@ import com.ichi2.anki.servicelayer.NoteService import com.ichi2.libanki.CardId import com.ichi2.libanki.Consts import com.ichi2.libanki.Note +import com.ichi2.libanki.NotetypeJson import com.ichi2.libanki.utils.TimeManager import com.ichi2.testutils.AnkiActivityUtils.getDialogFragment import com.ichi2.testutils.AnkiAssert.assertDoesNotThrow @@ -1065,6 +1066,27 @@ class CardBrowserTest : RobolectricTest() { Assert.assertEquals("((filtered))", dueString(col, c)) } + @Test + fun `tts tags are stripped`() { + val note = addNonClozeModel( + "test", + arrayOf("Front", "Back"), + "[anki:tts lang=de_DE voices=com.google.android.tts-de-DE-language]{{Front}}[/anki:tts]", + "" + ).let { name -> + col.notetypes.byName(name)!! + }.addNote("Test", "Blank") + + val question = CardCache(note.firstCard().id, col, 1, CARDS) + .getColumnHeaderText(CardBrowserColumn.QUESTION) + + assertThat(question, equalTo("")) + } + + fun NotetypeJson.addNote(field: String, vararg fields: String): Note { + return addNoteUsingModelName(this.name, field, *fields) + } + @Suppress("SameParameterValue") private fun withBrowser(noteCount: Int = 0, block: suspend CardBrowser.() -> Unit) = runTest { getBrowserWithNotes(noteCount).apply {