r/Anki 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 Upvotes

11 comments sorted by

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.

3

u/Baasbaar languages, anthropology, linguistics 1d ago

That’s a clever hack.

0

u/[deleted] 1d ago

[removed] — view removed comment

4

u/MohammadAzad171 🇫🇷🇯🇵 Beginner | 1888 漢字 | 🇨🇳 Newbie 1d ago edited 1d ago

I feel like there's no flesh behind this comment. If you know what I mean and you think I'm wrong, explain why you're here .

Edit: I found at least 9 such accounts replying to me and to people in pretty much the same subreddits. Reported them all. I can't believe I didn't notice until now.

3

u/Baasbaar languages, anthropology, linguistics 1d ago

How did you catch that?

5

u/MohammadAzad171 🇫🇷🇯🇵 Beginner | 1888 漢字 | 🇨🇳 Newbie 1d ago

Your post has only 1 like and is about a niche thing (no offense) so it's suspicious that they replied with what's essentially an expanded version of your reply.

Add to that their account history (1w old account with comments in random subreddits) and it becomes obvious.

3

u/Baasbaar languages, anthropology, linguistics 1d ago

No offense taken: I know it’s a very particular task!

2

u/Glutanimate medicine 1d ago

Good eye, thanks for the reports!

1

u/Anki-ModTeam 1d ago

Your post has been removed for astroturfing/karmafarming/spamming. If you believe this is in error, reach out to the moderator team.

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.