{"id":"2e0c3f744cf28696","repo":"gohugoio/hugo","slug":"failed-to-parse-markdown-attributes-you-may-need","errorCode":null,"errorMessage":"failed to parse Markdown attributes; you may need to quote the values","messagePattern":"failed to parse Markdown attributes; you may need to quote the values","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"markup/goldmark/codeblocks/render.go","lineNumber":166,"sourceCode":"\t\t\tif attrEndIdx == -1 && char == '{' {\n\t\t\t\tattrStartIdx = idx\n\t\t\t}\n\t\t\tif attrStartIdx != -1 && char == '}' {\n\t\t\t\tattrEndIdx = idx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif attrStartIdx != -1 && attrEndIdx != -1 {\n\t\t\tn := ast.NewTextBlock() // dummy node for storing attributes\n\t\t\tattrStr := infostr[attrStartIdx : attrEndIdx+1]\n\t\t\tif attrs, hasAttr := parser.ParseAttributes(text.NewReader(attrStr)); hasAttr {\n\t\t\t\tfor _, attr := range attrs {\n\t\t\t\t\tn.SetAttribute(attr.Name, attr.Value)\n\t\t\t\t}\n\t\t\t\treturn n.Attributes(), \"\", nil\n\t\t\t} else {\n\t\t\t\treturn nil, string(attrStr), errors.New(\"failed to parse Markdown attributes; you may need to quote the values\")\n\t\t\t}\n\t\t}\n\t}\n\treturn nil, \"\", nil\n}\n","sourceCodeStart":148,"sourceCodeEnd":172,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/markup/goldmark/codeblocks/render.go#L148-L172","documentation":"Hugo's Goldmark code-block renderer found a `{...}` attribute block in a fenced code block's info string but Goldmark's `parser.ParseAttributes` failed to parse it. Hugo supports Markdown attributes on code fences (e.g. ```` ```go {linenos=true} ````), and this error surfaces when the attribute syntax inside the braces is malformed — commonly unquoted values containing spaces or special characters.","triggerScenarios":"Rendering a fenced code block whose info string contains `{` and `}` with content that fails Goldmark attribute parsing — e.g. ```` ```bash {style=monokai theme} ```` or values with spaces/commas/special chars not wrapped in quotes. Requires `markup.goldmark.parser.attribute.block` or code-fence attribute handling to reach codeblocks/render.go:166 via `getAttributes`.","commonSituations":"Adding highlight options like `{linenos=table,hl_lines=1-3}` with a typo, using unquoted string values containing spaces (`{title=My File}`), copying attribute snippets from other SSGs with incompatible syntax, or curly braces in the info string that aren't meant as attributes.","solutions":["Quote attribute values: change `{title=My File}` to `{title=\"My File\"}`.","Check attribute syntax matches Hugo docs: comma- or space-separated key=value pairs inside a single `{...}` block, e.g. `{linenos=inline, hl_lines=[2,3]}`.","If the braces are part of the language/info text and not attributes, remove or escape them from the info string.","Run `hugo` with `-v` to identify the offending file, then fix that code fence."],"exampleFix":"```go {title=my file, linenos=true}   <!-- before: unquoted value with space -->\n```go {title=\"my file\", linenos=true} <!-- after -->","handlingStrategy":"validation","validationCode":"// Lint fences before build: quote attribute values containing spaces/commas\n// ```go {linenos=true, style=\"monokai\"} — quote anything non-alphanumeric\nre := regexp.MustCompile(\"^```\\\\w+\\\\s*\\\\{(.*)\\\\}\")\n// verify each attr parses as key=value with quoted strings for complex values","typeGuard":null,"tryCatchPattern":"if err := hugolib.Build(...); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse Markdown attributes\") {\n        // report offending file/line from the wrapped error; fix the fence, don't retry\n    }\n}","preventionTips":["Quote code-fence attribute values that contain spaces, commas, or special characters","Keep attribute lists in the documented `{key=value, key2=\"v 2\"}` form","Add a CI markdown-lint step that scans fences for unquoted complex values"],"tags":["hugo","goldmark","markdown","code-fence","attributes"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}