Flexible cloze 2 [Support thread]

Flexible cloze 2 support thread.

Hello, it seems that the hint function of fc2 does not work properly. I added the following test cards.

This test card does not display hints when reviewing, and only cycles through the following two states.

스크린샷 2023-02-10 오후 10.34.28

Please help, thank you.

Thanks, I think the last update should fix it.

With regards to the issues raised in the reviews:

Night mode

The text colors can be styled in the Styling page of the Cards dialog from Manage note type, something like this for example:

/* Display form and style of active clozes on front */
.front span.cloze
{ background-color: #FA8072; color: #000000;}

/* Display form and style of active clozes on back */
.back span.cloze
{ background-color: #D0F0C0; color: #000000;}

/* Display form and style of inactive clozes on front and back */
.front span.cloze-inactive, .back span.cloze-inactive
{ background-color: #F0F0F0; color: #000000; }

Hints

Hints should be working with the latest version, if there is something that is not working, please let me know a little more specifically:

image

Hi @TRIAEIOU , do you know if it would be possible to work with c1.1, c1.2 and so on. This would be great in order o convert big clozes flashcards into smaller ones without having to change all the numbers of the note in order to preserve an ascending logic.

Thanks for your great work

Flexible cloze 2 functionality depends on the core Anki card generation and cloze handling so any “special cloze handling” is not really possible, for something like that the original Flexible Cloze would be a better starting point as that logic parses the note “from scratch”. I am not sure I understand what you want to do though? If you just want to “sort the clozes in ascending order” running something like this using Editor Scripts & Symbols should do the trick:

const html = document.activeElement.shadowRoot.activeElement.innerHTML
const ahtml = [...html.matchAll(new RegExp(/\{\{c(\d+)::.*?\}\}/g))]
let ord = 1
const ord_map = new Map()
for (const el of ahtml) {
  if (!ord_map.has(parseInt(el[1]))) {
    ord_map.set(parseInt(el[1]), ord++)
  }
}
document.activeElement.shadowRoot.activeElement.innerHTML = html.replace(/\{\{c(\d+)::/g, function(match, p1) {
   return "{{c" + ord_map.get(parseInt(p1)) + "::"
})

What I pretend is to convert, for example, a note with 5 clozes with “big content”. In order to review it with more fluidity, I would like to divide each one into 2 or 3 flashcards. For this, I would put c.1.1 at some point, 1.2 at another, and so on, in order to divide all the c1 in 2 or 3 flashcards.

As I can’t, what I do is putting c6, c7, and so on, to avoid using numbers that I use. However, this doesn’t allow me to have all the clozes in a “numerical order”. That’s why I asked this question.

Ok, so I understand correctly, you want to change this:

Foo: {{c1::
Bar
Baz
Qux
}}
Quux: {{c2::
Corge
Grault
Garply
}}

to something like

Foo: 
{{c1.1::Bar}}
{{c1.2::Baz}}
{{c1.3::Qux}}
Quux:
{{c2.1::Corge}}
{{c2.2::Grault}}
{{c2.3::Garply}}

And then review in order c1.1, c1.2, c1.3, c2.1, c2.2, c2.3 as separate cards? The issue with this is that it has to happen in the Anki backend, otherwise no cards are generated. Both Flexible cloze (and all other cloze variants) are depending on the backend generating a card for every cloze. Those cards are then parsed to display the content in various ways but if the back end only generates say two cards then the user (and template) will only see two cards.

However, using the javascript snippet above will sort cloze ordering for you before reviewing - run the script on note once in the editor. It would for example sort these clozes:

Foo: 
{{c7::Bar}}
{{c1::Baz}}
{{c32::Qux}}
Quux:
{{c11::Corge}}
{{c4::Grault}}
{{c99::Garply}}

to

Foo: 
{{c1::Bar}}
{{c2::Baz}}
{{c3::Qux}}
Quux:
{{c4::Corge}}
{{c5::Grault}}
{{c6::Garply}}

(note that if you have already learned some of the clozes running the javascript will mess up your scheduling as the learning state in the data base is dependent on the cloze ordinal, not the content of the cloze)

If on the other hand you want one card for c1, c2 and c3 then wouldn’t just using {{c1:: for bar/baz/qux give you the wanted result?

Well, my situation is the one you described firstly and, unfortunately, they are all learned cards. For that reason, I wanted that “c1.1” thing to have the option to review all in order.

I guess that the best and easiest option is to forget the review order (not as important in my particular case) and to focus on the division.

Thanks for your attention

Hello @TRIAEIOU ,

I have downloaded the latest version updated at 2023-02-21, however, the hint bug for some reason still persists, what went wrong?


^^specifically for c2 cloze.

I tried redownloading the add-on from here:

It also shows there are not updates available here:

Many Thanks.

Hi,

I don’t know what’s going on, I had a working emulation of macOS earlier but it seems broken now so I need to set up a new one to have a closer look. I only know it works on Windows and Android. In the mean time, it would be great if you could try inserting the following in the card template editor (if you have customized the FC2 template you can simply create a copy and paste the code below into the copy):
Front: https://raw.githubusercontent.com/TRIAEIOU/flexible-cloze-2/log-search-rollup/bin/fc2-front.html
Back: https://raw.githubusercontent.com/TRIAEIOU/flexible-cloze-2/log-search-rollup/bin/fc2-back.html
Style: https://raw.githubusercontent.com/TRIAEIOU/flexible-cloze-2/log-search-rollup/bin/fc2.css

That’s from the development arm and has a debug-field built in (it also has yet unreleased features including searching in the card from the reviewer and customizing options on a per note basis by using tags). Any errors should be printed into the red field at the bottom of the reviewer along with some other debug info:

Hi,

First of all, thank you @TRIAEIOU for your continued work on this add on. I remember you were very helpful when I was attempting to integrate it into my deck last year. I am reattempting now and have encountered another issue.

What is the best way to generate clozes spanning multiple lines within a list? I am having trouble making these clozes such that they appear as intended in the review window. See below:

The following note:


associated HTML:

<ul><li>cloze list 1:</li><ul><li>{{c1::test</li><li>test</li><li>test</li><li>test}}</li></ul><li>cloze list 2:</li><ul>{{c2::<li>test</li><li>test</li><li>test</li><li>test</li>}}</ul><li>{{c3::cloze 3}}</li></ul>

generates 3 cards. The third card appears like this:


with all clozes revealed:

In this image, the active cloze is cloze 3. Both cloze 1 and cloze 2 are inactive and should be entirely hidden. However, only the first line of cloze 1 is hidden while lines 2-4 remain visible. Cloze 1 is generated by typing “{{c1::” and “}}” manually into the editor. I have tried various methods of highliting/typing to generate the cloze and none have worked as intended.

I was able to make it work as intended in cloze 2 by manually editing the HTML and moving the position of “{{c2::” and “}}” relative to < li > and < /li > as per this post from the prior support thread: (Flexible Cloze [Support thread] - #85 by TRIAEIOU). However, this is impractical, particularly for long cards and a large collection.

Is anyone else encountering this problem? What is the most efficient way of generating clozes containing nonordered lists in a time-efficient manner? For those like me with a large collection of cards containing clozes spanning a multiline list, what is the best method of converting those cards to Flexible cloze?

Thank you.

When you want to enclose a list (or sublist) you need to start at the very end of the preceding line and end at the very end of the last line.

I personally find it easier to cloze lists using the keyboard using End key to ensure end-of-line start and end of the cloze. When selecting by mouse ensure you “drag-select” way past the end of line to get the entire tag.

Showing the HTML editor in the clip below is just for demonstration purposes, I don’t have it open when I edit, I just go from end-of-line to end-of-line when clozing lists/sublists and start-of-line to end-of-line when clozing list items.

examples

1 Like

Thank you for the clear instructions.

I believe the issue I’m having is the placement of the < /li > of line preceding the list I’m attempting to cloze.


In this example, the < /li > for Item A2 immediately follows ‘Item A2’. However, in your HTML, the < /li > for Item A2 follows “Sublist B2 < /li > < /ul >”

When using your method (going from end of line of item A2 to end of line of Sublist item B2), the result for me is this:


with resultant card:
image

If I edit the HTML of my starting note to match yours, then both your cursor and keyboard methods work perfectly! I’m not sure why my Anki creates HTML differently from yours…any ideas? I’ve disabled all my add ons and the issue persists. I’m on the following Anki version: Version ⁨2.1.64 (581f82c5)⁩
Python 3.9.15 Qt 5.15.2 PyQt 5.15.5

EDIT: Actually, it appears if I just hit backspace enough times to delete that extra line, it works properly. Will report back if I notice any persistent issues!! Thank you.

I noticed that hints aren’t working. As with the user above, I am on the most updated version. I’m using Anki on Windows.

Note:


Card upon loading:

Card upon clicking the highlighted cloze field:

The hint never shows.

Is this related to the error message that is showing?

Thank you!

When trying it again from a fresh note writing in the rich text editor I get the same HTML as you do, i.e. the nested list lies between two li. To me it isn’t immediately clear if that is according to spec as both ul and li are listed as flow content (where ul/ol are allowed). It likely stems from the Qt implementation. I almost exclusively edit in Markdown these days but I remember from building the Markdown input that I correct for that behavior:

// Move nested lists inside preceding li
if (
  ['ul', 'ol'].includes(tag) &&
  result[result.length - 1]?.['tagName'] === 'li'
) {
  result[result.length - 1]['children'].push(mutate(child, state))
}

Regardless, when starting with your example, just put the cursor on the “extra” root item and backspace, for me that corrects everything - the nested list is moved into the preceding li and everything works as it should.

example

I think the correct place to fix this is in the Anki source as it is a problem facing anyone wanting to cloze nested lists. In the mean time it should be possible to write a regex that moves nested lists inside preceding li, something like (</li>)\s*(<(ul|ol)>.*?</\3>) with \2\1 (to make it handle 3+ levels you’d have to make it a little more complex as you need to balance the ul/ol opening/closing tags it so don’t run it on your entire collection as is)

As a side note, you also have some other funky stuff going on, at times the Anki editor starts inserting div elements as paragraphs (which it shouldn’t) which also seem to stem from the QWebEngineView implementation.

1 Like

Thank you very much for the detailed answer. I think Markdown is too complex for my needs at this time but it’s good to know that option exists. As you said, deleting that extra line seems to be a reliable enough solution for me.

When you have time, I’d love to hear your thoughts on why the hint function is not working for me.

Thank you again.

Hmm, I’ve found a bug in the hint handling, I’ll update in a while, I also have an error when exiting review mode when on the back/answer side and I can’t figure out why.

1 Like

Ok, I think the problem is in the new core implementation of image occlusion. Cloning a Cloze note and just adding the following produces an error when leaving review mode when on the back/answer side for a note like: one {{c1::two::three}} four

Strike that, it seems to have been a 2.1.63 issue, all good.

To your knowledge, is this new bug something that can be addressed by changes to the note code? If not, do you know whether it could be resolved by downgrading to a prior version of Anki?