{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/transform/transform.go#L118-L154","documentation":"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.","triggerScenarios":"Calling {{ transform.Highlight .Code \"go\" \"lineNos=table\" \"extra\" }} with a third variadic argument.","commonSituations":"Adding an extra options argument by mistake; refactoring a call and leaving a stray argument; confusing Highlight with HighlightCodeBlock which takes a context object.","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\") }}."],"exampleFix":"// before\n{{ transform.Highlight .Code \"go\" \"lineNos=table\" \"extra\" }}\n// after\n{{ transform.Highlight .Code \"go\" (dict \"lineNos\" \"table\") }}","handlingStrategy":"validation","validationCode":"{{ transform.Highlight .Code \"go\" (dict \"lineNos\" \"table\") }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Highlight takes at most code + lang + options (3 total).","Merge multiple options into one map."],"tags":["template-function","transform","highlight","arity","argument"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}