A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template
Project description
mkdocs-markdownextradata-plugin
A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template
usecase
As a user with variables that need to be inserted at the markdown level, not the template level.
I need a mkdocs plugin that will inject my `extras` variables into the markdown template before it gets rendered to html.
So that I can build my markdown pages with different values for images, urls, client_names, etc.
Installation
Note: This package requires MkDocs version 0.17 or higher.
Install the package with pip:
pip install mkdocs-markdownextradata-plugin
Enable the plugin in your mkdocs.yml
:
plugins:
- search
- markdownextradata: {}
You are then able to use the mkdocs extra: {}
hash to pass context data into your files
Note: If you have no
plugins
entry in your config file yet, you'll likely also want to add thesearch
plugin. MkDocs enables it by default if there is noplugins
entry set, but now you have to enable it explicitly.
Using external data files
If the extra: {}
hash is not enough for your data then you are able to make use of external yaml files to provide that context data
plugins:
- search
- markdownextradata:
data: path/to/datafiles
The data path is optional; when absent, it will look for a _data
folder adjacent to your mkdocs.yml
and inside your docs_dir
.
If this path is found, the plugin will read all .yml
and .json
files inside it and add the data in them to the data available to the templates.
The paths to these become their variable names, so if inside your data folder you have a file
called sections/captions.yml
, the data inside that file will be available in your
templates as sections.captions
.
Features
Use Extra Variables in your markdown files
The variables you define in the mkdown.yml extra:
slot will become available in your templates
extra:
customer:
name: Your name here
web: www.example.com
salt: salt.example.com
and then in your *.md
files
{{ customer.name }}
<a href="{{ customer.web }}">{{ customer.web }}</a>
Testing
virtualenv venv -p python3.7
source venv/bin/activate
python setup.py test
pytest test
Contributing
From reporting a bug to submitting a pull request: every contribution is appreciated and welcome. Report bugs, ask questions and request features using Github issues. If you want to contribute to the code of this project, please read the Contribution Guidelines.
Contributors
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
File details
Details for the file mkdocs-markdownextradata-plugin-0.1.2.tar.gz
.
File metadata
- Download URL: mkdocs-markdownextradata-plugin-0.1.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b074198cbbf0707ddfe5f46f5ca9b5f8be6594fc620944912106e11f72cda833 |
|
MD5 | af2422738aa17a59a199bae882200dab |
|
BLAKE2b-256 | 2fbeea24e8273ec84c0fbd2278d529f456376967b638b7759a0ad7be7f902189 |
Provenance
File details
Details for the file mkdocs_markdownextradata_plugin-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: mkdocs_markdownextradata_plugin-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52e3c95a99d6b19026f01989ebdc16a5f8ba831a22ad32f9989a514fc3770bd2 |
|
MD5 | d95065b29973ffa12377d57b0b52fe1e |
|
BLAKE2b-256 | ea8742c86dc6f797b323c5b2e64277b14f0b034f8ee2be03e7e8dd561e7945d3 |