@mocanvas/mocanvas · function

richTextToHtml

declare function richTextToHtml(source: RichTextSource, options?: RichTextHtmlOptions): string

Serialize a rich-text document to HTML.

The output is generated here from a known set of node and mark types — text is escaped, link hrefs are scheme-checked — so it is safe to hand to innerHTML. Unknown node types are recursed into rather than dropped, so their text survives even when their formatting cannot.

No whitespace is emitted between tags: the measuring probe renders the result with white-space: pre-wrap, where an indenting newline would measure as a space.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.