diff --git a/docs/importing.md b/docs/importing.md index e4a3958..8bb9a09 100644 --- a/docs/importing.md +++ b/docs/importing.md @@ -85,8 +85,10 @@ pages are written: What doesn't come across is listed in `IMPORT-REPORT.md`, page by page: snippet includes (`--8<--`), template tags (the macros plugin), abbreviations, icons and emoji (`:material-check:`), Mermaid diagrams (shown -as code), code highlighting and annotations, and the theme's overrides and -extra CSS and JavaScript: the site's own look replaces the theme. +as code), code annotations, and the theme's overrides and extra CSS and +JavaScript: the site's own look replaces the theme. Code blocks are colored +as pymdownx.highlight colors them, with the same class names, and +`hl_lines` marks lines; line numbers (`linenums`) aren't drawn. MkDocs passes any HTML in a page through as it is; HotDog sanitizes it, so an inline ``, a `
` around the block and +Pygments' short class names on the pieces (`.k` a keyword, `.s` a string, +`.c1` a comment), so a stylesheet written for MkDocs or Pygments colors it +too. `hl_lines="2 4-5"` in the fence's info marks those lines +(``). A block with no language, `text`, or a language +chroma doesn't know is left as it always was. + +The starter's stylesheet and the docs pack's have the colors: each is a hue +from the palette (`--code-keyword`, `--code-string`, `--code-number`, +`--code-function`, `--code-type`, `--code-tag`, `--code-mark`) mixed into the +code block's own text color, so the same hues read on a light block and a +dark one. A theme without these rules shows the code as before. +`markdown.highlight: false` in `site.yaml` turns the coloring off. + ## The footer `site.yaml`'s `copyright:` names who holds the copyright the footer shows diff --git a/go.mod b/go.mod index d56bf79..b707238 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.coffeylabs.org/coffey-labs/hotdog-cms go 1.26.0 require ( + github.com/alecthomas/chroma/v2 v2.27.0 github.com/fsnotify/fsnotify v1.10.1 github.com/microcosm-cc/bluemonday v1.0.27 github.com/yuin/goldmark v1.8.6 @@ -14,6 +15,7 @@ require ( require ( github.com/aymerick/douceur v0.2.0 // indirect + github.com/dlclark/regexp2/v2 v2.2.1 // indirect github.com/gorilla/css v1.0.1 // indirect golang.org/x/sys v0.48.0 // indirect ) diff --git a/go.sum b/go.sum index a25a8ae..035c573 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,19 @@ +github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= +github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= +github.com/alecthomas/chroma/v2 v2.27.0 h1:FodwmyOBgJULFYmDqibcp9pvfDLWdtPRh9v/r5BXYZs= +github.com/alecthomas/chroma/v2 v2.27.0/go.mod h1:NjJ3ciIgrqBNeIkWZ4e46nseoLDslxU1LmfCoL+wcY8= +github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs= +github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= +github.com/dlclark/regexp2/v2 v2.2.1 h1:mf4KkFUj0gJuarK8P+LgiS+Lit7m9N1yAwEfPbee7R0= +github.com/dlclark/regexp2/v2 v2.2.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho= github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA= github.com/yuin/goldmark v1.8.6 h1:d0VcaP1sx9GkFVkoW+KtggpGi2KZ965i14b0+bDQST4= diff --git a/internal/importer/mkdocs.go b/internal/importer/mkdocs.go index 8461cda..01f2b79 100644 --- a/internal/importer/mkdocs.go +++ b/internal/importer/mkdocs.go @@ -136,6 +136,7 @@ var mkdocsUnderstood = map[string]bool{ "tables": true, "toc": true, "pymdownx.details": true, "pymdownx.keys": true, "pymdownx.tabbed": true, "pymdownx.tasklist": true, "pymdownx.superfences": true, "pymdownx.betterem": true, "fenced_code": true, "pymdownx.tilde": true, "sane_lists": true, "meta": true, "pymdownx.magiclink": true, + "pymdownx.highlight": true, "codehilite": true, } // mkdocsSource maps a file under docs_dir to its source under content/: diff --git a/internal/site/config.go b/internal/site/config.go index 8f67c39..585a064 100644 --- a/internal/site/config.go +++ b/internal/site/config.go @@ -106,11 +106,17 @@ type MarkdownConfig struct { // the key's own capitalized: {hash: "#"} shows ++hash++ as #. MkDocs' // pymdownx.keys calls it key_map. Keys map[string]string `yaml:"keys"` + // Highlight colors code blocks that name their language (```go) when the + // site is built (highlight.go). On unless set to false. + Highlight *bool `yaml:"highlight"` } // AutolinkOn reports whether bare URLs become links. func (m MarkdownConfig) AutolinkOn() bool { return m.Autolink == nil || *m.Autolink } +// HighlightOn reports whether code blocks are colored. +func (m MarkdownConfig) HighlightOn() bool { return m.Highlight == nil || *m.Highlight } + // Redirect sends one old address somewhere else. type Redirect struct { From string `yaml:"from" json:"from"` diff --git a/internal/site/docsyntax_test.go b/internal/site/docsyntax_test.go index 3327365..1250e24 100644 --- a/internal/site/docsyntax_test.go +++ b/internal/site/docsyntax_test.go @@ -52,7 +52,7 @@ func TestTabs(t *testing.T) { got := render(t, MarkdownConfig{}, "=== \"Linux\"\n ```sh\n a\n ```\n\n===+ \"macOS\"\n Two.\n\n===! \"Other\"\n New set.\n\n=== \"More\"\n Same set.\n") for _, want := range []string{ `
`, - "
\n
a\n
\n
", + "
\n
a\n
\n
", `data-tabs="2:2">\n **Bold** inside.\n\n - one\n
\n\n```html\n
\nleft alone in code\n
\n```\n" + src := "
\n **Bold** inside.\n\n - one\n
\n\n```text\n
\nleft alone in code\n
\n```\n" got := render(t, MarkdownConfig{TrustHTML: true}, src) for _, want := range []string{"
\n

Bold inside.

\n
    \n
  • one
  • \n
\n
", "<div markdown>"} { if !strings.Contains(got, want) { @@ -184,8 +184,8 @@ func TestAdmonitionTitleMarkdown(t *testing.T) { func TestCodeTitle(t *testing.T) { got := render(t, MarkdownConfig{}, "```json title=\"servers.json\"\n{\"a\": 1}\n```\n\n```sh\nls\n```\n") for _, want := range []string{ - "
servers.json
{"a": 1}\n
\n
", - "
ls\n
", + "
servers.json
{"a": 1}\n
\n
", + "
ls\n
", } { if !strings.Contains(got, want) { t.Errorf("missing %q in\n%s", want, got) diff --git a/internal/site/highlight.go b/internal/site/highlight.go new file mode 100644 index 0000000..b637682 --- /dev/null +++ b/internal/site/highlight.go @@ -0,0 +1,181 @@ +package site + +// Code highlighting, done when the site is built, so a page needs no script +// for it. A fenced block whose info names a language chroma knows, +// +// ```go +// +// comes out as pymdownx.highlight writes it, with Pygments' class names, +// so a stylesheet written for MkDocs colors it too: +// +//
func …
+//
+// The colors are the site's stylesheet's to choose (the starter's and the
+// docs pack's have them); without any, the code reads as it did before.
+// A block with no language, or one chroma doesn't know, is left as it was.
+//
+// hl_lines="2 4-5" in the info marks lines, as pymdownx.highlight does:
+// each is wrapped in .
+
+import (
+	"regexp"
+	"strconv"
+	"strings"
+
+	"github.com/alecthomas/chroma/v2"
+	"github.com/alecthomas/chroma/v2/lexers"
+	"github.com/yuin/goldmark"
+	"github.com/yuin/goldmark/ast"
+	"github.com/yuin/goldmark/renderer"
+	"github.com/yuin/goldmark/renderer/html"
+	"github.com/yuin/goldmark/util"
+)
+
+type codeHighlight struct{}
+
+func (codeHighlight) Extend(m goldmark.Markdown) {
+	// Ahead of goldmark's own renderer (1000), which still draws the blocks
+	// this one leaves alone.
+	m.Renderer().AddOptions(renderer.WithNodeRenderers(util.Prioritized(codeRenderer{}, 200)))
+}
+
+type codeRenderer struct{}
+
+func (codeRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
+	reg.Register(ast.KindFencedCodeBlock, renderFencedCode)
+}
+
+// plainFenced is goldmark's own renderer for a fenced block, for the blocks
+// that aren't highlighted, so they come out exactly as they always have.
+var plainFenced = func() renderer.NodeRendererFunc {
+	var g grabFenced
+	html.NewRenderer().RegisterFuncs(&g)
+	return g.f
+}()
+
+type grabFenced struct{ f renderer.NodeRendererFunc }
+
+func (g *grabFenced) Register(k ast.NodeKind, f renderer.NodeRendererFunc) {
+	if k == ast.KindFencedCodeBlock {
+		g.f = f
+	}
+}
+
+var hlLinesRe = regexp.MustCompile(`\bhl_lines=(?:"([^"]*)"|'([^']*)')`)
+
+func renderFencedCode(w util.BufWriter, src []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
+	n := node.(*ast.FencedCodeBlock)
+	var info []byte
+	if n.Info != nil {
+		info = n.Info.Segment.Value(src)
+	}
+	lang := strings.ToLower(string(n.Language(src)))
+	marked := markedLines(info)
+	lexer := codeLexer(lang)
+	if lexer == nil && len(marked) > 0 {
+		lexer = lexers.Fallback
+	}
+	if lexer == nil {
+		return plainFenced(w, src, node, entering)
+	}
+	if !entering {
+		return ast.WalkContinue, nil
+	}
+	var code strings.Builder
+	for i := 0; i < n.Lines().Len(); i++ {
+		l := n.Lines().At(i)
+		code.Write(l.Value(src))
+	}
+	it, err := chroma.Coalesce(lexer).Tokenise(&chroma.TokeniseOptions{State: "root", EnsureLF: true}, code.String())
+	if err != nil {
+		// chroma gave up on it; the block is still worth showing.
+		return plainFenced(w, src, node, entering)
+	}
+	_, titled := n.Parent().(*codeTitle)
+	if !titled {
+		w.WriteString(`
`) + } + w.WriteString(`
")
+	for i, line := range chroma.SplitTokensIntoLines(it.Tokens()) {
+		if marked[i+1] {
+			w.WriteString(``)
+		}
+		for _, t := range line {
+			if cls := tokenClass(t.Type); cls != "" {
+				w.WriteString(``)
+				w.Write(util.EscapeHTML([]byte(t.Value)))
+				w.WriteString("")
+			} else {
+				w.Write(util.EscapeHTML([]byte(t.Value)))
+			}
+		}
+		if marked[i+1] {
+			w.WriteString("")
+		}
+	}
+	w.WriteString("
") + if !titled { + w.WriteString("
") + } + w.WriteString("\n") + return ast.WalkSkipChildren, nil +} + +// codeLexer finds the lexer for a fence's language, by name, alias or file +// extension. Plain text gets none: there's nothing in it to color. +func codeLexer(lang string) chroma.Lexer { + if lang == "" { + return nil + } + l := lexers.Get(lang) + if l == nil || l.Config().Name == "plaintext" { + return nil + } + return l +} + +// tokenClass is the Pygments class for a token, or its parent's when it has +// none of its own; plain text has none. +func tokenClass(t chroma.TokenType) string { + for ; t != 0; t = t.Parent() { + if cls, ok := chroma.StandardTypes[t]; ok { + if cls == "w" { + return "" // whitespace: nothing to color + } + return cls + } + } + return "" +} + +// markedLines reads hl_lines="2 4-5" into the line numbers it names. +func markedLines(info []byte) map[int]bool { + m := hlLinesRe.FindSubmatch(info) + if m == nil { + return nil + } + out := map[int]bool{} + for _, f := range strings.Fields(string(m[1]) + string(m[2])) { + from, to, ok := strings.Cut(f, "-") + a, err := strconv.Atoi(from) + if err != nil { + continue + } + b := a + if ok { + if b, err = strconv.Atoi(to); err != nil { + continue + } + } + for i := a; i <= b && i-a < 10000; i++ { + out[i] = true + } + } + return out +} diff --git a/internal/site/highlight_test.go b/internal/site/highlight_test.go new file mode 100644 index 0000000..612b9b5 --- /dev/null +++ b/internal/site/highlight_test.go @@ -0,0 +1,60 @@ +package site + +import ( + "strings" + "testing" +) + +func TestHighlight(t *testing.T) { + got := render(t, MarkdownConfig{}, "```go\nfunc main() { return \"\" } // done\n```\n") + for _, want := range []string{ + `
func main`,
+		`"<hi>"`,
+		`// done` + "\n
", + } { + if !strings.Contains(got, want) { + t.Errorf("missing %q in\n%s", want, got) + } + } +} + +func TestHighlightLeavesPlainBlocks(t *testing.T) { + for _, src := range []string{"```\na < b\n```\n", "```nosuchlanguage\na < b\n```\n", "```text\na < b\n```\n", " a < b\n"} { + got := render(t, MarkdownConfig{}, src) + if strings.Contains(got, "highlight") || strings.Contains(got, "
") { + t.Errorf("%q: want the block as it was, got\n%s", src, got) + } + } + off := false + if got := render(t, MarkdownConfig{Highlight: &off}, "```go\nfunc f() {}\n```\n"); got != "
func f() {}\n
\n" { + t.Errorf("highlight: false still colored:\n%s", got) + } +} + +func TestHighlightWithTitleAndLines(t *testing.T) { + got := render(t, MarkdownConfig{}, "```yaml title=\"site.yaml\" hl_lines=\"2 4-5\"\na: 1\nb: 2\nc: 3\nd: 4\ne: 5\n```\n") + if strings.Count(got, `class="highlight"`) != 1 || !strings.HasPrefix(got, `
site.yaml
`) {
+		t.Errorf("want one highlight box, the file name over the code:\n%s", got)
+	}
+	if n := strings.Count(got, ``); n != 3 {
+		t.Errorf("want lines 2, 4 and 5 marked, got %d:\n%s", n, got)
+	}
+	if !strings.Contains(got, "\nb") && !strings.Contains(got, `b`) {
+		t.Errorf("line 2 isn't the marked one:\n%s", got)
+	}
+	// Marking lines works on a block in no language too.
+	if got := render(t, MarkdownConfig{}, "``` hl_lines=\"1\"\nplain\n```\n"); !strings.Contains(got, "plain\n") {
+		t.Errorf("unmarked plain line:\n%s", got)
+	}
+}
+
+// With unsafe_html the output passes the sanitizer, which must keep the
+// classes the colors hang on.
+func TestHighlightSurvivesSanitizer(t *testing.T) {
+	got := render(t, MarkdownConfig{UnsafeHTML: true}, "```bash\necho \"hi\" # say it\n```\n")
+	for _, want := range []string{`
`, `echo`, `# say it`} { + if !strings.Contains(got, want) { + t.Errorf("missing %q in\n%s", want, got) + } + } +} diff --git a/internal/site/markdown.go b/internal/site/markdown.go index 08c1464..22a15a8 100644 --- a/internal/site/markdown.go +++ b/internal/site/markdown.go @@ -42,6 +42,9 @@ func NewMarkdown(c MarkdownConfig, host string) *Markdown { if c.AutolinkOn() { exts = append(exts, extension.Linkify) } + if c.HighlightOn() { + exts = append(exts, codeHighlight{}) + } rendererOpts := []goldmark.Option{ goldmark.WithExtensions(exts...), goldmark.WithParserOptions(parser.WithAutoHeadingID(), parser.WithAttribute()), diff --git a/packs/docs/README.md b/packs/docs/README.md index 2700092..161c9ee 100644 --- a/packs/docs/README.md +++ b/packs/docs/README.md @@ -16,3 +16,10 @@ host, as on a docs subdomain. The docs collection gets a search index (`/docs/search.json`, with each page's headings so a result can go to its section); a pack can't carry scripts, so adding a search box is up to the site. hotdogcms.org/docs is built with this pack. + +Code blocks that name their language (` ```yaml `) are colored when the +site is built, and the pack's stylesheet has the colors: each one a hue +mixed into the code's own text color, so they read on light code blocks and +dark ones. A theme that wants other hues sets `--code-keyword`, +`--code-string`, `--code-number`, `--code-function`, `--code-type`, +`--code-tag` and `--code-mark` (behind lines marked with `hl_lines`). diff --git a/packs/docs/assets/docs.css b/packs/docs/assets/docs.css index ba1b122..68420aa 100644 --- a/packs/docs/assets/docs.css +++ b/packs/docs/assets/docs.css @@ -164,3 +164,17 @@ dd { margin: .2em 0 0 1.4em; color: var(--text); } /* A code block's file name (```json title="servers.json"). */ .highlight > .filename { display: block; margin-top: 1.2em; padding: 6px 14px; font: 600 .85em var(--font-mono, monospace); color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0; } .highlight > .filename + pre { margin-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; } +/* Code colors. Blocks that name their language (```go) are colored when the + site is built, with Pygments' class names. Each color is a hue mixed into + the code's own text color, so it reads on a light block and a dark one, + on any theme. A theme can set the hues (--code-keyword and the rest). */ +.highlight :is(.k, .kd, .kn, .kp, .kr, .ow, .cp, .cpf, .nd) { color: color-mix(in srgb, var(--code-keyword, #a855f7) 60%, currentColor); } +.highlight :is(.s, .sa, .sb, .sc, .dl, .sd, .s1, .s2, .sh, .sx, .sr, .ss, .l, .ld, .gi) { color: color-mix(in srgb, var(--code-string, #16a34a) 60%, currentColor); } +.highlight :is(.m, .mb, .mf, .mh, .mi, .il, .mo, .se, .si, .no, .kc, .na) { color: color-mix(in srgb, var(--code-number, #ea7a12) 60%, currentColor); } +.highlight :is(.nf, .fm, .nc, .nn, .ne, .gh, .gu) { color: color-mix(in srgb, var(--code-function, #2f7ff0) 60%, currentColor); } +.highlight :is(.kt, .nb, .bp) { color: color-mix(in srgb, var(--code-type, #0d9488) 60%, currentColor); } +.highlight :is(.nt, .nv, .vc, .vg, .vi, .vm, .gd, .gr, .gt) { color: color-mix(in srgb, var(--code-tag, #e0457b) 60%, currentColor); } +.highlight :is(.c, .ch, .cm, .c1, .cs, .gp, .go) { color: color-mix(in srgb, currentColor 68%, transparent); } +.highlight :is(.c, .ch, .cm, .c1, .cs, .ge) { font-style: italic; } +.highlight :is(.gh, .gu, .gs) { font-weight: 700; } +.highlight .hll { display: block; background: color-mix(in srgb, var(--code-mark, #f5c542) 22%, transparent); } diff --git a/packs/docs/pack.yaml b/packs/docs/pack.yaml index 3c4adaa..fd76da5 100644 --- a/packs/docs/pack.yaml +++ b/packs/docs/pack.yaml @@ -1,5 +1,5 @@ name: docs -version: 1.4.0 +version: 1.5.0 title: Documentation description: A documentation section with a sidebar of parts and pages (as deep as you like), a breadcrumb, an on-this-page list, a page for each part, and previous and next links, in the order you set. license: MIT diff --git a/starter/site/assets/styles.css b/starter/site/assets/styles.css index 1c6ed86..61a40e2 100644 --- a/starter/site/assets/styles.css +++ b/starter/site/assets/styles.css @@ -21,6 +21,10 @@ --accent-soft: #fbeadf; --band: #1d2b3a; --band-text: #f5f1ea; + /* Code colors: hues, mixed with the code's text color where they're used, + so the same ones serve light mode and dark. */ + --code-keyword: #a855f7; --code-string: #16a34a; --code-number: #ea7a12; + --code-function: #2f7ff0; --code-type: #0d9488; --code-tag: #e0457b; --code-mark: #f5c542; --radius: 14px; --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --font-mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, monospace; @@ -256,3 +260,17 @@ dd { margin: .2em 0 0 1.4em; color: var(--text); } /* A code block's file name (```json title="servers.json"). */ .highlight > .filename { display: block; margin-top: 1.2em; padding: 6px 14px; font: 600 .85em var(--font-mono, monospace); color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0; } .highlight > .filename + pre { margin-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; } +/* Code colors. Blocks that name their language (```go) are colored when the + site is built, with Pygments' class names. Each color is a hue mixed into + the code's own text color, so it reads on a light block and a dark one, + and follows the band color the Look panel sets. */ +.highlight :is(.k, .kd, .kn, .kp, .kr, .ow, .cp, .cpf, .nd) { color: color-mix(in srgb, var(--code-keyword) 60%, currentColor); } +.highlight :is(.s, .sa, .sb, .sc, .dl, .sd, .s1, .s2, .sh, .sx, .sr, .ss, .l, .ld, .gi) { color: color-mix(in srgb, var(--code-string) 60%, currentColor); } +.highlight :is(.m, .mb, .mf, .mh, .mi, .il, .mo, .se, .si, .no, .kc, .na) { color: color-mix(in srgb, var(--code-number) 60%, currentColor); } +.highlight :is(.nf, .fm, .nc, .nn, .ne, .gh, .gu) { color: color-mix(in srgb, var(--code-function) 60%, currentColor); } +.highlight :is(.kt, .nb, .bp) { color: color-mix(in srgb, var(--code-type) 60%, currentColor); } +.highlight :is(.nt, .nv, .vc, .vg, .vi, .vm, .gd, .gr, .gt) { color: color-mix(in srgb, var(--code-tag) 60%, currentColor); } +.highlight :is(.c, .ch, .cm, .c1, .cs, .gp, .go) { color: color-mix(in srgb, currentColor 68%, transparent); } +.highlight :is(.c, .ch, .cm, .c1, .cs, .ge) { font-style: italic; } +.highlight :is(.gh, .gu, .gs) { font-weight: 700; } +.highlight .hll { display: block; margin: 0 -18px; padding: 0 18px; background: color-mix(in srgb, var(--code-mark) 22%, transparent); }