Files
hugo/docs/content/en/functions/transform/Highlight.md
T
2026-05-21 12:22:49 +02:00

1.5 KiB

title, description, categories, keywords, params, aliases
title description categories keywords params aliases
transform.Highlight Renders code with a syntax highlighter.
highlight
functions_and_methods
aliases returnType signatures
highlight
template.HTML
transform.Highlight CODE LANG [OPTIONS]
/functions/highlight

The transform.Highlight function uses the alecthomas/chroma package to generate syntax-highlighted HTML from the provided code, language, and options.

Arguments

The transform.Highlight function takes three arguments.

CODE
(string) The code to highlight.
LANG
(string) The language of the code to highlight. This value is case-insensitive.
OPTIONS
(map or string) A map or comma-separated key-value pairs wrapped in quotation marks. You can set default values for each option in your project configuration. The key names are case-insensitive.

Examples

{{ $input := `fmt.Println("Hello World!")` }}
{{ transform.Highlight $input "go" }}

{{ $input := `console.log('Hello World!');` }}
{{ $lang := "js" }}
{{ transform.Highlight $input $lang "lineNos=table, style=api" }}

{{ $input := `echo "Hello World!"` }}
{{ $lang := "bash" }}
{{ $opts := dict "lineNos" "table" "style" "dracula" }}
{{ transform.Highlight $input $lang $opts }}

Options

{{% include "_common/syntax-highlighting-options.md" %}}