Skip to content

Commit

Permalink
fix tts in browser (#16347)
Browse files Browse the repository at this point in the history
* add tts tag test

Co-authored-by: David Allison <[email protected]>

* fix tts tag in browser

---------

Co-authored-by: David Allison <[email protected]>
  • Loading branch information
RobozinhoD and david-allison authored May 12, 2024
1 parent 636cf9e commit 769dd4b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
14 changes: 8 additions & 6 deletions AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
22 changes: 22 additions & 0 deletions AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 769dd4b

Please sign in to comment.