# datocms-structured-text-to-plain-text

> Convert DatoCMS Structured Text field to plain text

Latest version **6.0.0** (published 2026-05-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install datocms-structured-text-to-plain-text
pnpm add datocms-structured-text-to-plain-text
yarn add datocms-structured-text-to-plain-text
bun add datocms-structured-text-to-plain-text
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2026-05-25 |
| First published | 2021-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 47.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Stefano Verna |
| Maintainers | marcelofinamorvieira, stefanoverna, delphaber, mat_jack1, souljuse, sistrall_, datoroger |
| Keywords | datocms, structured-text |

## Links

- npm: https://www.npmjs.com/package/datocms-structured-text-to-plain-text
- Repository: https://github.com/datocms/structured-text
- Homepage: https://github.com/datocms/structured-text/tree/master/packages/to-plain-text#readme
- Issues: https://github.com/datocms/structured-text/issues
- npm.io page: https://npm.io/package/datocms-structured-text-to-plain-text

## Dependencies (2)

- [datocms-structured-text-utils](https://npm.io/package/datocms-structured-text-utils.md) ^6.0.0
- [datocms-structured-text-generic-html-renderer](https://npm.io/package/datocms-structured-text-generic-html-renderer.md) ^6.0.0

## Recent versions

- 6.0.0 (latest) — 2026-05-25
- 4.1.0-alpha.0 (next) — 2025-01-17
- 5.1.16 — 2026-05-03
- 5.1.15 — 2026-04-28
- 5.1.14 — 2026-04-28
- 5.1.13 — 2026-04-28
- 5.1.11 — 2026-04-27
- 5.1.9 — 2026-04-24
- 5.1.7 — 2025-12-05
- 5.1.6 — 2025-10-01
- 5.1.5 — 2025-10-01
- 5.1.4 — 2025-09-21
- 5.1.3 — 2025-09-20
- 5.1.2 — 2025-09-19
- 5.1.1 — 2025-09-10
- … 50 more at https://npm.io/package/datocms-structured-text-to-plain-text/versions

## README

![Node.js CI](https://github.com/datocms/structured-text/workflows/Node.js%20CI/badge.svg)

# datocms-structured-text-to-plain-text

Plain text renderer for the Structured Text document.

## Installation

Using [npm](http://npmjs.org/):

```sh
npm install datocms-structured-text-to-plain-text
```

Using [yarn](https://yarnpkg.com/):

```sh
yarn add datocms-structured-text-to-plain-text
```

## Usage

```javascript
import { render } from 'datocms-structured-text-to-plain-text';

const structuredText = {
  value: {
    schema: 'dast',
    document: {
      type: 'root',
      children: [
        {
          type: 'heading',
          level: 1,
          children: [
            {
              type: 'span',
              value: 'This\nis a\ntitle!',
            },
          ],
        },
      ],
    },
  },
};

render(structuredText); // -> "This is a title!"
```

You can also pass custom renderers for `itemLink`, `inlineItem`, `block` as optional parameters like so:

```javascript
import { render } from 'datocms-structured-text-to-plain-text';

const graphqlResponse = {
  value: {
    schema: 'dast',
    document: {
      type: 'root',
      children: [
        {
          type: 'paragraph',
          children: [
            {
              type: 'span',
              value: 'A ',
            },
            {
              type: 'itemLink',
              item: '344312',
              children: [
                {
                  type: 'span',
                  value: 'record hyperlink',
                },
              ],
            },
            {
              type: 'span',
              value: ' and an inline record: ',
            },
            {
              type: 'inlineItem',
              item: '344312',
            },
          ],
        },
        {
          type: 'block',
          item: '812394',
        },
      ],
    },
  },
  blocks: [
    {
      id: '812394',
      image: { url: 'http://www.datocms-assets.com/1312/image.png' },
    },
  ],
  links: [{ id: '344312', title: 'Foo', slug: 'foo' }],
};

const options = {
  renderBlock({ record }) {
    return `[Image ${record.image.url}]`;
  },
  renderInlineRecord({ record, adapter: { renderNode } }) {
    return `[Inline ${record.slug}]${children}[/Inline]`;
  },
  renderLinkToRecord({ record, children, adapter: { renderNode } }) {
    return `[Link to ${record.slug}]${children}[/Link]`;
  },
};

render(document, options);
// -> A [Link to foo]record hyperlink[/Link] and an inline record: [Inline foo]Foo[/Inline]
//    [Image http://www.datocms-assets.com/1312/image.png]
```

---
_Source: https://npm.io/package/datocms-structured-text-to-plain-text · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
