Cloze not working anymore

I have a card template that used:

var index = parseInt('{{cloze::Symbol Index}}'.replace(/[\[\]]/g, '').match(/<span.*>([0-9]+)<\/span>/)[1])

With the Cloze field looking something like:


To basically get an integer value corresponding to the current Cloze deletion index shown during review. This index was then used to index various arrays in the other fields.

Problem is that this used to work on ankimobile and anki desktop, but now only work on anki desktop with <2.54 with ankimobile always displaying whatever the max index is (i.e. in this case 4).

ankimobile is latest from App Store
And anki desktop is using 2.54. Latest anki desktop, however also does not work.

Was looking at release notes and didn’t see anything on what changes if any are required to migrate templates for cloze. Can you please advise?

You can use the web inspector in the latest desktop version to see the HTML that clozes produce.

I switched to using the regex:

var index = parseInt('{{cloze::Symbol Index}}'.replace(/[\[\]]/g, '').match(/<span.*?class="?cloze(?!-)"?.*?>([0-9]+)<\/span>/)[1]);

And it appears to work for both anki <2.54 and >2.54. Posting in case someone else finds useful.

Also is there a better way to produce an index from cloze or is what I’m doing probabaly the best way to do it (i.e. using regexes on html)?

If you’re only targeting recent versions, you can extract the ordinal from the data-ordinal attribute in the DOM instead of relying on a regex.

Awesome! Thanks so much Damien! Will try that out.

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