[core] Sanitiser: the dark reader's colours (v0.2.0) #2
Reference in New Issue
Block a user
Delete Branch "feature/dark-reader"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The dark reader's colours, for the app's "mail body in the dark" (Epistula
docs/06_screens.md, "Making a mail's HTML dark"). Release: tagv0.2.0.What changes
SanitizeOptions.colours: Colours—Original(the default) orDark(DarkPalette).DarkPalette::DOMIis the Domi theme: body#111726, rule#6b7a99, highlight the--secondtintrgba(244, 201, 93, 0.13).Dark:background,background-colorandbgcolorare removed everywhere. A coloured background onspan,font,mark,b,i,u,strongorembecomes the tint. A white or grey one there just goes.#1b2130and#fff8f0go too.#c0392b→#d7594c,#2e7d32→#36933b,#1a43a6→#517ce4.colorand<font color>.color, background andtext-decoration, so the reader's colour and underline win.!importantis cut (everything after a!) before the forbidden-CSS check. Note: inOriginala declaration with!importantis still dropped whole, because "important" contains "import". That is today's behaviour, kept on purpose.BLOCKED_IMAGE_SRC_DARK(#6b7a99).Sanitized.colours_changed: true when a background that named something was removed, or a colour was lightened. Removing grey text is no change. It is always false inOriginal.sanitize::colour(private module, its functions re-exported): parsing#rgb[a],#rrggbb[aa],rgb[a](),hsl[a]()and the CSS named colours, plus WCAG luminance and contrast,is_greyandreadable_on.SanitizeOptionsneed..Default::default(), and literals ofSanitizedneedcolours_changed. That is why it is 0.2.0.Tests (first, red at
f65c959)cargo test: lib 3 · compose 10 · mime 16 · sanitize 25 (was 9) · thread_rules_search 20 · doc 0. All pass. Clippy: only the warning that was already there (filename.rs:36).New in
tests/sanitize.rs:Originalis byte for byte what v0.1.0 wrote, against a golden recorded before the change.Dark: no background but the tint on a word, every kept colour ≥ 4.5 : 1 and not grey, borders in the rule colour, links without their own colours, no!, nobgcolor, and nothing dangerous.!important, highlights,bgcolor, borders, links as buttons, the palette and placeholder, and the old link colour failing on the dark.Self-review
Darktoo.parse_colournever slices inside a character. Hex digits are checked first, and non-finite numbers (1e999,nan,inf) giveNone. The unit tests cover these cases.bodymust be dark, as documented onDarkPalette.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.