siyuan-note/siyuan · error

invalid encoded style entity in attribute view rich text…

Error message

invalid encoded style entity in attribute view rich text mark [%s]

What it means

While restoring HTML style entities that were replaced with sentinel tokens during attribute view rich text sanitization, the walker found a sentinel inside a text mark's content (or inline math content) whose mark type is neither 'code' nor 'inline-math'. Only those mark types are allowed to carry protected entity tokens in their text, so any other mark type containing a sentinel means the rich text payload was hand-crafted or corrupted. The library aborts normalization to prevent style-attribute injection via crafted entity tokens.

Solutions

  1. Remove the raw HTML entity from the text of the offending text mark, or wrap that text in a code (inline code) or inline-math mark where entity tokens are permitted
  2. Re-generate the rich text content through the editor (Protyle DOM -> Kramdown) instead of hand-assembling the Kramdown string
  3. Escape entities in the way the exporter expects (e.g. use literal characters instead of &#...; sequences) and retry the update
  4. Restore the affected row/value from history or backup if the payload was corrupted by an external write

Example fix

// before: entity inside a bold mark
{"type":"strong","text":"a & b"}
// after: entity only in an inline code mark
{"type":"code","text":"a & b"}
Defensive patterns

Strategy: validation

Validate before calling

// strip HTML entities from text of non-code/non-inline-math marks before submit
if (/[&][a-zA-Z]+;|&#\d+;/.test(markText) && !["code","inline-math"].includes(markType)) {
  throw new Error("entity not allowed in mark type " + markType);
}

Try / catch

try { await setCellValue(rich) } catch (e) { if (String(e.msg).includes("invalid encoded style entity")) { regenerateViaEditorRoundTrip(); } }

Prevention

When it happens

Trigger: Calling NormalizeValueTextRich / NormalizeRichContent (directly or via AV value save/update APIs, e.g. setting a database text cell) with rich text content where an HTML entity such as { or & in the content of a non-code/non-inline-math text mark was converted to a protection sentinel during parsing but appears in a disallowed position, e.g. inside a 'strong', 'em', 'a', or 'tag' text mark's text.

Common situations: Programmatically building or post-processing attribute view rich text (plugins, scripts, imports) and inserting raw HTML entities into mark text; editing the .av JSON by hand; corrupted rows after partial sync or a buggy external tool.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/8c32aaa3d739ed33. Report an issue: GitHub.

Appendix: source

Thrown at kernel/av/value.go:1974

			if !node.IsTextMarkType("text") {
				err = fmt.Errorf("encoded style entity is not attached to an attribute view rich text span")
				return ast.WalkStop
			}
			if textProtected || inlineMathProtected || tokensProtected ||
				!markValueTextRichStyleProtections(style, sentinel, tokenIndexes, restored) {
				err = fmt.Errorf("invalid encoded style entity in attribute view rich text span")
				return ast.WalkStop
			}
			style = styleReplacer.Replace(style)
			node.SetIALAttr("style", style)
			if nil != node.Next && ast.NodeKramdownSpanIAL == node.Next.Type {
				node.Next.Tokens = parse.IAL2Tokens(node.KramdownIAL)
			}
			return ast.WalkContinue
		}
		if textProtected || inlineMathProtected {
			if !node.IsTextMarkType("code") && !node.IsTextMarkType("inline-math") {
				err = fmt.Errorf("invalid encoded style entity in attribute view rich text mark [%s]", node.TextMarkType)
				return ast.WalkStop
			}
			if tokensProtected || textProtected &&
				!markValueTextRichStyleProtections(node.TextMarkTextContent, sentinel, tokenIndexes, restored) ||
				inlineMathProtected &&
					!markValueTextRichStyleProtections(node.TextMarkInlineMathContent, sentinel, tokenIndexes, restored) {
				err = fmt.Errorf("invalid encoded style entity in attribute view rich text mark [%s]", node.TextMarkType)
				return ast.WalkStop
			}
			node.TextMarkTextContent = textMarkCodeReplacer.Replace(node.TextMarkTextContent)
			node.TextMarkInlineMathContent = textMarkInlineMathReplacer.Replace(node.TextMarkInlineMathContent)
			return ast.WalkContinue
		}
		if !tokensProtected {
			return ast.WalkContinue
		}
		switch node.Type {
		case ast.NodeCodeBlockCode, ast.NodeMathBlockContent, ast.NodeCodeSpanContent, ast.NodeInlineMathContent:

View on GitHub (pinned to 9f775e8a12)