3

In Anki, I have a note type where one card is effectively a cloze deletion, however I am using other cards at the same time, with the cloze deletion field in it. I've tried to use javascript to replace everything within two '\'s and it appears to work in the preview when editing, but when the card appears during normal use, only the first line appears as plain text. I'm using the desktop linux program for editing, but would also like to be able to use it in AnkiDroid.

So the question is: what's the problem and how can I fix it?

Front Template:

<script>
    function showDef() {
        document.getElementById("def").innerHTML = '{{Bedeutung 1}}'.replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');
    };

    var initial = false;
    var beispiel = (function () {/*{{Beispiel 1}}*/}).toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');
    var splitBeispiel = beispiel.split('\\');
    document.write(splitBeispiel[0] + "<n id='cloze'>[...]</n>" + splitBeispiel[2]);
</script>
<p onclick="showDef()" id="def">Click to show definition</p>

Styling:

.card {
 font-family: arial;
 font-size: 20px;
 text-align: center;
 color: black;
 background-color: white;
}

#cloze {
 font-family: arial;
 font-size: 25px;
 text-align: center;
 color: blue;
 background-color: white;
}

#def {
 font-family: arial;
 font-size: 15px;
 text-align: center;
 color: green;
 background-color: white;
}

#beispiel {
 font-family: arial;
 font-size: 15px;
 text-align: center;
 color: orange;
 background-color: white;
}

Back Template:

<script>
var initial = false;
var beispiel = (function () {/*{{Beispiel 1}}*/}).toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');
var splitBeispiel = beispiel.split('\\');
document.write(splitBeispiel[0] + "<n id='cloze'>" + splitBeispiel[1] +"</n>" + splitBeispiel[2]);
</script>

<hr id=answer>

{{Singular Nominativ}}

The 'Beispiel 1' field in the following example is "ein kirchlicher, ein \gesetzlicher\ Feiertag"

Screenshot of editor preview: Screenshot of editor preview

Screenshot of test: Screenshot of test

Jon Saw
  • 7,599
  • 6
  • 48
  • 57
user3231511
  • 31
  • 1
  • 5

1 Answers1

-1

I guess, you should look for the solution here. Avoid using document.write in your templates and use document.getElementById("HTMLidToReplace").innerHTML = '<b>' + your_var + '</b>';, for example. Hope it helps.

JulyMorning
  • 531
  • 1
  • 4
  • 8