siyuan-note/siyuan · error

invalid encoded style entity in attribute view rich text…

Error message

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

What it means

During sentinel restoration, a node whose raw Tokens contain the sentinel token failed markValueTextRichStyleProtections: the token inside a code block code, math block content, code span, or inline math content is malformed (bad index, missing suffix) or could not be matched against the recorded protections. The restoration is aborted because the entity cannot be safely restored.

Solutions

  1. Restore the original HTML entity in place of the broken token in the code/math content
  2. Re-create the cell value through the UI or API so the sanitizer runs end-to-end
  3. Verify the payload against a known-good copy of the row from history and re-submit it
  4. Check for tooling that does naive string replacement on Kramdown and fix it to preserve tokens intact

Example fix

// before: broken token in code span content
`\ue000siyuan-av-rich-text-style-entities-9` (index out of range)
// after: literal entity
` `
Defensive patterns

Strategy: validation

Validate before calling

// ensure code/math tokens contain only complete tokens or none
function hasCompleteTokens(s, sentinel) {
  let i = 0;
  while ((i = s.indexOf(sentinel, i)) !== -1) {
    if (s.indexOf("\ue002", i) === -1) return false;
    i += 1;
  }
  return true;
}

Try / catch

try { saveValue(v) } catch (e) { if (String(e).includes("rich text node")) { restoreFromHistory(v.blockId); } }

Prevention

When it happens

Trigger: Parsing AV rich text where a sentinel token embedded in NodeCodeBlockCode / NodeMathBlockContent / NodeCodeSpanContent / NodeInlineMathContent tokens was truncated or given an index that is not in the protection list (e.g. token 7 when only 5 entities exist).

Common situations: Hand-editing or diff-merging .av Kramdown content so tokens were cut mid-way; data written by a mismatched kernel version; corruption during copy of database rows between documents.

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/aeb4a0c256427138. Report an issue: GitHub.

Appendix: source

Thrown at kernel/av/value.go:1994

			}
			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:
			if !markValueTextRichStyleProtections(tokens, sentinel, tokenIndexes, restored) {
				err = fmt.Errorf("invalid encoded style entity in attribute view rich text node [%s]", node.Type.String())
				return ast.WalkStop
			}
			node.Tokens = []byte(literalReplacer.Replace(tokens))
		default:
			err = fmt.Errorf("invalid encoded style entity in attribute view rich text node [%s]", node.Type.String())
			return ast.WalkStop
		}
		return ast.WalkContinue
	})
	if nil != err {
		return
	}
	for _, found := range restored {
		if !found {
			return fmt.Errorf("attribute view rich text style entity was not restored")
		}
	}
	ast.Walk(tree.Root, func(node *ast.Node, entering bool) ast.WalkStatus {

View on GitHub (pinned to 9f775e8a12)