Colors not preserved when pasting in night mode

In this case I’m copying code snippets from Joplin which contains this information

<div class="joplin-editable" style="color: rgb(248, 248, 242); font-family: Avenir, Arial, sans-serif; font-size: 15px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px; white-space: normal; background-color: rgb(40, 42, 54);"><pre class="hljs" style="font-family: monospace, monospace; font-size: 1em; display: block; overflow-x: auto; padding: 0.5em; color: rgb(171, 178, 191); background: rgb(40, 44, 52);"><code style="white-space: pre-wrap !important;">$<span class="hljs-keyword" style="color: rgb(249, 38, 114);">some</span> = <span class="hljs-string" style="color: rgb(152, 195, 121);">"thing"</span> . <span class="hljs-string" style="color: rgb(152, 195, 121);">"beautiful"</span> ;</code></pre></div>

I’ve been doing this for some time now and was amazed how easily it was to add perfectly well syntax highlighted code into my notes by copy/paste from Joplin.

It stopped (I think in 2.1.42). Now only the <code> and <pre> tags are preserved and all those nice <span> tags are gone.

I’d really like to have this behaviour back in the app (as an option?).

To add another example to show that not all <span> tags are dropped:

  1. Copy the git clone line from here and paste it into an anki note
  2. Inspecting it results in
<pre><code>git <span style="font-weight: 700;">clone</span> <span style="font-weight: 700;">--recursive</span> &lt;project url&gt;</code></pre>
  1. Paste it in e.g. this editor and see that in particular the colors have been dropped in anki but are present in the original:
<span class="hljs-keyword" style=" color: rgb(51, 51, 51); font-weight: 700;">clone</span>

Seems to work for me in day mode. In night mode colours are not preserved, as they can be difficult to see against the background.

Thanks a ton. That’s the change I oversaw so I’d like to change the topic title accordingly (but I can’t).

Nonetheless I’d like to question this approach as I really do like my colors in nightmode as well :slight_smile: . Many websites offer a nightmode (or darkmode) with plenty of colors as do code editors with syntax highlighting.

At least make it an option. Shall I open a request on GitHub for it?

I’ve added Handle colours when pasting in night mode · Issue #1078 · ankitects/anki · GitHub

1 Like