import { Mark, Paragraph, RichTextBlock, RichTextNode } from '@shared/kernel/rich-text'; /** * The quarantined boundary between the imperative `contenteditable` DOM and the * serialisable `RichTextBlock` value. Pure functions (given a DOM they render / * read) so they round-trip losslessly and can be unit-tested without Angular. The * rest of the app only ever sees `RichTextBlock` — this is the one place DOM leaks. * * ponytail: mark detection covers the tags/styles a browser's execCommand emits * (strong/b, em/i, u, and inline font-weight/style/decoration); exotic pasted markup * degrades to plain text rather than crashing. */ const ORDER: readonly Mark[] = ['bold', 'italic', 'underline']; const MARK_TAG: Record = { bold: 'strong', italic: 'em', underline: 'u' }; export function renderInto( root: HTMLElement, block: RichTextBlock, labelFor: (key: string) => string, autoFor?: (key: string) => boolean, ): void { const doc = root.ownerDocument; root.replaceChildren(); const paras = block.paragraphs; let i = 0; while (i < paras.length) { const para = paras[i]; if (para.list) { // Group consecutive lines of the same list kind into one