sphinx-examples#

A small sphinx extension to add “example snippets” that allow you to show off source markdown and the result of rendering it in Sphinx.

For example:

Showing off a card and note directive

:::{note}
Here's a sample note!
:::

Note

Here’s a sample note!

Warning

This currently only works with MyST Markdown content, it will not work if you’ve written your documentation in reStructuredText.

Install#

Install with pip:

$ pip install sphinx-examples

Use#

The {example} directive allows you to show off some source markdown, and the result of rendering it. It is meant to help you demonstrate functionality of a theme, extension, syntax, etc. For example:

Using the example directive

```{example} Example title
Here's my **example**!
```

Example title

Here's my **example**!

Here’s my example!

Reverse source and result#

You can reverse the order of source and result by using the :reverse: flag, like so:

```{example} Reversed source and result
:reverse:
Here's my **example**!
```

Reversed source and result

Here’s my example!

Here's my **example**!

You can also remove the parent container of the source/result blocks in case you wish to demonstrate something that would not work properly inside a container:

Remove the container with simple mode#

You can remove the Sphinx Design container entirely, which simply places the source / result next to one another. This is useful if the container would prevent you from demonstrating some functionality:

No container so we can show off a margin

Source

```{example}
:no-container:

:::{margin}
Here's my **margin content**!
:::

```

Result

Source

:::{margin}
Here's my **margin content**!
:::

Result

Add your own class#

You can add your own classes to examples as well. For example:

Source

```{example} A full-width example
:class: full-width
:no-container:

:::{note}
A full-width note!
:::

```

Result

A full-width example

Source

:::{note}
A full-width note!
:::

Result

Note

A full-width note!