# `RichTextBlock`

One block of a [`RichText`](/docs/types/type-rich-text.md): a paragraph, a heading, a quote or a list item.

Use it when you build a [`RichText`](/docs/types/type-rich-text.md) in code. To hold a document, use [`RichText`](/docs/types/type-rich-text.md).

## Shape

One of these, each with its own fields:

| Variant | Field | Type | Required? |
|---|---|---|---|
| `RichTextBlock.paragraph` | `spans` | `List<`[`RichTextSpan`](/docs/types/type-rich-text-span.md)`>` | Yes |
| `RichTextBlock.heading` | `level` | `Int` | Yes |
|  | `spans` | `List<`[`RichTextSpan`](/docs/types/type-rich-text-span.md)`>` | Yes |
| `RichTextBlock.quote` | `spans` | `List<`[`RichTextSpan`](/docs/types/type-rich-text-span.md)`>` | Yes |
| `RichTextBlock.bullet_item` | `level` | `Int` | Yes |
|  | `spans` | `List<`[`RichTextSpan`](/docs/types/type-rich-text-span.md)`>` | Yes |
| `RichTextBlock.numbered_item` | `level` | `Int` | Yes |
|  | `spans` | `List<`[`RichTextSpan`](/docs/types/type-rich-text-span.md)`>` | Yes |

## Example

```jadpo
RichTextBlock.heading {
    level: 2
    spans: [
        RichTextSpan { text: "Soups" marks: [] link: none }
    ]
}
```

## Good to know

- A heading's level runs from 1 to 6, and a list item's from 1 to 9.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it.

## In JSON

An object of its variant's name, as `tag`, and the variant's fields, in a request, a response or `json.write`:

```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":[]}]}
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`RichTextBlock` is in the group Text formats, and has been in Jadpo since 0.1.0.

### Text form

It has no single text form, so `text.from` and `text.parse` don't take it.

### How it is stored

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

### How it is 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 also takes `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
