Syntax highlighting: The look and feel

Nue uses the built-in syntax highlighter, Glow, to style your fenced code blocks with minimal setup. It offers the following features:

For details on adding code blocks to your Markdown documents, refer to the code syntax guide. This article also explains how to adjust the look and feel of the generated HTML.

The HTML output

Syntax blocks are rendered as standard HTML tags, without additional class names. For example, the following Markdown block:

 ```javascript
 // a comment
 "A string value"
 ```

Produces the HTML:

<pre>
  <code language="javascript">
    <sup>// a comment
    <em>"A string value"</em>
    ...
  </code>
</pre>

Built-in stylesheet

Whenever you add a syntax block, Nue includes a stylesheet for syntax highlighting. This stylesheet is configurable through CSS variables, and a few adjustments are usually all that’s needed to make code blocks match your design system:

/* Key Glow variables */
pre {
  --glow-base-color: #eee;
  --glow-primary-color: #823;
  --glow-padding: 2em;
}

To disable the built-in stylesheet for full control over your styles, set this in site.yaml:

syntax_highlight: false

Then, add your own stylesheet with the variables and elements described below.

CSS variables and HTML elements

Below is a list of all CSS variables with the associated HTML elements for styling syntax blocks:

CSS variableDefault valueHTML tagDescription
accent-color#419fffstrongspecial emphasis
base-color#555foreground color
char-color#64748bibrackets, commas...
comment-color#4e5d61supcomments
counter-color#475569line numbers
del-color250, 110, 130deldeleted lines
error-color#ff0uerrors
ins-color50, 210, 190insinserted lines
line-color50, 180, 250dfnhighlighted lines
line-opacity0.15highlighted line opacity
padding1emcontainer padding
primary-color#7dd3fcbprimary accent color
secondary-color#f472b6emsecondary accent color
selected-color#2dd4bf26markmarked code
special-color#ffflabelspecial standout words

Notes

Language-specific styling

To apply language-specific tweaks, use the language attribute, as in:

[language="html"] {
  --glow-accent-color: green;
}

Adjusting formatting

Glow uses bolding with --glow-special-color, and other elements are styled by color alone. You can add formatting to any elements to fine-tune the syntax blocks. For example:

/* Bold all secondary syntax elements */
pre em {
  font-weight: bold;
}