> ## Documentation Index
> Fetch the complete documentation index at: https://docs.frogbot.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Converting Plain Text

> Convert Lexical rich text into plain text.

## Rich Text to plain text

```ts theme={"theme":"tokyo-night"}
import type { SerializedEditorState } from '@frogbotai/richtext-lexical/lexical'
import { convertLexicalToPlaintext } from '@frogbotai/richtext-lexical/plaintext'

export function toPlainText(data: SerializedEditorState) {
  return convertLexicalToPlaintext({ data })
}
```

| Option | Type | Default | Description |
| - | - | - | - |
| `data` | `SerializedEditorState` | Required | The rich text value to convert. An empty editor state returns an empty string. |
| `converters` | `PlaintextConverters` | `{}` | Converters keyed by node type, with custom blocks under `blocks` and `inlineBlocks` keyed by slug. Each converter is a string or a function that receives the `node` and returns its text. Nodes without a converter follow the rules in [Custom converters](#custom-converters). |

## Custom converters

Add converters for custom blocks or override standard node handling:

```ts theme={"theme":"tokyo-night"}
import type {
  DefaultNodeTypes,
  SerializedBlockNode,
} from '@frogbotai/richtext-lexical'
import type { SerializedEditorState } from '@frogbotai/richtext-lexical/lexical'
import {
  convertLexicalToPlaintext,
  type PlaintextConverters,
} from '@frogbotai/richtext-lexical/plaintext'

type TextBlock = {
  blockName?: string
  blockType: 'text'
  text?: string
}

const converters: PlaintextConverters = {
  blocks: {
    text: ({ node }) => ('text' in node.fields ? node.fields.text ?? '' : ''),
  },
  link: ({ node }) => node.fields.url ?? '',
}

export function toPlainText(data: SerializedEditorState) {
  return convertLexicalToPlaintext({ converters, data })
}
```

Plain-text conversion has no default converter map. When a node has no converter, the converter applies these rules:

* A `text` property becomes plain text.
* `children` are converted recursively.
* Nodes with neither property are ignored.
* Paragraph, text, and tab nodes add their corresponding newline or tab characters.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.