GetTheCode plugin for Sphinx
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>
Metadata
Release files for sphinxcontrib-getthecode 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sphinxcontrib-getthecode-1.2.1.tar.gz | 22.1 kB | Without provenance | Details for sphinxcontrib-getthecode-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sphinxcontrib_getthecode-1.2.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for sphinxcontrib_getthecode-1.2.1-py2.py3-none-any.whl |
Total release size: 41.3 kB
Release files / sphinxcontrib-getthecode-1.2.1.tar.gz
| Download URL | sphinxcontrib-getthecode-1.2.1.tar.gz |
|---|---|
| Size | 22.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a1d6ae9e6886a93111fb7dd5ccbd050c4bb32b3e1e8b122d74f9176e28cdce5
|
|
BLAKE2b-256 checksum How to use checksums |
cb7c8c1c5243d4552d44d477131f5718d62f308607e1bafdc474173bc58dccef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.0
|
Release files / sphinxcontrib_getthecode-1.2.1-py2.py3-none-any.whl
| Download URL | sphinxcontrib_getthecode-1.2.1-py2.py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
2e95ae39ff6f333eb1a1861386b2bb3c39249c37db334b2861acb31d09bc7b53
|
|
BLAKE2b-256 checksum How to use checksums |
7a19d764ae0d5935b87b112d7287497a3f32eb1ebad39d678801296929536ae0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.0
|
Security for sphinxcontrib-getthecode 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.