# `RichText`

A structured document: its blocks in order, as Portable Text holds one, each a paragraph, a heading, a quote or a list item, with nothing nested; `markup.rich_to_html` writes it as `Html`.

[Text formats](types.md#text-formats); not ordered; since Jadpo 0.1.0.

## Make one

It is a list of `RichTextBlock`: build one from a list of them, as you build a named list type of your own.

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an array of its items.

| JSON |
|---|
| `[{"tag":"heading","level":2,"spans":[{"text":"Soups","marks":[]}]},{"tag":"paragraph","spans":[{"text":"Made ","marks":[]},{"text":"daily","marks":["strong"]}]}]` |
| `[{"tag":"bullet_item","level":1,"spans":[{"text":"Leek","marks":[]}]},{"tag":"bullet_item","level":1,"spans":[{"text":"Tomato","marks":[]}]}]` |
| `[]` |

It is stored in one column named for the field, of type `jsonb`. `[{"tag":"bullet_item","level":1,"spans":[{"text":"Leek","marks":[]}]},{"tag":"bullet_item","level":1,"spans":[{"text":"Tomato","marks":[]}]}]` is stored as `'[{"tag":"bullet_item","level":1,"spans":[{"text":"Leek","marks":[]}]},{"tag":"bullet_item","level":1,"spans":[{"text":"Tomato","marks":[]}]}]'::jsonb`.

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `[{"tag":"heading","level":2,"spans":[{"text":"Soups","marks":[]}]},{"tag":"paragraph","spans":[{"text":"Made ","marks":[]},{"text":"daily","marks":["strong"]}]}]` | `"Soups\nMade daily"` |
| `[{"tag":"bullet_item","level":1,"spans":[{"text":"Leek","marks":[]}]},{"tag":"bullet_item","level":1,"spans":[{"text":"Tomato","marks":[]}]}]` | `"Leek\nTomato"` |
| `[]` | `""` |

## Operations

- `markup.rich_to_html(rich: RichText) -> Html`: `rich` written as HTML, each block its element and each mark its element inside its link, then made safe as every `Html` is, which changes nothing: a `RichText` holds only what the sanitiser keeps.

Like every standard type, it also has the contract's own operations: `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
