# `RichTextBlock`

One block of a `RichText`: a heading's level is 1 to 6, a list item's 1 to 9, how deep it sits.

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

## Make one

Pick one of its variants and give its fields, `RichTextBlock.paragraph { spans: ... }`.

## Variants

| Variant | Fields |
|---|---|
| `paragraph` | `spans`: `List<`[`RichTextSpan`](type-rich-text-span.md)`>` |
| `heading` | `level`: `Int`, `spans`: `List<`[`RichTextSpan`](type-rich-text-span.md)`>` |
| `quote` | `spans`: `List<`[`RichTextSpan`](type-rich-text-span.md)`>` |
| `bullet_item` | `level`: `Int`, `spans`: `List<`[`RichTextSpan`](type-rich-text-span.md)`>` |
| `numbered_item` | `level`: `Int`, `spans`: `List<`[`RichTextSpan`](type-rich-text-span.md)`>` |

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an object of its variant's name, as `tag`, and the variant's fields.

| JSON |
|---|
| `{"tag":"paragraph","spans":[{"text":"Fresh ","marks":[]},{"text":"soup","marks":["emphasis"]}]}` |
| `{"tag":"heading","level":1,"spans":[{"text":"Soups","marks":[]}]}` |
| `{"tag":"quote","spans":[{"text":"Fresh every day","marks":[]}]}` |
| `{"tag":"numbered_item","level":2,"spans":[{"text":"Stir","marks":[]}]}` |

It is stored in one column named for the field, of type `jsonb`. `{"tag":"quote","spans":[{"text":"Fresh every day","marks":[]}]}` is stored as `'{"tag":"quote","spans":[{"text":"Fresh every day","marks":[]}]}'::jsonb`.

## Shown to people

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

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"tag":"paragraph","spans":[{"text":"Fresh ","marks":[]},{"text":"soup","marks":["emphasis"]}]}` | `Fresh soup` |
| `{"tag":"heading","level":1,"spans":[{"text":"Soups","marks":[]}]}` | `Soups` |
| `{"tag":"quote","spans":[{"text":"Fresh every day","marks":[]}]}` | `Fresh every day` |
| `{"tag":"numbered_item","level":2,"spans":[{"text":"Stir","marks":[]}]}` | `Stir` |

## Operations

It 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.
