@mocanvas/editor · function

richTextToPlainText

declare function richTextToPlainText(doc: unknown, unknownNodeTypes?: Set<string>): string

Flatten a rich-text document to the plain string mocanvas stores in props.text.

The document is a tree of { type, content?, text? } nodes. text nodes contribute their string, hardBreak nodes a newline, top-level paragraphs are joined by newlines, and any other node is recursed into so unknown marks or wrappers still yield their text. unknownNodeTypes, when passed, collects the node types that were not understood.

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.