gohugoio/hugo · error
failed to parse Markdown attributes; you may need to quote…
Error message
failed to parse Markdown attributes; you may need to quote the values
What it means
Returned by getAttributes in markup/goldmark/codeblocks/render.go:166 when a fenced code block's info string contains a {...} attribute block that Hugo's attribute parser (parser.ParseAttributes) rejects. The hint suggests quoting values, the most common cause.
Solutions
- Quote the attribute values, e.g. ```go {lineNos="true"} .
- Verify attribute names are valid (identifiers) and values are quoted strings or booleans.
- If the '{' is literal (not attributes), move it into the code body or remove it from the info string.
- Reproduce with a minimal fence to confirm which attribute breaks parsing.
Example fix
// before
```go {lineNos=true opt=un quoted}
// after
```go {lineNos="true" opt="quoted"} Defensive patterns
Strategy: validation
Validate before calling
// Quote code-fence attribute values; validate before relying on them.
// Prefer: ```go {lineNos="true"} Prevention
- Always quote attribute values in code-fence info strings.
- Avoid stray '{' in the info string after the language.
- Reproduce with a minimal fence to isolate the bad attribute.
When it happens
Trigger: Authoring a fenced code block with attribute syntax whose values are unquoted/problematic, e.g. ```go {lineNo=.} or ```bash {id=a b} (space breaks parsing). getAttributes runs during Goldmark code-block rendering.
Common situations: Adding Hugo code-block attributes (line numbers, IDs, options) and forgetting quotes around a value, using an unsupported attribute syntax, or a stray '{' in the info string that looks like attributes.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- goldmark
- project config…
- project config markup.goldmark.renderHooks.link.useEmbedded…
- shortcode has no name
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/2e0c3f744cf28696.
Report an issue: GitHub.
Appendix: 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 52c9bd7908)