Sphinx getthecode extension
Project description
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
:notebook: ### optional, if a example.ipynb is available
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="../example.py" download="example.py" type="text/x-python" target="_blank" rel="noreferrer noopener">
<span> example.py </span>
</a>
</li>
<li class="getthecode-notebook-link">
<a href="../example.ipynb" download="example.ipynb" type="application/x-ipynb+json" target="_blank" rel="noreferrer noopener">
<span> example.ipynb </span>
</a>
</li>
<!-- Added by javascript -->
<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.
You can customise the HTML code using the getthecode_header_template configuration variable that contains a Jinja2 template, by default set to:
<div class="getthecode-header">
<ul>
<li class="getthecode-filename">{{ filename }}</li>
<li class="getthecode-filename-link">
<a href="{{ url }}" download={{ filename }} type="text/x-python" target="_blank" rel="noreferrer noopener"><span>
{{ filename }}
</span></a>
</li>
{% if notebook_url %}
<li class="getthecode-notebook-link">
<a href="{{ notebook_url }}" download={{ notebook_filename }} type="application/x-ipynb+json" target="_blank" rel="noreferrer noopener"><span>
{{ notebook_filename }}
</span></a>
</li>
{% endif %}
</ul>
</div>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sphinxcontrib-getthecode-1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e15e074d03986fa8df97a8e94bc356c3668809ee28bf028c073151eae9d4a8c3 |
|
MD5 | b017bfb6e8723bb13ec5a0edd628ada4 |
|
BLAKE2b-256 | c90b7463d8159712833850cd2e4e207a97eb795ed48e743f858e1033c21e162b |
Hashes for sphinxcontrib_getthecode-1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2b1c46af4bd25564a32a5370a555340ee51f68b8bf7c456b26d561696b15667 |
|
MD5 | a4cdbca68bcb6fad86989f50f4ce0eb8 |
|
BLAKE2b-256 | c6718351e083bdd63ba10cb236245d5254116d17181b7391509fe96f49b5cbf8 |