---
project: "rich-click"
title: "Text Markup & Formatting"
description: "The five text_markup modes rich-click supports (Rich markup, Markdown, reStructuredText, ANSI and plain), plus emoji, newline handling and help text styling."
url: "https://ewels.github.io/rich-click/latest/documentation/text_markup_and_formatting/"
---

# Text Markup & Formatting

## Markup

**rich-click** supports 5 different values for `text_markup`, which determines how text is rendered:

- `'ansi'`: **(Default)** Rendered as plain text with ANSI escape codes handled.
- `'rich'`: Rendered using Rich's markup syntax.
- `'markdown'`: Rendered with markdown.
- `'rst'`: Rendered as reStructuredText (requires the `rst` extra).
- `None`: Rendered as plain text, ANSI escape codes are not handled.

<details open>
<summary>rich-click ≥1.8.0 deprecation</summary>

Prior to **rich-click** 1.8.0, markup was controlled by the booleans `use_rich_markup` and `use_markdown`.

These booleans have been silently deprecated (read: they will still be supported for the distant future),
and users are encouraged to use the `text_markup` config option instead.

</details>

### Rich markup

In order to be as widely compatible as possible with a simple import,
**rich-click** does _not_ parse rich formatting markup (eg. `[red]`) by default.
You need to opt-in to this behaviour.

Remember that you'll need to escape any regular square brackets using a back slash in your help texts,
for example: `[dim]\[my-default: foo][\]`

For more information, read the Rich docs on [markup](https://rich.readthedocs.io/en/stable/markup.html) and [styles](https://rich.readthedocs.io/en/stable/style.html).

```python
help_config = {"text_markup": "rich"}
```
```python
help_config = click.RichHelpConfiguration(text_markup="rich")
```
```python
click.rich_click.TEXT_MARKUP = "rich"
```
```sh runnable.outputFile="../images/rich_markup.ansi" title="Rich markup example"
$ python examples/04_rich_markup.py --help
```

> See [`examples/04_rich_markup.py`](https://github.com/ewels/rich-click/blob/main/examples/04_rich_markup.py) for an example.

### Markdown

If you prefer, you can use Markdown text.

```python
help_config = {"text_markup": "markdown"}
```
```python
help_config = click.RichHelpConfiguration(text_markup="markdown")
```
```python
click.rich_click.TEXT_MARKUP = "markdown"
```
```sh runnable.outputFile="../images/markdown.ansi" title="Markdown example"
$ python examples/05_markdown.py --help
```

> See [`examples/05_markdown.py`](https://github.com/ewels/rich-click/blob/main/examples/05_markdown.py) for an example.

### reStructuredText

You can also write help text in [reStructuredText](https://docutils.sourceforge.io/rst.html),
which is handy if your docstrings are also used by Sphinx.
Rendering is done by [rich-rst](https://github.com/wasi-master/rich-rst), which is an optional dependency:

```shell
pip install 'rich-click[rst]'
```

```python
help_config = {"text_markup": "rst"}
```
```python
help_config = click.RichHelpConfiguration(text_markup="rst")
```
```python
click.rich_click.TEXT_MARKUP = "rst"
```
Admonitions (`.. note::`, `.. warning::`, etc.) are rendered compactly by default to suit help text,
and `::` literal blocks are highlighted as shell sessions (`default_lexer="console"`).
Click's `\b` no-rewrap paragraphs keep their line breaks and indentation, though inline markup in them shows as plain text.
The help text is rendered as one document, so `padding_helptext_first_line` pads all of it.
Any `text_kwargs` are passed to `rich_rst.RestructuredText()`, for example
`text_kwargs={"admonition_style": "panel", "code_theme": "github-dark"}`.

```sh runnable.outputFile="../images/rst.ansi" title="reStructuredText example"
$ python examples/14_rst.py --help
```

> See [`examples/14_rst.py`](https://github.com/ewels/rich-click/blob/main/examples/14_rst.py) for an example.

## Markup in text

The selected `text_markup` is used to render all text in your CLI help that can be set in the high-level API:

- The command's `help`
- Each subcommand's `help`
- Each parameter's `help`
- Each panel's `help`
- Header text, footer text, and epilog text.

```python
richMarkupRaw
```

<details open>
<summary>Output</summary>

```sh runnable.outputFile="../images/code_snippets/text_markup_and_formatting/rich_markup.ansi"
$ python rich_markup.py --help
```

</details>

You can also set the styles of `help` for objects in decorators using `help_style=`.
The below code renders the same as the above code:

```python
markupWithHelpStyleRaw
```

<details>
<summary>Output</summary>

```sh runnable.outputFile="../images/code_snippets/text_markup_and_formatting/markup_with_help_style.ansi"
$ python markup_with_help_style.py --help
```

</details>

## Emojis

Emoji codes are rendered by default in `'rich'` and `'markdown'` text markup modes.
For other modes, including the default mode, emojis are not rendered.

You can explicitly enable and disable emojis with the config option `text_emoji`:

```python
emojisRaw
```

<details open>
<summary>Output</summary>

```sh runnable.outputFile="../images/code_snippets/text_markup_and_formatting/emojis.ansi"
$ python emojis.py --help
```

</details>

You can view all available emojis with the following command:

```shell
uvx --from rich -- python3 -m rich.emoji
```

## Newlines

Handling newlines on **rich-click**'s end involves discretion because in a docstring, newlines can represent a softwrap; they are not necessarily genuine new lines.

For `'markdown'` mode, we send all newline handling directly to `rich.markdown.Markdown()`.
Likewise, `'rst'` mode sends newline handling to `rich_rst.RestructuredText()`.

For other modes, we implement the following rules:

- Double newlines collapse to single newlines by default.
- Single newlines are not preserved, unless...
- The line starts with `'- '`, `'* '`, `'> '` or <code>'&nbsp;&nbsp;&nbsp;&nbsp;'</code> (4 spaces).

The following code snippet demonstrates this:

```python
newlineControlRaw
```

<details open>
<summary>Output</summary>

```sh runnable.outputFile="../images/code_snippets/text_markup_and_formatting/newline_control.ansi"
$ python newline_control.py --help
```

</details>

Note that this differs from how base Click handles newlines.
The following is the same CLI help text but using `import click` instead of `import rich_click as click`:

<details>
<summary>Output - <code>import click</code> instead of <code>import rich_click as click</code></summary>

```sh runnable.outputFile="../images/code_snippets/text_markup_and_formatting/newline_control_base_click.ansi"
$ python newline_control_base_click.py --help
```

</details>

### Spacing

By default, **rich-click** renders double newlines as single newlines.
This is a deliberate decision to make help text take up less vertical space.

However, you can override this behavior by setting the config option `text_paragraph_linebreaks` to `"\n\n"`.

```python
newlineControlDoubleRaw
```

<details open>
<summary>Output</summary>

```sh runnable.outputFile="../images/code_snippets/text_markup_and_formatting/newline_control_double.ansi"
$ python newline_control_double.py --help
```

</details>

<details open>
<summary>Info</summary>

This default behavior of collapsing newlines is not true when `text_markup='markdown'` or `text_markup='rst'`.
For these modes, we do not do any newline manipulation.

</details>