{"id":"23b879f64ecbd828","repo":"gohugoio/hugo","slug":"transform-highlight-expects-at-most-3-arguments","errorCode":null,"errorMessage":"transform.Highlight: expects at most 3 arguments","messagePattern":"transform\\.Highlight: expects at most 3 arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/transform/transform.go","lineNumber":136,"sourceCode":"\t\t\topts = args[0]\n\t\t} else {\n\t\t\tvar arg string\n\t\t\tif arg, err = cast.ToStringE(args[0]); err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\tif strings.Contains(arg, \"=\") || strings.Contains(arg, \",\") {\n\t\t\t\topts = arg\n\t\t\t} else {\n\t\t\t\tlang = arg\n\t\t\t}\n\t\t}\n\tcase 2:\n\t\tif lang, err = cast.ToStringE(args[0]); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\topts = args[1]\n\tdefault:\n\t\treturn \"\", errors.New(\"transform.Highlight: expects at most 3 arguments\")\n\t}\n\n\thl := ns.deps.ContentSpec.Converters.GetHighlighter()\n\thighlighted, err := hl.Highlight(code, lang, opts)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn template.HTML(highlighted), nil\n}\n\n// HighlightCodeBlock highlights a code block on the form received in the codeblock render hooks.\nfunc (ns *Namespace) HighlightCodeBlock(ctx hooks.CodeblockContext, opts ...any) (highlight.HighlightResult, error) {\n\tvar optsv any\n\tif len(opts) > 0 {\n\t\toptsv = opts[0]\n\t}\n\n\thl := ns.deps.ContentSpec.Converters.GetHighlighter()","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/transform/transform.go#L118-L154","documentation":"`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.","triggerScenarios":"Calling `{{ highlight $code \"go\" \"linenos=true\" \"style=monokai\" }}` — i.e. passing language plus more than one options argument, or any call with 4+ arguments.","commonSituations":"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.","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."],"exampleFix":"<!-- before -->\n{{ highlight $code \"go\" \"linenos=true\" \"style=monokai\" }}\n<!-- after -->\n{{ highlight $code \"go\" \"linenos=true,style=monokai\" }}","handlingStrategy":"validation","validationCode":"{{/* highlight takes code, lang, and at most one options argument */}}\n{{ $opts := \"linenos=table,hl_lines=1-3\" }}\n{{ highlight $code \"go\" $opts }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hugo","templates","transform","highlight","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}