about summary refs log tree commit diff
path: root/filters/html-converters
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@kodafritt.se>2023-01-29 17:55:29 +0100
committerRory& <root@rory.gay>2025-04-26 21:16:43 +0200
commitc7f7b235a8f0d8a3c3fbc8db78aff25d02e79eed (patch)
tree4816765899ffd7dd52f514a3337bb578784cc16e /filters/html-converters
parentClean up flake imports (diff)
downloadcgit-magenta-c7f7b235a8f0d8a3c3fbc8db78aff25d02e79eed.tar.xz
css: Support for dark mode
Modern browsers have a "dark mode" preference, which enables alternate
styles on web sites that support this.

This patch adds a dark color scheme, that is automatically activated
via a CSS @media query.

Older browsers that do not support color schemes will simply show the
light scheme, but possibly without syntax highlighting.

Note that filters that use color (such as source highlighters) and
logotypes may need to be updated to work with a black background!
See the updated files in the filters/ directory.

Signed-off-by: Samuel Lidén Borell <samuel@kodafritt.se>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'filters/html-converters')
-rwxr-xr-xfilters/html-converters/md2html30
1 files changed, 28 insertions, 2 deletions
diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html

index 59f43a8..627808a 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html
@@ -4,6 +4,11 @@ import sys import io from pygments.formatters import HtmlFormatter from markdown.extensions.toc import TocExtension + +# The dark style is automatically selected if the browser is in dark mode +light_style='pastie' +dark_style='monokai' + sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') sys.stdout.write(''' @@ -283,10 +288,31 @@ div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div# background-color: transparent; border: none; } +@media only all and (prefers-color-scheme: dark) { +.markdown-body a.absent { color: #f33; } +.markdown-body h1 .mini-icon-link, .markdown-body h2 .mini-icon-link, .markdown-body h3 .mini-icon-link, .markdown-body h4 .mini-icon-link, .markdown-body h5 .mini-icon-link, .markdown-body h6 .mini-icon-link { color: #eee; } +div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div#cgit .markdown-body h3 a.toclink, div#cgit .markdown-body h4 a.toclink, div#cgit .markdown-body h5 a.toclink, div#cgit .markdown-body h6 a.toclink { color: #eee; } +.markdown-body h1 { color: #eee; } +.markdown-body h2 { border-bottom-color: #333; color: #eee; } +.markdown-body h6 { color: #888; } +.markdown-body hr { border-color: #333; } +.markdown-body blockquote { border-left-color: #222; color: #888; } +.markdown-body table th, .markdown-body table td { border-color: #333; } +.markdown-body table tr { border-top-color: #333; background-color: #111; } +.markdown-body table tr:nth-child(2n) { background-color: #070707; } +.markdown-body span.frame span span { color: #ccc; } +.markdown-body code, .markdown-body tt { border-color: #151515; background-color: #070707; } +.markdown-body .highlight pre, .markdown-body pre { background-color: #070707; border-color: #333; } ''') -sys.stdout.write(HtmlFormatter(style='pastie').get_style_defs('.highlight')) +sys.stdout.write(HtmlFormatter(style=dark_style).get_style_defs('.highlight')) sys.stdout.write(''' -</style> +} +@media (prefers-color-scheme: light) { +''') +sys.stdout.write(HtmlFormatter(style=light_style).get_style_defs('.highlight')) +sys.stdout.write(''' +} +</style> ''') sys.stdout.write("<div class='markdown-body'>") sys.stdout.flush()