2.0 KiB
2.0 KiB
title, description, categories, keywords, params, aliases
| title | description | categories | keywords | params | aliases | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| transform.Highlight | Renders code with a syntax highlighter. |
|
|
|
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 thetypekey 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 theCODEargument. type- {{< new-in 0.162.0 />}}
- (
string) Overrides theLANGargument.