Instead of:
Put into the sentence: “the”
Paris is […] capital of France
You do something like:
Put into the sentence: “the”
Paris is capital of France
Instead of:
Put into the sentence: “the”
Paris is […] capital of France
You do something like:
Put into the sentence: “the”
Paris is capital of France
You could add visibility: hidden;
into the .cloze
style. This will hide the word but preserve the spacing:
You can also remove it completely without having a spacing (in the front template):
<script>
// get all clozes
var element = document.getElementsByClassName("cloze");
// hide them
for (var i = 0; i < element.length; i++) {
element[i].innerHTML = "";
}
</script>
{{cloze:Text}}
The “backside” and “before” are the same for both options.
Also: A bit more explaination on what you currently have and what you want is generally a good idea. It makes helping much much easier.
That second option worked beautifully.
Out of curiosity I wondered if I can do this for the inactive clozes as well. I tried:
<script>
// get all clozes
var element = document.getElementsByClassName("cloze");
// hide them
for (var i = 0; i < element.length; i++) {
element[i].innerHTML = "";
}
element = document.getElementsByClassName("cloze-inactive");
for (var i = 0; i < element.length; i++) {
element[i].innerHTML = "";
</script>
But it doesn’t seem to work the same way.
For some context I’m trying to memorize different parts of this definition but i only want to reveal certain information when I test a particular cloze
vestragon(consonant-final, perfect participle vestreta)
- to say somthing (accusative) to someone (dative)
- to tell someone (dative) something (accusative)
- to speak
- (with impersonal subject and subjunctive) to seem,
Hae hunē kirine Zaldrīzdōrot īlō vestretas.- seems to someone (dative)
Zāliapossa buqō ynot vestras.
Also some times simply knowing that there is more information gives away the answer for me
Stach all that made a typo
ty, tyvm @Anon_0000
Glad it works for you!
For that, maybe you want to look at the following snippet too:
Actually there is a slight issue. The script only fires 1 time and it’s the 1st time I look at the frontside of the 1st card
Every time after that nothing happens
It seems to work fine for me with the script you provided above (though I added the missing }
from the for loop).
Can you give me steps to reproduce (as detailed as possible) please?
Here’s what I got. Sorry it’s slightly different now.
I’m trying out some ideas so I changed it around.
Now I want to hide an “cloze-inactive” but only if it doesn’t contain the cloze.
Ex from the docs
{{c1::Canberra was {{c2::founded}}}} in 1913
I don’t want to hide c1 here if c2 is the cloze
here is my code:
// Frontside
<script>
// Find inactive clozes
let elements = document.getElementsByClassName("cloze-inactive");
// Hide them if they don't have a child with the class "cloze"
for (let i = 0; i < elements.length; i++) {
if (!elements[i].querySelector(".cloze")) {
elements[i].innerHTML = "";
}
}
</script>
{{cloze:Text}}
// Backside
{{cloze:Text}}
I see. I won’t be able to test it right now but maybe the following solves your issue already:
Switch let
to var
(let
doesn’t work the way you’d expect).
Yup that was it. Dang man thanks so much
Sorry I’m not a JS person. I just made chat gippty do it for me and copy pasted %
For anyone interested I came up with a convenient way to change inactive clozes based on the current cloze #
Basically works like this
{{c1::First’s stuff}} {{c2::Second’s stuff!c1!c3)) ((c3:: Third’s stuff}}
On card #1:
[…] [.] Third’s stuff
On card #2:
First’s stuff […] Third’s stuff
On card #3
First’s stuff [.] […]
As long as you append the hide tags to the end it seems to work great.
Here’s the script. I don’t javascript very well so please forgive me.
// On the Front
<script>
var cloze = document.getElementsByClassName("cloze");
var inactives = document.getElementsByClassName("cloze-inactive");
function MarkTags(ele)
{
var eleInner = ele.innerHTML;
var eleData = eleInner.split(/!c/);
console.log(eleData.join(','))
var eleVals = [];
while(eleData.length > 1)
{
eleVals.push(eleData[eleData.length - 1]);
eleData.pop();
}
ele.setAttribute("hide-values", eleVals);
ele.innerHTML = eleData;
}
for (let i = 0; i < inactives.length; i++)
{
MarkTags(inactives[i]);
}
function TryReplace()
{
var clozeOrdinal = cloze[0].getAttribute("data-ordinal");
for (let i = 0; i < inactives.length; i++)
{
var hides = inactives[i].getAttribute("hide-values");
if(!hides)
{
continue;
}
var hideVals = hides.split(',');
if (hideVals.indexOf(clozeOrdinal) > -1) {
inactives[i].innerHTML = "[.]";
}
}
}
TryReplace();
</script>
// On the back
<script>
var cloze = document.getElementsByClassName("cloze");
var inactives = document.getElementsByClassName("cloze-inactive");
function MarkTags(ele)
{
var eleInner = ele.innerHTML;
var eleData = eleInner.split(/!c/);
console.log(eleData.join(','))
var eleVals = [];
while(eleData.length > 1)
{
eleVals.push(eleData[eleData.length - 1]);
eleData.pop();
}
ele.setAttribute("hide-values", eleVals);
ele.innerHTML = eleData;
}
for (let i = 0; i < inactives.length; i++)
{
MarkTags(inactives[i]);
}
MarkTags(cloze[0]);
</script>
One might wonder
“Couldn’t you just use nested clozes?”
I could but I found out that you can only go 3 levels of nesting deep. And I actually had some cards that went deeper than that.
Additionally if you cloze more than 1 thing on the same number anki default styling will highlight them both.
While studding my eyes naturally look for the highlighted thing to answer the card and when there is more than 1 it’s annoying, even if I add a hint.
This limit will be removed in the next stable release (the release candidate is already in testing).
You can also remove the styling completely or change it to something less distracting.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.