Skip to content

richTextToPlainText

richTextToPlainText(props): string

Defined in: packages/core/src/fields/richtext/utils.ts:50

Flattens a richtext document to a plain-text excerpt.

Joins every top-level node’s own text (via nodeToPlainText, which concatenates inline children with no separator) with a single space between nodes — the document’s blocks — then trims the result and truncates to maxLength with a trailing "…" when the text is longer. Used by the admin data table cell (never renders markup) and by richTextFieldToInputSchema’s required check (a document whose only content is empty paragraphs has an empty plain-text excerpt).

Input props.

RichTextDocument

The richtext document to flatten.

number

When set, the excerpt is truncated to this many characters (trailing whitespace trimmed first) with a "…" appended. Omitted → the full excerpt is returned.

string

The plain-text excerpt, or "" for an empty document.

richTextToPlainText({
document: [{ type: "p", children: [{ text: "Hello world" }] }],
}) // "Hello world"
richTextToPlainText({
document: [{ type: "p", children: [{ text: "Hello world" }] }],
maxLength: 8,
}) // "Hello wo…"