gohugoio/hugo · error
failed to parse Markdown attributes; you may need to quote t
Error message
failed to parse Markdown attributes; you may need to quote the values
What it means
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.
Source
Thrown at markup/goldmark/codeblocks/render.go:166
if attrEndIdx == -1 && char == '{' {
attrStartIdx = idx
}
if attrStartIdx != -1 && char == '}' {
attrEndIdx = idx
break
}
}
if attrStartIdx != -1 && attrEndIdx != -1 {
n := ast.NewTextBlock() // dummy node for storing attributes
attrStr := infostr[attrStartIdx : attrEndIdx+1]
if attrs, hasAttr := parser.ParseAttributes(text.NewReader(attrStr)); hasAttr {
for _, attr := range attrs {
n.SetAttribute(attr.Name, attr.Value)
}
return n.Attributes(), "", nil
} else {
return nil, string(attrStr), errors.New("failed to parse Markdown attributes; you may need to quote the values")
}
}
}
return nil, "", nil
}
View on GitHub ↗ (pinned to 8a468df065)
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.
Example fix
```go {title=my file, linenos=true} <!-- before: unquoted value with space -->
```go {title="my file", linenos=true} <!-- after --> Defensive patterns
Strategy: validation
Validate before calling
// Lint fences before build: quote attribute values containing spaces/commas
// ```go {linenos=true, style="monokai"} — quote anything non-alphanumeric
re := regexp.MustCompile("^```\\w+\\s*\\{(.*)\\}")
// verify each attr parses as key=value with quoted strings for complex values Try / catch
if err := hugolib.Build(...); err != nil {
if strings.Contains(err.Error(), "failed to parse Markdown attributes") {
// report offending file/line from the wrapped error; fix the fence, don't retry
}
} Prevention
- 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
When it happens
Trigger: 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`.
Common situations: 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.
Related errors
- project config markup.goldmark.renderHooks.image.useEmbedded
- project config markup.goldmark.renderHooks.link.useEmbedded
- goldmark: %s
- no code renderer found for %q
- unrecognized render hook template
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/2e0c3f744cf28696.json.
Report an issue: GitHub ↗.