This extension for Sphinx 1.0 converts ANSI colour sequences to colored HTML output. Use this extension to correctly include the output of command line tools, which use these control sequences to color their output (like sphinx-build, for instance).
The extension is available under the terms of the BSD license, see LICENSE for more information.
This extension can be installed from the Python Package Index:
pip install sphinxcontrib-ansi
Alternatively, you can clone the sphinx-contrib repository from BitBucket, and install the extension directly from the repository:
hg clone http://bitbucket.org/birkenfeld/sphinx-contrib cd sphinx-contrib/ansi python setup.py install
To interpret ANSI colour codes, use the following directive:
This directive interprets its content as literal block containing ANSI control sequences for coloured output for HTML output. If the document is build with any other builder than html, color sequences are stripped from output.
If the option string_escape is specified, the content of the directive is decoded using the string_escape codec. Thus you can include Python escape sequences, and therefore use \x1b instead of the real escape character.
The appearance is controlled by html_ansi_stylesheet:
The builtin stylesheet to use for ANSI color sequences. As of now, the following builtin stylesheets are provided:
If you do not like the builtin stylesheets, set html_ansi_stylesheet to None and create your own stylesheet. This stylesheet must provide styles for the following CSS classes:
These classes can appear in different combinations, especially a colour combined with a text format. You can therefore use a different colour, if the colour class is combined with a text format class. See black-on-white.css for an example.
Put this stylesheet somewhere in your html_static_path and make it known to sphinx by including the following code snippet in your conf.py:
def setup(app): app.add_stylesheet('my_ansi_theme.css')