Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
12345678910111213141516171819202122232425import { RenderYJSFragment } from "components/Blocks/TextBlock/RenderYJSFragment";
// A footnote's content (its block/text yjs value) rendered to the HTML that// travels in a ref's data-footnote-def attribute — the same shape external// markdown footnotes are normalized to, from which the paste builder mints a// fresh footnote entity (see htmlToBlocks). A ref must never travel as a bare// entity id: the pasted footnote node would alias the source block's entity,// and deleting the pasted ref would delete the original's content.export async function renderFootnoteDefHTML(value: string): Promise<string> { const { renderToStaticMarkup } = await import("react-dom/server"); const html = renderToStaticMarkup( <RenderYJSFragment value={value} wrapper="p" renderComments={false} />, ); // A footnote referenced from inside another footnote's definition can't be // represented (matching normalizePastedHTML), and leaving its id-carrying // markup in the definition would reintroduce the aliasing this exists to // prevent. if (!html.includes("footnote-ref")) return html; const container = document.createElement("div"); container.innerHTML = html; for (const ref of Array.from(container.querySelectorAll("span.footnote-ref"))) ref.remove(); return container.innerHTML;}