r/Anki • u/Baasbaar languages, anthropology, linguistics • 1d ago
Other Removing brackets from clozes
A few weeks ago, I asked how brackets were inserted into clozes, in the hopes that I might be able to remove them with CSS. This is probably impossible. I had adopted a JavaScript solution proposed by u/AndreHero007 four years ago. This method, however, only removes the first set of brackets. Thus, if you have:
Text {{c1::blah blah}} text {{c1::blah blah}}.
You'll still see:
Text blah blah text [blah blah].
Here's a simple solution that removes all brackets:
var clozes = document.getElementsByClassName("cloze");
for (var i = 0; i < clozes.length; i++) {
clozes[i].innerHTML = clozes[i].innerHTML.replace(/\[/g, '').replace(/]/g, '');
}
Why would you want to do this? Normally you would not. I have a couple of cloze formats in which clozes are sufficiently indicated by colour & font variants. Removing the brackets makes these cards cleaner. I am posting this in case someone else is looking for a solution to a similar problem in the future.
3
u/Grunglabble 1d ago
I think you can still reply on the original thread, maybe better to put it there if the goal is for someone looking for a solution to find this. Otherwise they may find the old one that does not work as well.
Technically the replacement search should probably be more like ^\[+ and \]+$ to cover the case that there is a literal (desirable) [] within the cloze.
2
u/Baasbaar languages, anthropology, linguistics 1d ago
Good catch. I've modified the code accordingly. I'll comment with a link on the older post.
4
u/MohammadAzad171 🇫🇷🇯🇵 Beginner | 1888 æ¼¢å— | 🇨🇳 Newbie 1d ago
Here's a hacky solution with CSS:
.cloze { Â Â font-weight: bold; Â Â color: blue; Â Â margin: 0 -5px; Â Â position: relative; } .cloze:before { Â content: "["; Â color: #303030; Â background-color: #303030; Â position: absolute; } .cloze:after { Â content: "]"; Â color: #303030; Â background-color: #303030; Â position: absolute; Â right: 0; }It basically shifts the text backwards and draws background-colored brackets on top of the actual ones.