jsonToText
Function Stability: stable
The plain text of a document: what a person typed, without markup. Takes a serialize('json') export, or its blocks
array, and is what serialize('text') computes, so the browser and a server working from the same JSON get the identical string.
Related guide: A read-only viewer →
The rule:
- A block's text is its characters as typed: no escaping, no markup, marks and links ignored, a line break inside the block
kept as
\n. Nothing is trimmed. - Blocks are separated by a blank line (
\n\n). The items of a list and their nested items are separated by a single\n, with no bullet or number. - A block without text (divider, image, video, file) and an empty block contribute nothing, so no blank lines pile up.
- A container (toggle, callout, region...) gives its own text (a region: its title), then its children's, in order.
- It reads the
contentof any block, so a block from an extension is covered without registering anything.
To keep proof of what a person wrote, store the string you received: do not recompute it later with a newer version of the library.
Signature
TypeScript
import { jsonToText } from '@aionbuilders/nabu/format';TypeScript
function jsonToText(json: any[] | { blocks?: any[] }): stringParameters
| Parameter | Type | Description |
|---|---|---|
json | any[] | { blocks?: any[] } | a |
Returns
string
Source: src/lib/format.js:58