Editor: apply font color, background color, custom class, custom style [Official thread]

Is there any way to disable the Auto Update Note Types warning? I have a ton of note types, some of which I use regularly to collaborate with other people, and it’s important that I maintain consistency with their copy of the templates. So I have deliberately refrained from auto-updating the note types, as I only use the text wrapping function which requires no css.

Are there any sections of code I could comment out or delete so that this warning doesn’t pop up every time I open Anki? I tried commenting out some stuff that seemed relevant to that function, but the addon threw errors. Or could you perhaps implement a checkbox in the addon config to toggle the auto-update styling function, in the next version of the addon?

I agree that this warning should only show up once. I will try to look into it shortly. If you find out which part it is, I’d also really appreciate it if you told me :slight_smile:

If you find out which part it is

Not sure if this what you’re asking about, but I tinkered around a bit more and I found out that if I comment out lines 86-90 of conf_dict.py:

     missing = templates_that_miss_the_import_of_the_styling_file()
     if missing:
          if askUser(warning_message_about_templates(missing)):

It stops displaying the update notes dialog on startup.

And if I comment out lines 41-47 of main_window.py:

     missing = templates_that_miss_the_import_of_the_styling_file()
     if not missing:
         msg = msg_restart_required + "\n\n" + warning_message_about_templates(missing)
         if askUser(msg):

It stops displaying the dialog every time you Edit the config.

If you have the time, could you check out this odd behaviour in the text wrapping function:

When I have the ‘Before’ string set to
<button class="hintzubutton" onclick=" if (document.getElementById('hintzu') .style.display=='none'){document.getElementById('hintzu') .style.display=''} else {document.getElementById('hintzu') .style.display='none'}" type="button">Expand</button><div id="hintzu">

and the ‘After’ string as </div>. It works as expected and wraps the selected content.

But when I change the front string to
<button class="hintzubutton" onclick=" if (document.getElementById('hintzu') .style.display=='none'){document.getElementById('hintzu') .style.display=''} else {document.getElementById('hintzu') .style.display='none'}" type="button">Expand</button><div id="hintzu" style="display:none;">
(Just adding style="display:none;" within the <div> tag )
It inserts the before and after strings, but the content that was selected, disappears.

P.S. I’ve also opened an issue related to the text wrapping function on the GitHub, #47, can you see it? I ask because my GitHub profile was flagged and someone said that they could not see the issue I had posted in another repo.

I think this is related to the selection function of the editor itself.

I’ve noticed similar behaviour while making clozes, if you select the first two lines in your example field content and use the cloze shortcut, the cloze is made, but the line break between the second and the third line disappears. But if you select the two lines using Ctrl+Shift+Arrow Keys, being careful to not to select anything once you have selected the last word in the last line, and then use the cloze shortcut. It wraps the two lines as expected, without consuming the line breaks. I think there is difference between the two selections (whole lines vs. selecting word-by-word), even though they appear visually the same. In the first one, selecting the whole line includes the <br> tag in the selection, and tries to wrap it in the cloze, leading to the funky behaviour. In the second one, the selection extends only to the end of the last word, in the line, and ends just before the <br> tag, leading to more expected behaviour.

Though I have used the cloze function in my example, I have tried it with a text wrapping function that wraps in <div> and </div> tags, and it worked exactly like i explained it for the cloze.

@hengiesel doesn’t seem like you replied to my comment I made on April 4th in reply to your post you made on April 4th. Not sure if you saw it or not. Still having issues where my custom inline styles are not being applied.

I had to downgrade to version 4.1.40, and once I did that the inline styling could be applied. Also, I just found another bug: sometimes the “remove formatting” button will delete text. For example, in the text “The HTML element allows authors to link…” clearing the formatting will delete the text “”.

@hengiesel any update on this?

You’re my only hope at this point, the authors of the other two Custom HTML Wrapping addons don’t seem to support them anymore haha

Thanks for this great add-on. Is it possible to use while reviewing cards with the edit fields during review add-on?

Hi. Text in menu not working in version 2.1.47.

The addon works for me when I install it, but when I close Anki and run it again it stops working and gives me this error message:

Anki 2.1.44 (b2b3275f) Python 3.8.6 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 10
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2021-09-10 12:54:44

Caught exception:
Traceback (most recent call last):
File “aqt\editor.py”, line 392, in checkFocus
File “C:\Users*\AppData\Roaming\Anki2\addons21\1899278645\editor\shortcuts.py", line 17, in
cuts.append((e[“Hotkey”], lambda s=e[“Setting”], f=func: f(editor, s)))
File "C:\Users*
\AppData\Roaming\Anki2\addons21\1899278645\editor\apply_categories.py”, line 17, in my_wrap_helper
before, after = beforeAfter.split(unique_string)
ValueError: not enough values to unpack (expected 2, got 1)


How do you add the: “@import url(”_editor_button_styles.css");" to all the note-models at once?
I keep getting this notification when I open Anki, but it is bigger than my screen and I can’t resize it, so I cannot read the bottom part of it.

If I remember correctly, there once was the option to add such code via the addon’s configuration menu, but I tried checking it and did not find it. Am I doing something wrong?

Thank you in advance

I noticed that, if I try to add inline styles using this addon, nothing at all happens.
I am using Anki 2.1.49; the same configurations worked fine in Anki 2.1.22

Everything else seems to work as it should

1 Like

Please make it work correctly in Anki 2.1.53

An update for 2.1.54~ is imminent, and will be coming soon, check out here.

1 Like

Is the version from GitHub supposed to work with 2.1.54 already?
I’ve tried it out but I’m getting an error at start-up.

It’s completely broken and useless in the newer anki version. And I think anki is to blame

The fix is still only almost done, I’d need another day of patching, I’m trying my best to get it out

1 Like

Really? I think it is not an issue with your addon but with anki. It can’t show applied style in editor but it can in reviewing screen. In older version of anki even with removed (your) addon still formatted styles are visible in both in editor and review screen, but in new anki only in review screen. So, I think the author of anki needs to make some changes otherwise even if you fix it, it will ALWAYS require your addon to be installed to see modifications in editor.

@hengiesel is a co-author main contributor of Anki :wink: The new editor features are mostly his work.

Did you use inline styles in both cases or could it be that you used classes on the newer version?