Skip to content

Venues Formatting

reprexlite comes with support for formatting reprexes for the following venues.

Venue Keyword Description Formatter
gh Github Flavored Markdown GitHubFormatter
so StackOverflow (alias for 'gh') GitHubFormatter
ds Discourse (alias for 'gh') GitHubFormatter
html HTML HtmlFormatter
py Python script PyScriptFormatter
rtf Rich Text Format RtfFormatter
slack Slack SlackFormatter

Examples

GitHubFormatter

Formatter for rendering reprexes in GitHub Flavored Markdown.

```python
2+2
#> 4
```

API documentation

HtmlFormatter

Formatter for rendering reprexes in HTML. If optional dependency Pygments is available, the rendered HTML will have syntax highlighting for the Python code.

<pre><code>2+2
#> 4</code></pre>

API documentation

PyScriptFormatter

Formatter for rendering reprexes as a Python script.

2+2
#> 4

API documentation

RtfFormatter

Formatter for rendering reprexes in Rich Text Format.

Example not shown.

API documentation

SlackFormatter

Formatter for rendering reprexes as Slack markup.

```
2+2
#> 4
```

API documentation

Custom Formatter

There are two steps to creating a custom formatter:

  1. Subclass the Formatter abstract base class and implement a format method.
  2. Register your custom formatter with the @register_formatter(...) decorator.
from reprexlite.formatting import Formatter, register_formatter

@register_formatter(venue="myformat", label="My Custom Format")
class MyCustomerFormatter(Formatter):

    @classmethod
    def format(
        cls, reprex_str: str, advertise: bool | None = None, session_info: bool = False
    ) -> str:
        ...

This will make your formatter available under the venue key you provide to the registration decorator.

Currently, reprexlite does not have any extension or plugin system to load your code with your custom formatter. This means that you will only be able to easily access it with certain usage options where you can import or run your code, such as using reprexlite as a library or with the IPython cell magic.