Highlight all cloze instances (c1, c2, c3, ...) in every card (Card1, Card2,..)

godfatha1's Avatar


14 Apr, 2019 08:27 PM


I would like to automatically format all text that's contained in a cloze. So if my Note has 3 clozes (c1, c2, c3), for Card1 I would like c2 and c3 to be highlighted, in addition to c1 (which is highlighted by default).

I am a beginner when it comes to javascript and css, but I think what this conditional formatting can be done with javascript.

I came across this code which I'm having difficulty implementing, but I think serves as a good pseudocode to solve this issue:

<span class="field">{{FrontSide}}</span>
<span class="field">{{Back}}</span>

  fields = document.querySelectorAll('.field');
  for(var i=0; i<fields.length; i++) {
    fields[i].innerHTML = fields[i].innerHTML
        .replace('{{c1::***}}', '<span style="color: orange">{{c1::***}}</span>')
        .replace('{{c2::***}}', '<span style="color: orange">{{c2::***}}</span>')
        .replace('{{c3::***}}', '<span style="color: orange">{{c3::***}}</span>')

Comments are closed, but you can start a new discussion.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac