Padding cloze-bracketing with zero-width spaces

This suggestion is related to Escaping double colon "::" in cloze deletion cards

There’s a conflict whenever either double colons or double curly-brackets are enclosed within a cloze field, or when one (or more) thereof are at the edge of the field, whether inside or outside.
Adding zero-width space circumvents the problem, but it is quite tedious to do even for a single card, to say nothing of doing it repeatedly if it so happens that one’s use case requires it.

I was wondering whether it would not be a good idea to:

  1. change the cloze bracketing such that they would include zero-width space automatically, i.e. that the add-note interface would input them and the parser expect them.
    That is, instead of {{c1::surprise::wrapping}}
    to have X{{c1::XsurpriseX::XwrappingX}}X (where X indicate zero-width space location)
  2. add, for backward compatibility, zero-width spaces into existing cards where the parser would expect them.

Thanks!

Zero width space is a perfect way to confuse users. “Why is my cloze card not working?”, “I encountered a weird bug after the latest update where typing the cloze syntax manually no longer works”, “My really complicated template suddenly stopped working!”, etc.

I agree that there should be a more intuitive way to escape these special characters.

2 Likes

True, manual typing of the enclosing (as well as importation) would be an issue.
What sort of (complicated) templates are you referring to?

Find and Replace

Hey,
I know about the find and replace functionality. I don’t see how it would be of help, however.

1 Like

I have no idea, someone somewhere somehow might have relied on the current syntax in their templates. (If that’s not possible, then maybe an addon)

1 Like

Can you give more details about your use case? Perhaps there’s a better way to make this work for you besides making it untype-able for everyone else?

1 Like

Some might use raw cloze expressions and parse them in card scripts directly to present the data in a desired way.

Can confirm that. One of my add-ons relies on the explicit use of the current syntax to make multiple-choice cards for the cloze note types. There are probably many other cases like that as well.

2 Likes

Maybe using a more easily typed way of escaping the colons and brackets, e.g. \:\:, when making cards and then using the find-and-replace to convert all of them into using zero-width space, would work for you?
Alternatively, the conversion can also be done on the side of the card template scripts during the review, so that there won’t be any need to apply the replacement manually each time after adding a card.

I’m making cloze cards for Rust expressions, which use double colons (::) as well as curly brackets.

The alternative sounds like a solution, though I wouldn’t know how to go about it. Otherwise, I think it would be easier for me to add a key for the zws to my keyboard and type it in when I make notes.

This topic might help: Adding sample cloze strings to Back, without generating cards.

1 Like

Try the following script:

<script>
document.querySelectorAll(".cloze").forEach((clozeElement) => {
	clozeElement.innerHTML = clozeElement.innerHTML.replace(/\\:\\:/,"::");
});
</script>

Yep, the thread that @ZornHadNoChoice posted matches your case. Take a look at that.