Hugo Syntax Highlighting

Table of Contents

You can have code snippets highlighted so that they are easier to read on your site using Chroma, Hugo’s default syntax highlighter. It is built in Go lang and is really, really fast – and for the most important parts compatible with Pygments. Chroma takes source code and other structured text and converts it into syntax highlighted HTML, ANSI-coloured text, etc.

The example below shows a simple HTML code snippet highlighted with the Hugo highlight built-in shortcode:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example HTML5 Document</title>
</head>
<body>
  <p>Test</p>
</body>
</html>

The following code snippet was used to achieve that result:

{{< highlight html >}}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example HTML5 Document</title>
</head>
<body>
  <p>Test</p>
</body>
</html>
{{< /highlight >}}

For more information, see “Hugo Syntax Highlighting” from official Hugo docs.

行叔 avatar
行叔
我是一位敏捷教练,业余的Python开发者。更多文章,可以访问 https://www.agilewalker.com