siyuan-note/siyuan · error

Invalid attribute view rich text style entity

Error message

Invalid attribute view rich text style entity

What it means

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.

Solutions

  1. Re-open/re-render the document to rebuild the cell from source; if transient, it will clear
  2. Fix or remove the offending av cell content that contains malformed HTML entities
  3. Check the Lute version — upgrade/rebuild lute if a protection restore bug is suspected
  4. Report the document/cell content if reproducible, since it indicates format corruption

Example fix

// before
parseAVRichTextKramdown(userEditedMarkdown);
// after
try { parseAVRichTextKramdown(userEditedMarkdown); } catch (e) { cell.resetToStoredValue(); }
Defensive patterns

Strategy: try-catch

Validate before calling

const balanced = (md: string) => !/&(?!;)|&&(?![a-zA-Z]+;)/.test(md); // reject malformed entities before parse

Try / catch

try { dom = parseAVRichTextKramdown(md); } catch (e) { fallBackToPlainText(md); logCorruptedCell(blockId); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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

Appendix: source

Thrown at app/src/protyle/render/av/richText.ts:301

            if (node.nodeType === Node.TEXT_NODE) {
                node.nodeValue = replaceProtections(node.nodeValue || "", false, restored);
                return;
            }
            node.childNodes.forEach(visit);
        };
        visit(element);
    };
    template.content.querySelectorAll('[data-type="NodeCodeBlock"], span[data-type~="code"]')
        .forEach(restoreLiteralText);
    template.content.querySelectorAll<HTMLElement>(
        '[data-type="NodeMathBlock"][data-content], [data-type="NodeMathBlock"] [data-content], ' +
        'span[data-type~="inline-math"][data-content]'
    ).forEach((element) => {
        element.setAttribute("data-content",
            replaceProtections(element.getAttribute("data-content") || "", false, restored));
    });
    if (protections.some((protection) => !restored.has(protection.token))) {
        throw new Error("Invalid attribute view rich text style entity");
    }
    return (template.innerHTML || "").trim();
};

const parseAVRichTextKramdown = (markdown: string, lute = getAVRichTextLute()) => {
    const protectedStyle = protectAVRichTextKramdownStyleEntities(markdown);
    return restoreAVRichTextBlockDOMStyleEntities(lute.Md2BlockDOM(protectedStyle.content),
        protectedStyle.protections);
};

const getAVRichTextPlainContent = (blockDOM: string, lute: Lute) => {
    const template = document.createElement("template");
    template.innerHTML = blockDOM;
    const blocks = Array.from(template.content.querySelectorAll<HTMLElement>(
        '[data-type="NodeParagraph"], [data-type="NodeHeading"], [data-type="NodeCodeBlock"], ' +
        '[data-type="NodeMathBlock"]'
    )).map((element) => lute.BlockDOM2Content(element.outerHTML));
    return projectAVRichTextPlainBlocks(blocks, lute.BlockDOM2Content(blockDOM));

View on GitHub (pinned to 9f775e8a12)