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).
Parameters
Section titled “Parameters”Input props.
document
Section titled “document”The richtext document to flatten.
maxLength?
Section titled “maxLength?”number
When set, the excerpt is truncated to this many
characters (trailing whitespace trimmed first) with a "…" appended.
Omitted → the full excerpt is returned.
Returns
Section titled “Returns”string
The plain-text excerpt, or "" for an empty document.
Example
Section titled “Example”richTextToPlainText({ document: [{ type: "p", children: [{ text: "Hello world" }] }],}) // "Hello world"
richTextToPlainText({ document: [{ type: "p", children: [{ text: "Hello world" }] }], maxLength: 8,}) // "Hello wo…"