Code highlighting Fenced code blocks in Markdown with a language are highlighted using CSS classes, so your stylesheet controls how code looks: ````markdown ```go func main() {} ``` ```` renders as: ```html
func main() {}
```
- The `` has `class="chroma"` and no inline styles. `tabindex="0"` lets
keyboard users scroll wide blocks.
- The `` has `class="language-"`, using the first word of the fence
as written.
- Each line is `...`, and
each token is a `` with Chroma's short class name for its type. Plain
text gets no span.
Common classes:
| Class | Token |
| --- | --- |
| `k` | Keyword |
| `kd` | Declaration keyword (`func`, `var`) |
| `nf` | Function name |
| `nx` | Other name |
| `s`, `s1`, `s2` | Strings |
| `m`, `mi` | Numbers |
| `c`, `c1`, `cm` | Comments |
| `o` | Operator |
| `p` | Punctuation |
The full list is in Chroma's token type table
(). The markup is
the same as Hugo's, so any Chroma stylesheet works: generate one with Chroma's
CLI or `hugo gen chromastyles` and paste it into your CSS.
Taragen adds no highlighting CSS. Without any, code shows in your normal `pre`
and `code` styles. A minimal monochrome style:
```css
.chroma [class^="k"] { font-weight: bold; } /* keywords */
.chroma [class^="c"]:not(.cl) { font-style: italic; } /* comments */
```
Dark mode is just your usual `prefers-color-scheme` rules.
Blocks in a language Chroma doesn't know, blocks without a language, indented
code blocks, and inline code are plain `` (keeping
`class="language-"` when a language was given). Taragen never guesses a
language.