@mocanvas/mocanvas · function

renderRichTextFromHTML

declare function renderRichTextFromHTML(_editor: Editor, html: string): RichText

Parse HTML into a rich-text document.

The inverse of renderHtmlFromRichText, and the path a paste from a browser or a word processor takes. Unknown elements are *descended into* rather than dropped, so text inside a <section> or a <font> survives even though the wrapper does not; unknown attributes are ignored entirely, which is what keeps a paste from carrying a stylesheet onto the canvas.

Returns a one-empty-paragraph document when there is nothing to parse, so the result is always a valid document with a caret line.

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.