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:

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:

Reverse source and result

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

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:

Add your own class

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