{"record":{"id":"1494329fd2449cda","repo":"siyuan-note/siyuan","slug":"invalid-attribute-view-rich-text-style-entity","errorCode":null,"errorMessage":"Invalid attribute view rich text style entity","messagePattern":"Invalid attribute view rich text style entity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/protyle/render/av/richText.ts","lineNumber":301,"sourceCode":"            if (node.nodeType === Node.TEXT_NODE) {\n                node.nodeValue = replaceProtections(node.nodeValue || \"\", false, restored);\n                return;\n            }\n            node.childNodes.forEach(visit);\n        };\n        visit(element);\n    };\n    template.content.querySelectorAll('[data-type=\"NodeCodeBlock\"], span[data-type~=\"code\"]')\n        .forEach(restoreLiteralText);\n    template.content.querySelectorAll<HTMLElement>(\n        '[data-type=\"NodeMathBlock\"][data-content], [data-type=\"NodeMathBlock\"] [data-content], ' +\n        'span[data-type~=\"inline-math\"][data-content]'\n    ).forEach((element) => {\n        element.setAttribute(\"data-content\",\n            replaceProtections(element.getAttribute(\"data-content\") || \"\", false, restored));\n    });\n    if (protections.some((protection) => !restored.has(protection.token))) {\n        throw new Error(\"Invalid attribute view rich text style entity\");\n    }\n    return (template.innerHTML || \"\").trim();\n};\n\nconst parseAVRichTextKramdown = (markdown: string, lute = getAVRichTextLute()) => {\n    const protectedStyle = protectAVRichTextKramdownStyleEntities(markdown);\n    return restoreAVRichTextBlockDOMStyleEntities(lute.Md2BlockDOM(protectedStyle.content),\n        protectedStyle.protections);\n};\n\nconst getAVRichTextPlainContent = (blockDOM: string, lute: Lute) => {\n    const template = document.createElement(\"template\");\n    template.innerHTML = blockDOM;\n    const blocks = Array.from(template.content.querySelectorAll<HTMLElement>(\n        '[data-type=\"NodeParagraph\"], [data-type=\"NodeHeading\"], [data-type=\"NodeCodeBlock\"], ' +\n        '[data-type=\"NodeMathBlock\"]'\n    )).map((element) => lute.BlockDOM2Content(element.outerHTML));\n    return projectAVRichTextPlainBlocks(blocks, lute.BlockDOM2Content(blockDOM));","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/protyle/render/av/richText.ts#L283-L319","documentation":"When restoring protected style entities in an attribute-view rich-text block DOM, restoreAVRichTextBlockDOMStyleEntities tracks each protection token it must restore; if any token was never restored into the template HTML it throws this error, signaling corrupted or mismatched protected markup rather than silently dropping content.","triggerScenarios":"parseAVRichTextKramdown receives kramdown whose protected entities (HTML entities inside style attributes, inline-math data-content, etc.) don't round-trip — e.g. malformed or hand-edited av cell content, double-escaped entities, or content produced by a different/older Lute version.","commonSituations":"Manually editing .sy files or database cell content; syncing content written by an older/newer SiYuan or Lute version; paste of raw HTML into an av rich-text cell producing unknown escapes; a Lute protection-restore regression.","solutions":["Re-open/re-render the document to rebuild the cell from source; if transient, it will clear","Fix or remove the offending av cell content that contains malformed HTML entities","Check the Lute version — upgrade/rebuild lute if a protection restore bug is suspected","Report the document/cell content if reproducible, since it indicates format corruption"],"exampleFix":"// before\nparseAVRichTextKramdown(userEditedMarkdown);\n// after\ntry { parseAVRichTextKramdown(userEditedMarkdown); } catch (e) { cell.resetToStoredValue(); }","handlingStrategy":"try-catch","validationCode":"const balanced = (md: string) => !/&amp;(?!;)|&&(?![a-zA-Z]+;)/.test(md); // reject malformed entities before parse","typeGuard":null,"tryCatchPattern":"try { dom = parseAVRichTextKramdown(md); } catch (e) { fallBackToPlainText(md); logCorruptedCell(blockId); }","preventionTips":["Never hand-edit .sy or av cell HTML entity content","Keep Lute and SiYuan versions in sync across clients","Fall back to plain-text rendering when parsing protected entities fails"],"tags":["av","richtext","parsing","corruption"],"backgroundTag":"internal-invariant-violation","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}