You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
markup/highlight: Allow overriding type and code via options
Treat type and code as highlighting options in both transform.Highlight
and transform.HighlightCodeBlock. The type option overrides the language
and code overrides the code, so the two functions now share the same
options handling.
transform.Highlight's LANG argument is now optional:
transform.Highlight CODE [LANG] [OPTIONS]
Fixes#11872
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The `transform.Highlight` function uses the [`alecthomas/chroma`][] package to generate syntax-highlighted HTML from the provided code, [language][], and [options][].
15
15
16
16
## Arguments
17
17
18
-
The `transform.Highlight` function takes three arguments.
19
-
20
18
CODE
21
19
: (`string`) The code to highlight.
22
20
23
21
LANG
24
-
: (`string`) The [language][] of the code to highlight. This value is case-insensitive.
22
+
: (`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" />}}
25
23
26
24
OPTIONS
27
-
: (`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.
25
+
: (`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. In addition to the [highlighting options](#options-1), the `type` and `code` keys override the `LANG` and `CODE` arguments respectively. {{< new-in "0.162.0" />}}
Copy file name to clipboardExpand all lines: docs/content/en/functions/transform/HighlightCodeBlock.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,4 +33,15 @@ To override the default [highlighting options]:
33
33
{{ $result.Wrapped }}
34
34
```
35
35
36
+
The `type` and `code` keys are special: they override the language and the code received from the code block respectively. {{< new-in "0.162.0" />}} For example, to fall back to plain text when the language is not supported by the highlighter:
0 commit comments