Files
2026-07-13 11:58:46 +08:00

2.0 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

CODE
(string) The code to highlight.
LANG
(string) The language of the code to highlight. This value is case-insensitive. Optional; you can also set the language with the type key in OPTIONS. {{< new-in 0.162.0 />}}
OPTIONS
(map or string) A map or comma-separated key-value pairs wrapped in quotation marks. See the options below; 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 }}

{{ $input := `print("Hello World!")` }}
{{ $opts := dict "type" "python" "style" "dracula" }}
{{ transform.Highlight $input $opts }}

Options

The transform.Highlight function accepts an options map.

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

code
{{< new-in 0.162.0 />}}
(string) Overrides the CODE argument.
type
{{< new-in 0.162.0 />}}
(string) Overrides the LANG argument.