gohugoio/hugo · error
transform.Highlight: expects at most 3 arguments
Error message
transform.Highlight: expects at most 3 arguments
What it means
Thrown by transform.Highlight when more than two variadic arguments (i.e. more than three total including the code) are passed (tpl/transform/transform.go:135-136, default case). Highlight accepts the code plus an optional LANG and/or OPTIONS.
Solutions
- Limit to at most three total arguments: code, lang, options.
- Combine multiple options into a single options map or string: {{ transform.Highlight .Code "go" (dict "lineNos" "table" "style" "mono") }}.
Example fix
// before
{{ transform.Highlight .Code "go" "lineNos=table" "extra" }}
// after
{{ transform.Highlight .Code "go" (dict "lineNos" "table") }} Defensive patterns
Strategy: validation
Validate before calling
{{ transform.Highlight .Code "go" (dict "lineNos" "table") }} Prevention
- Highlight takes at most code + lang + options (3 total).
- Merge multiple options into one map.
When it happens
Trigger: Calling {{ transform.Highlight .Code "go" "lineNos=table" "extra" }} with a third variadic argument.
Common situations: Adding an extra options argument by mistake; refactoring a call and leaving a stray argument; confusing Highlight with HighlightCodeBlock which takes a context object.
Related errors
- must provide at least one argument
- unmarshal takes 1 or 2 arguments
- failed to detect target data serialization format
- first argument must be a map
- invalid arguments supplied to `time`
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/23b879f64ecbd828.
Report an issue: GitHub.
Appendix: 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 52c9bd7908)