Rendering and Output Venues¶
A rendered reprex will be code plus the computed outputs plus additional formatting markup appropriate for some particular output venue. For example, the gh
venue (GitHub) will be in GitHub-flavored markdown and may look like this:
```python
2+2
#> 4
```
The venue can be set using the --venue / -v
command-line flag or the venue
configuration file option. The following section documents the available output venue options.
Venue options¶
Venue Keyword | Description | Formatter Function |
---|---|---|
gh |
Github Flavored Markdown | format_as_markdown |
so |
StackOverflow (alias for 'gh') | format_as_markdown |
ds |
Discourse (alias for 'gh') | format_as_markdown |
html |
HTML | format_as_html |
py |
Python script | format_as_python_script |
rtf |
Rich Text Format | format_as_rtf |
slack |
Slack | format_for_slack |
Formatter functions¶
format_as_markdown
¶
Format a rendered reprex reprex as a GitHub-Flavored Markdown code block. By default, includes a footer that credits reprexlite.
Used for venues: gh
, so
, ds
Example
```python
2+2
#> 4
```
format_as_html
¶
Format a rendered reprex reprex as an HTML code block. If optional dependency Pygments is available, the rendered HTML will have syntax highlighting for the Python code. By default, includes a footer that credits reprexlite.
Used for venues: html
Example
<pre><code>2+2
#> 4</code></pre>
format_as_python_script
¶
Format a rendered reprex reprex as a Python script.
Used for venues: py
Example
2+2
#> 4
format_as_rtf
¶
Format a rendered reprex reprex as a Rich Text Format (RTF) document. Requires dependency Pygments.
format_for_slack
¶
Format a rendered reprex as Slack markup.
Used for venues: slack
Example
```
2+2
#> 4
```
Under the hood and Python API¶
There are two steps to rendering a reprex:
- The
Reprex.render()
method renders a reprex instance as just the code and outputs. - A formatter function from
reprexlite.formatting
(see above) formats the rendered reprex code and outputs for the specified venue.
The whole process is encapsulated in the Reprex.render_and_format()
method.