siyuan-note/siyuan · error

attribute view rich text style entity was not restored

Error message

attribute view rich text style entity was not restored

What it means

After walking the tree and replacing all sentinel tokens, the sanitizer checked its 'restored' flags and found at least one recorded protection whose token never appeared anywhere in the parsed tree. The content claims to contain a protected HTML entity (the protection list was built) but the corresponding token vanished during parsing, so restoration is incomplete and the library refuses to proceed.

Solutions

  1. Inspect the rich text source for entities inside constructs that the parser discards (comments, unknown tags) and move the entity into valid inline content
  2. Rebuild the content via the editor round-trip so tokens are regenerated in parseable positions
  3. Upgrade/verify the kernel version used to write the payload matches the one reading it
  4. Restore the affected value from history or backup

Example fix

// before: entity hidden in a dropped construct
<!-- a &amp; b -->
// after: entity in normal text
"a &amp; b"
Defensive patterns

Strategy: validation

Validate before calling

// avoid entities inside constructs the parser drops (comments, unknown tags)
if (/<!--[\s\S]*?&[a-zA-Z#0-9]+;[\s\S]*?-->/.test(content)) {
  throw new Error("HTML entity inside a comment will not survive parsing");
}

Try / catch

try { NormalizeRichContent() } catch (e) { if (String(e).includes("was not restored")) { rebuildContentFromPlainText(); } }

Prevention

When it happens

Trigger: Parsing AV rich text where Lute's parser dropped or merged a token (e.g. the sentinel ended up in a position that is discarded during parsing, such as inside an HTML comment or an invalid construct) so its token index is never marked restored.

Common situations: Content where an HTML entity sits inside a construct the parser drops (comments, invalid markup, escaped constructs); content produced by an incompatible writer version; regex edits that moved the token outside the tree.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at kernel/av/value.go:2009

		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 {
		if entering && valueTextRichNodeContainsSentinel(node, sentinel) {
			err = fmt.Errorf("attribute view rich text style entity sentinel was not removed from node [%s]",
				node.Type.String())
			return ast.WalkStop
		}
		return ast.WalkContinue
	})
	return
}

func valueTextRichNodeContainsSentinel(node *ast.Node, sentinel string) bool {
	values := []string{
		node.ID, node.Spec, node.Data, string(node.Tokens), string(node.CodeBlockOpenFence),
		string(node.CodeBlockInfo), string(node.CodeBlockCloseFence), string(node.LinkRefLabel),
		string(node.FootnotesRefLabel), node.FootnotesRefId, string(node.HtmlEntityTokens),

View on GitHub (pinned to 9f775e8a12)