Flexible Cloze [Support thread]

I’ve done it, now it doesn’t appear that error. Thanks a lot

Ok, now I have looked some more at it.

My remarks around the design are based on where the different addons do things - notably for functionality such as to copy from one field to another. I think we mean different things with “client side only”. What I mean is that nothing is done in the editor/actual note - it all happens in JavaScript in the card template i.e. when the reviewer shows the card.

To roughly illustrate:

  1. Editor: different fields are filled in, changed, copied etc. ⇐ Cloze (Hide All) and Enhanced Cloze are active here (check cloze_hide_all/src at master · trgkanki/cloze_hide_all · GitHub). Any copying between fields would need to happen here.
  2. Reviewer loads note type (cloze vs “regular”) and parses the fields generating an HTML document from the contents and the card template. ⇐ After this step there are no separate fields only a single HTML document, all FCZ does here is provide the template into which the note content is inserted.
  3. Resulting HTML is shown and card template JS is executed ⇐ Cloze (Hide All) and Enhanced Cloze are also active here, FCZ logic is only active here.

I have never used TTS nor type-in-the-answer which was why I asked for samples/explanations. Looking a little at it {{type:cloze:Text}} and {{tts en_US:cloze-only:Text}} seems to work as expected when inserting them at an appropriate place in the FCZ template but that has nothing to do with FCZ it’s all built in Anki functionality.

As far as I can tell the most viable way to not have to type the expose character/string nor have it TTS:ed would be to move it outside the cloze tag so instead of {{c1::!Answer}} you would do !{{c1::Answer}} (or whatever you set the expose character/string to). This solution would require no copying etc. and should be convenient when editing (i.e. instead of ctrl+shift+c then ! you do ! then ctrl+shift+c) but it would likely be better to set another expose character/string to avoid FCZ from misinterpreting a sentence ! (e.g. set it to !! or ¤ or whatever is easy in your keyboard layout and not commonly used).

This is easily amended in the latest version by changing
const PATTERN = new RegExp(`[{]{2}c(\d+)[:]{2}?(${fcz.expose})?(.?)(?:[:]{2}(.?))?[}]{2}`, ‘gms’);
fcz.root.innerHTML = document.getElementById(“fcz-field”).innerHTML.replace(PATTERN, (match, cloze, expose, content, hint) => {
// Sanitize input
if (expose == undefined) { expose = “”; }

to
const PATTERN = new RegExp(`(${fcz.expose})?[{]{2}c(\d+)[:]{2}?(${fcz.expose})?(.?)(?:[:]{2}(.?))?[}]{2}`, ‘gms’);
fcz.root.innerHTML = document.getElementById(“fcz-field”).innerHTML.replace(PATTERN, (match, exp_pre, cloze, exp_post, content, hint) => {
// Sanitize input
let expose = (exp_pre == undefined) && (exp_post == undefined) ? “” : fcz.expose;

The inclusion of the expose character/string both before and after the {{c1:: is to avoid breaking existing notes as well as not messing up the preference of a majority to satisfy a minority.

You are free to try the above to see if it meets your requirements as copying between fields is outside of the scope of this addon. If it works as expected and breaks nothing else I will include it in a future update.

I am certainly no TTS expert but what TTS are you using? Are you inserting something like {{tts en_US:cloze-only:Text}} tags in the template? If so then it seems like the following is happening:

  1. Reviewer parses the note and template.
  2. Reviewer calls OS TTS with the appropriate string for the initial read (for instance, it strips {{c1:: etc. depending on what field replacement you use).
  3. When generating the card HTML the reviewer inserts HTML with pycmd that launch reviewer code referenced in 2. for replay functionality.

Based on that you could make your own addon that works in the reviewer (that might be tricky for platform compatibility) that has another implementation of what is sent to the OS TTS.

I am not sure I understand your use case, sample notes would be much easier to understand, however it seems you have a rather complex note generation procedure. FCZ aims to have the same simple note generation process as for “regular” Anki clozes (and indeed there is no difference, the notes are regular Anki cloze notes, FCZ only changes how they are displayed).

For the type-answer it should work well with FCZ with earlier mentioned modification if you use the !{{c1:: format rather than {{c1::! to expose clozes. However if all you want to do is to always expose all inactive clozes then it would easy to add a configuration option like --show-inactive: true that would always expose all inactive clozes (similar to a regular Anki cloze display).

If you want to keep the field copying and it is something that could be done with regexes etc. you could create an addon that does the parsing/copying automatically each time the note is saved (which happens every few seconds in the editor except when adding new notes, then it is done when adding the note).

When I press “J”, I have the same problem when changing the style mode to “span” + this parameter to “false” → –iteration-hides-previous: “true”; / false leaves cloze open when cycling forward/backward*.

On the other hand, how could I adjust the scroll preferences in order to center the active clozes?

Thanks in advance, your work is awesome!

So, I am new in Anki, and I want to use the Flexible Cloze template, but I want to convert it to type-in-the-answer. Can anyone help me with that? :sweat:

1 Like

I don’t use type-in-the-answer myself but inserting {{type:cloze:Text}} somewhere in the front template, for instance at the top of the footer (so the type in field will always be visible) should work:
<!-- Footer at the bottom of the screen, delete to remove or modify/add to change – >
<div id=“fcz-footer”>
{{type:cloze:Text}}
<!-- Symbol legend, delete divs to remove or modify number and content of child divs – >
<div id=“fcz-legend-footer”>

If you intend to use exposed clozes (i.e. clozes that are displayed when they are not the active cloze) you may want to change the location of the expose-flag byt setting --expose-pos: to "pre" (it is set to "begin" per default) in the Styling section.

When I press “J”, I have the same problem when changing the style mode to “span” + this parameter to “false” → –iteration-hides-previous: “true”; / false leaves cloze open when cycling forward/backward*.

I’m sorry, I don’t understand the problem? Does it not move to next cloze or does it not hide the previous?

On the other hand, how could I adjust the scroll preferences in order to center the active clozes?

Assuming you have the latest update, setting --scroll: "center"; in Styling should center the active clozes (unless they are too large to fit, in that case it will scroll to one line above the first active cloze).

I mean that more than one c1/c2/c3, … are revealed when I press “J” most of the time while having that parameter to “false” (depending on what cloze number I’m reviewing). Because I have multiple c1’s, c2’s, etc.

Ok, just so I understand correctly:

  • You have set --iteration-hides-previous: “false” (this should leave shown clozes “open” when cycling forward/backward)
  • When you press “j” (mapped to go to next cloze, which should open) it also opens other “related” clozes (i.e. if the next cloze is a c1 then other c1’s are also opened, even though they are not “next in line”)?

A few questions:

  • What have you set --iterate-inactive to?
  • I can’t reproduce the behavior, do you have any sample notes?

As a side note I am currently bug testing some new logic that:

  • Adds --scroll: “none”/“min”/“center” ⇐ the scroll behavior on card show and flip
  • Adds --scroll-iterate: “none”/“min”/“center” ⇐ scroll behavior when using edge press/key press (next/previous)
  • Adds --scroll-click: “none”/“min”/“center” ⇐ scroll behavior when clicking a cloze (i.e. after the card is shown/flipped)
    -Replaces --iterate-inactive with --iterate: “active”/“inactive”/“all” ⇐ which clozes are iterated with next/previous.

Hi TRIAEIOU,

I see from an earlier post that you do not have an iOS device. Do you have any plans to extend support to iOS version of Anki? At the moment, cards appear as intended on my desktop and Ankidroid, but appear as below on iOS. I’ve confirmed that these cards contain text and clozes.


Thank you for your hard work!!

A few guesses on what could be the problem:

  • There either is something different in the HTML structure of the cards on the iOS version (for comparison, desktop Anki wraps the content in a <div> tag with id “qa” whereas on AnkiDroid the id is “content”)
  • Some HTML or javascript functionality is implemented differently (like flex-box etc.) in Qt on iOS (unlikely).
  • FCZ relies on the fact that you can access the entire cloze note in unchanged format through {{Text}} (and not just the current cloze card through {{cloze:Text}}) - as far as I understand the iOS Anki is a different code base from Anki desktop and AnkiDroid so it is possible that the {{Text}} tag is not supported for cloze type notes. If this is the case the foundation of the FCZ logic is invalid on iOS and would be hard to address.

Can you get the raw HTML from a card and post here so I can have a look at what could be the problem? This seems to be one way of getting the HTML: Quick Tip: Using Web Inspector to Debug Mobile Safari

Hm, I tried that method but AnkiMobile isn’t an inspectable application as far as I can tell.

Using the suggestion from this post, I obtained this output. Unfortunately, I can’t figure out how to copy paste it or reveal what follows the “…”. I can keep trying if this is what you’re looking for.


For reference, this is the appearance of the particular card I’ve sent in the above examples. I noticed the text is centered, whereas it is left justified on desktop and Ankidroid:

This is the HTML for the card via the editor, but I don’t think this is what you’re looking for:

Sorry if this isn’t as helpful as you would’ve liked. I’m happy to investigate further if you have any suggestions for things I can try!

try this
<script>alert(document.body.innerHTML)</script>
But do it on a note with a single cloze an minimal text, something like
qst: {{c1::ans}}
as I need to see the HTML that surrounds the content.

Yes I saw that some of text that is left aligned in the original template is centered on your screen shots, there may be some class name collision in the styling, but I should be able to see that with the output from above.


Hope this helps!

Ok, that at least shows that the css is being inserted and that there seems to be a root div called ‘qa’, could you try:
<script>document.alert(document.getElementById('fcz-content').outerHTML)</script>
and <script>document.alert(document.getElementById('qa').nextElementSibling.outerHTML)</script>

Strangely, I don’t get any pop up boxes with the provided code. Just out of curiosity, I tried the following and received the following outputs:

image

image

Ok, thanks. Where in the template did you put this?

Could you try to put the following at the top of the template:
<script>setTimeout(() => alert(document.getElementById('fcz-content').outerHTML), 5000);</script>
This will wait some 5s before executing to allow the rest of the page to finish.

The FCZ javascript parses the note and populates the fcz-content <div> appropriately. If the alert is run after the FCZ JS is run and still is empty it probably means the FCZ JS is crashing somewhere.

At some point I will have to come up with some JS that will paste all the content as well as the console to a floating contenteditable div or similar, however that will unfortunately likely not be in the immediate.

Thanks

I’ve been putting the lines of code at the bottom of the back template:

Putting your new code at top of back template:


yields this:

Putting your new code at the top of the front template:


yields something similar:

Thank you for your help! Looking forward to any progress you can make. Best wishes.

Ok, so it seems something is crashing in the javascript on the front side. I’ll need to figure out a way to get the console output as “debugging over a forum” is kind of hard!

Cheers

To your first two considerations: Yes to the first one, and yes to the second one, when I press “J”, maybe not in the first review but yes in another close to the first one (For example: if I review the flashcard in the edit menu, maybe at the first time this problem doesn’t appear, but if I keep pressing “J”, in the next clozes of the same flashcard, the problem will appear).

To the 2 questions: --iterate-inactive is “False”, and yes, I share some sample notes here Flexible Cloze Samples.

On the other hand, I would like to know if it would be possible to avoid the following issue that I’ve found:
— When I review a flashcard, and there aren’t more active clozes, If I keep pressing “J” or tapping the right corner the behavior feels like I’m begining again to uncover clozes and the scroll function starts it’s pattern again.
— Also, the fact that with every cloze that pertains to another line it scrolls one time and another, makes a bit confusing the fact of review a flashcard with several c1’s, c2’s and so on (the auto-scroll logic of the add-on Enhanced Cloze 2.1 works better in that aspect, in my opinion).

It would be great to be able to do something with that.
Thanks a lot for your effort!

Cheers