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

  1. Quote the attribute values, e.g. ```go {lineNos="true"} .
  2. Verify attribute names are valid (identifiers) and values are quoted strings or booleans.
  3. If the '{' is literal (not attributes), move it into the code body or remove it from the info string.
  4. 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

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

Related errors


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)