JavaScript to replace text string with image?

Hi!

Is it possible to add a script to the card template that replaces every instance of a specific text string with a matching image previously saved to the Anki collection.media folder?

Example: every instance of the text “one” in these cards are replaced with the image _one.png from the media folder when reviewing.

Could something like this be made to work?

<div id=front />
<script>
var str = document.getElementById("Front").innerHTML;
var res = str.replace(/one/g, "<img src='_one.png'>");
document.getElementById("Front").innerHTML = res;
</script>
<div id=front>{{Front}}</div>

<script>
var str = document.getElementById("front").innerHTML;
var res = str.replace(/one/g, "<img src='_one.png'>");
document.getElementById("front").innerHTML = res;
</script>
1 Like

Thank you :pray:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.