sphinxcontrib-relativeinclude
About
This package implements a new reST directive to include files and translate paths included in those files.
Installation
The project is hosted on PyPI, and can be installed via pip.
pip install sphinxcontrib-relativeinclude
You can find the contents of the README and the module documentation for the latest release online. It's also available PDF or EPUB.
Motivation
Let's assume you want to transclude the README.rst sitting in your repository root, in your docs/index.rst, so it automatically shows up in your generated documentation.
You can just use reST's standard include directive.
.. include: ../README.rst
Sidenote: If you're using a parser, like MyST, you could also easily include markdown files, of course.
This will insert the contents of your README in the appropriate place, and even take care of heading levels for you.
The problem arises when you have images or other files included in there. Sphinx won't resolve those links properly, i.e., relative to the README, but instead relative to your Sphinx index document. That means those pictures won't show up, which, needless to say, is not optimal. If you use your valuable time to create visual resources for your documentation these should also be included in the documentation output.
| Picture of a honey badger by Sumeetmoghe on Wikimedia Commons (CC-BY-SA-4.0) |
This picture uses a relative path to a file in the docs/assets directory, and would happily show up in your Git repo, but not in your documentation.
This is what this extension is supposed to solve.
It defines a new relativeinclude directive, that takes relative paths in included files, and resolves them into absolute ones.
This way your images show up in your documentation output, but you don't have to hardcode absolute paths in your documentation.
(Cf. this awesome honey badger here)
Caveat emptor: At this point in time, nested includes are unfortunately not supported. (See TODOs)
Usage
You have to enable the extension in your conf.py file.
# in conf.py
extensions = [
# ...
"sphinxcontrib.relativeinclude",
# ...
]
After that, the directive will be available for you to use in your documentation.
.. relativeinclude: ../README.md
:parser: myst_parser.docutils_
It supports the same options as the standard include directive.
If not, you've found a bug, and I'd be happy if you reported it on the issue tracker.
Please provide thorough description, and a minimal reproducible example, i.e., (abbreviated) reST files you used, potentially your conf.py contents and maybe other relevant info.
If you want to see some real code, check out this repository's documentation at docs/index.rst.
TODOs
- support multiple levels of indirection
- properly register directive on install
License
sphinxcontrib-relativeinclude is distributed under the terms of the MIT license.
Release files for sphinxcontrib-relativeinclude 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sphinxcontrib_relativeinclude-0.0.5.tar.gz | 7.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sphinxcontrib_relativeinclude-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:14.7 kB
Release files / sphinxcontrib_relativeinclude-0.0.5.tar.gz
| Download URL | sphinxcontrib_relativeinclude-0.0.5.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c595e2c6ca285fea967539e4eb5b251ff132a6ccf2ba19077edc8c27de930b1e
|
|
BLAKE2b-256 checksum How to use checksums |
486d9e70971a55cf22de432c3cfe2f22b97df1f405a208e6500611807a42fd53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / sphinxcontrib_relativeinclude-0.0.5-py3-none-any.whl
| Download URL | sphinxcontrib_relativeinclude-0.0.5-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
43df4bf253720a0bf731eb1aaa1b7a738d280f76bda75acd5564d6eafe04c59f
|
|
BLAKE2b-256 checksum How to use checksums |
e7a95b4956d44f197cf44aecb3e10de6a5b0beb0009212d0bbb614f6768bca15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|