ankitects / anki

Anki's shared backend and web components, and the Qt frontend
https://apps.ankiweb.net
Other
18.34k stars 2.1k forks source link

Handle colours when pasting in night mode #1078

Open dae opened 3 years ago

dae commented 3 years ago

The paste filter in htmlFilter.ts currently strips formatting when pasting in night mode. The majority of pastes are coming from pages with light backgrounds, and thus have dark foregrounds, which tend to be difficult to read on a dark background. If we allow the background colour to come in as well, we end up with nasty-looking black-on-white strips of text.

We could use some color arithmetic to modify the colours as we paste, though we may end up with them being difficult to read if the user switches to day mode afterwards.

I believe AnkiDroid's default CSS inverts text colours in night mode. This changes the hue and doesn't look great, and I'm not sure how it would cope with content pasted from a dark website. But perhaps we could use a solution that adjusts the lightness while keeping the hue closer.

Suggestions or a PR welcome!

sh34v3 commented 3 years ago

I think I've been encountering a similar problem. In review I've found that a number of my cards have had selections of text restyled as lighter colors. Though, when initially creating these cards this was not a problem... image

sh34v3 commented 3 years ago

The saved HTML also seems to have a bunch of additions in it that I never added...

Too much <b>mulch</b>&nbsp;can...<div>1)&nbsp;<span style="color: var(--text-fg);">{{c1::stifle </span><b style="color: var(--text-fg);">lenticel respiration</b><span style="color: var(--text-fg);">::<i>damage buried tissues...</i></span><span style="color: var(--text-fg);">}}</span></div><div>2)&nbsp;<span style="color: var(--text-fg);">{{c2::foster </span><b style="color: var(--text-fg);">fungal</b><span style="color: var(--text-fg);">&nbsp;and </span><b style="color: var(--text-fg);">bacterial </b><span style="color: var(--text-fg);"><b>pathogens</b>::<i>foster which <b>pathogens</b></i>}}</span></div><div>3)&nbsp;<span style="color: var(--text-fg);">{{c3::provide habitats for </span><b style="color: var(--text-fg);">pests</b><span style="color: var(--text-fg);">&nbsp;to feed on the soft </span><b style="color: var(--text-fg);">bark</b><span style="color: var(--text-fg);">::<i><b>parasitic</b> threat</i></span><span style="color: var(--text-fg);">}}</span></div>

dae commented 3 years ago

A previous Anki version was erroneously including those var(...) lines when pasting between fields. The issue has since been fixed, and you should be able to use the Find&Replace feature in the browse screen to remove the unwanted styling.

algopenne commented 10 months ago

Experiencing this as well. As far as suggestions I think https://github.com/ankitects/anki/issues/1964 is relevant or the changes made in https://github.com/ankitects/anki/commit/4dbb87e4c192811122d1cab5d1cf849731c5780e

There's also this string, seems to be a lot of things that could affect this https://github.com/search?q=repo%3Aankitects%2Fanki+paste_strips_formatting&type=code