This plugin provides an enhanced literalinclude directive for the Sphinx Documentation Generator.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sphinxcontrib
static
.gitignore
LICENSE.txt
MANIFEST.in
README.rst
setup.cfg
setup.py
tox.ini
upload-to-pypi

README.rst

GetTheCode plugin for Sphinx

sphinxcontrib-getthecode license sphinxcontrib-getthecode python version

sphinxcontrib-getthecode last version

This plugin implements an enhanced literalinclude directive for the Sphinx Documentation Generator.

For a demo, look at Pyterate.

Authored by Fabrice Salvaire.

Source code is hosted at https://github.com/FabriceSalvaire/sphinx-getthecode

Installation

Using pip:

pip install sphinxcontrib-getthecode

Else clone the Git repository:

git clone git@github.com:FabriceSalvaire/sphinx-getthecode

then install the plugin using:

python setup.py install

Usage

To load the plugin, you have to add it in your conf.py file.

extensions = [
  ...
  'sphinxcontrib.getthecode',
  ]

Directives

This plugin implements a directive getthecode which is equivalent to the literalinclude directive, but it adds a header before the pre element. This header contains the file name and a link to download the file.

.. getthecode:: example.py
    :language: python3
    :hidden: ### optional, add a class highlight-hidden

will result in:

<div class="getthecode">
    <div class="getthecode-header">
    <ul>
        <li class="getthecode-filename">example.py</li>
        <li class="getthecode-filename-link">
            <a href="../../_downloads/example.py">
                <span>example.py</span>
                <i class="fa fa-download" aria-hidden="true"></i>
            </a></li>
        <li class="show-code-button" title="Show/Hide the code">
            <i class="fa fa-eye" aria-hidden="true"></i>
            <i class="fa fa-eye-slash" aria-hidden="true" style="display: none;"></i>
        </li></ul>
    </div>
    <div class="highlight-python3 highlight-hidden" style="display: none;">
    <div class="highlight">
        <pre>
        ...
        </pre>
    </div>
    </div>
</div>

You can find in the static directory an example of CSS stylesheet and a Javascript code to show/hide the code.