Provides the `includex` macro for more flexible includes.
Project description
includex
Use includex
to include anything from any file into your markdown documentation.
Installation
pip install mkdocs-macros mkdocs-macros-includex
Usage
includex
can be configured as a pluglet for mkdocs-macros in the mkdocs.yml
configuration file:
plugins:
- search
- macros:
modules: ['includex']
Then you can use it to dynamically include file content in your documentation like this:
### Versioning
The version number is defined in the `pyproject.toml` file:
{{ includex("pyproject.toml", start_match="[tool.hatch.version]", code=True, lines=2, caption=True) }}
Would be rendered as
Versioning
The version number is defined in the pyproject.toml
file:
[tool.hatch.version]
path = "includex.py"
Comparison to other tools
snippets (pymdown-extensions)
The main use case this solves over snippets is that it includes partial content (i.e. a section or block) from a file as-is (i.e. without the need for special markers).
Snippets partially supports this now since v9.6 added support to include sections by lines.^snippet-lines Further, v9.7 added to support to sections by name, given that they are marked as such using a special marker comment.^snippet-sections
What includex does additionally is to match the start and end of blocks and include them without the need for any markers or line numbers. While this makes the documentation more prone to break, e.g., when the line that is being matched is changed in a way that it no longer matches, it supports some additional use-cases and requires less custom syntax.
Snippets is implemented as a preprocessor, while includex is implemented as a mkdocs-macros pluglet. This means that snippets are evaluated earlier than includex and prohibits snippets to work with other macros, like this:
{% for file in get_files("docs/") %}
{{ includex(file) }}
{% endfor %}
However, sections included using includex
are not evaluated themselves, so includex
cannot be nested (yet). If you need nested includes, use snippets
instead.
Project details
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
File details
Details for the file mkdocs_macros_includex-0.0.4.tar.gz
.
File metadata
- Download URL: mkdocs_macros_includex-0.0.4.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e318cf1a4b1b518e008b41233885a4d2d474169124c8fdef917c8b8feafaa211 |
|
MD5 | 3534381d0fee0208a9f8a377b9faad22 |
|
BLAKE2b-256 | 070fb561a612d039c9b5544cd813f6649ffdab714820ab8e7f4778f68f683dd3 |
File details
Details for the file mkdocs_macros_includex-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: mkdocs_macros_includex-0.0.4-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01d0baacc25ee942e5eb2977f82e19fd2e06c07778f70914ed7f67fba2788b1d |
|
MD5 | 12a48b9017891d4f244c0f549392032a |
|
BLAKE2b-256 | fdb51d1fc282e2a9091e50ac36523d4bcfed1fd2fa05510eacfb048d946ef480 |