gohugoio/hugo · error
transform.Highlight: expects at most 3 arguments
Error message
transform.Highlight: expects at most 3 arguments
What it means
`transform.Highlight` takes the code to highlight plus up to two more arguments: a language and an options string/map. Its variadic tail is limited to two extra values; when more than three total arguments are supplied, the switch falls into the default case and returns this error.
Source
Thrown at tpl/transform/transform.go:136
opts = args[0]
} else {
var arg string
if arg, err = cast.ToStringE(args[0]); err != nil {
return "", err
}
if strings.Contains(arg, "=") || strings.Contains(arg, ",") {
opts = arg
} else {
lang = arg
}
}
case 2:
if lang, err = cast.ToStringE(args[0]); err != nil {
return "", err
}
opts = args[1]
default:
return "", errors.New("transform.Highlight: expects at most 3 arguments")
}
hl := ns.deps.ContentSpec.Converters.GetHighlighter()
highlighted, err := hl.Highlight(code, lang, opts)
if err != nil {
return "", err
}
return template.HTML(highlighted), nil
}
// HighlightCodeBlock highlights a code block on the form received in the codeblock render hooks.
func (ns *Namespace) HighlightCodeBlock(ctx hooks.CodeblockContext, opts ...any) (highlight.HighlightResult, error) {
var optsv any
if len(opts) > 0 {
optsv = opts[0]
}
hl := ns.deps.ContentSpec.Converters.GetHighlighter()View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Combine options into a single argument: `{{ highlight $code "go" "linenos=true,style=monokai" }}`.
- Or pass a dict: `{{ highlight $code "go" (dict "lineNos" true "style" "monokai") }}`.
- Drop any extra positional arguments beyond code, lang, and one options value.
Example fix
<!-- before -->
{{ highlight $code "go" "linenos=true" "style=monokai" }}
<!-- after -->
{{ highlight $code "go" "linenos=true,style=monokai" }} Defensive patterns
Strategy: validation
Validate before calling
{{/* highlight takes code, lang, and at most one options argument */}}
{{ $opts := "linenos=table,hl_lines=1-3" }}
{{ highlight $code "go" $opts }} Prevention
- Pass transform.Highlight at most 3 args: code, language, options
- Combine multiple options into one string or dict — don't pass them as separate arguments
- Prefer configuring defaults in markup.highlight in hugo config so call sites stay to 2 args
When it happens
Trigger: Calling `{{ highlight $code "go" "linenos=true" "style=monokai" }}` — i.e. passing language plus more than one options argument, or any call with 4+ arguments.
Common situations: Splitting options into separate arguments instead of one comma-separated string or dict; porting shortcode-style `{{< highlight go "linenos=true" >}}` syntax into a template function call with extra positional args.
Related errors
- failed to detect format from content
- failed to detect target data serialization format
- need at least 2 arguments to append
- must provide a Resource and optionally an options map
- operator argument must be string type
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/23b879f64ecbd828.json.
Report an issue: GitHub ↗.