All Projects → rosscdh → mkdocs-markdownextradata-plugin

rosscdh / mkdocs-markdownextradata-plugin

Licence: MIT License
A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template

Programming Languages

python
139335 projects - #7 most used programming language
Nix
1067 projects

Projects that are alternatives of or similar to mkdocs-markdownextradata-plugin

mkdocs-git-authors-plugin
MkDocs plugin to display git authors of a page.
Stars: ✭ 27 (-43.75%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-table-reader-plugin
MkDocs plugin that adds a {{ read_csv('table.csv') }} markdown tag to directly insert CSV files as a table into a page.
Stars: ✭ 60 (+25%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-section-index
MkDocs plugin to allow clickable sections that lead to an index page
Stars: ✭ 36 (-25%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-exclude-search
🔎 A mkdocs plugin that lets you exclude selected chapters from the search index.
Stars: ✭ 16 (-66.67%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-print-site-plugin
MkDocs Plugin that adds an additional page that combines all pages, allowing easy exports to PDF and standalone HTML.
Stars: ✭ 38 (-20.83%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-git-revision-date-localized-plugin
MkDocs plugin to add a last updated date to your site pages
Stars: ✭ 73 (+52.08%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-rss-plugin
MkDocs plugin to generate a RSS feeds for created and updated pages, using git log and YAML frontmatter (page.meta).
Stars: ✭ 43 (-10.42%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-htmlproofer-plugin
A MkDocs plugin that validates URL in rendered html files
Stars: ✭ 17 (-64.58%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-static-i18n
MkDocs i18n plugin using static translation markdown files
Stars: ✭ 78 (+62.5%)
Mutual labels:  mkdocs, mkdocs-plugin
mkdocs-literate-nav
MkDocs plugin to specify the navigation in Markdown instead of YAML
Stars: ✭ 19 (-60.42%)
Mutual labels:  mkdocs, mkdocs-plugin
node-v
🔒 Secure ❄️ Synchronized ⚡️ Realtime ☁️ Cloud 🌈 Native JavaScript Variables & Events
Stars: ✭ 27 (-43.75%)
Mutual labels:  variables
mkdocs build plantuml
MkDocs plugin to help generate your plantuml images locally or remotely as files (NOT inline)
Stars: ✭ 31 (-35.42%)
Mutual labels:  mkdocs
expandvars
Expand system variables Unix style
Stars: ✭ 17 (-64.58%)
Mutual labels:  variables
kotlin-rev-solution
Kotlin reference site in Japanese.
Stars: ✭ 46 (-4.17%)
Mutual labels:  mkdocs
mkdocs-rtl
mkdocs rtl theme based on mkdocs-material
Stars: ✭ 22 (-54.17%)
Mutual labels:  mkdocs
Documentation
Kodular Documentation
Stars: ✭ 41 (-14.58%)
Mutual labels:  mkdocs
docutools
Dev Centric Tools for Mkdocs Based Documentation
Stars: ✭ 13 (-72.92%)
Mutual labels:  mkdocs
jdg
Гайд-путеводитель по JDG (ИП) в Польше
Stars: ✭ 84 (+75%)
Mutual labels:  mkdocs
emlid-docs
Documentation for Emlid products
Stars: ✭ 62 (+29.17%)
Mutual labels:  mkdocs
vue-global-var
Reactive global variable can be sharable between components
Stars: ✭ 21 (-56.25%)
Mutual labels:  variables

mkdocs-markdownextradata-plugin

Build Status

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 the search plugin. MkDocs enables it by default if there is no plugins entry set, but now you have to enable it explicitly.

Features

Use Extra Variables in your markdown files

The variables you define in the mkdown.yml extra: slot will become available in your templates

site_name: My fantastic site

plugins:
    - search
    - markdownextradata

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>

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

or if you have multiple locations provide a comma (,) separated list of locations

plugins:
    - search
    - markdownextradata:
        data: path/to/datafiles, another/path/to/datafiles

if you leave markdownextradata.data empty

plugins:
    - search
    - markdownextradata

by default it will search in the folder where your mkdocs.yml is kept and in the docs folder for another folder called _data (i.e. ./docs/_data/site.yaml), available as {{ site.whatever_variable_in_the_yaml}}.

If these paths are found, the plugin will read all .yml|.yaml and .json files inside them and add the data in them under the extra key.

For example, if you have a file called [path/to/datafiles/]sections/captions.yaml which includes a variable foo - where [path/to/datafiles/] is the path declared in your configuration under data - the data inside that file will be available in your templates as {{sections.captions.foo}} or {{sections['captions']['foo']}}.

Alternatively, you can access all files and variable declared under data in template using extra key. This is particularly useful if your folder or filename do not comply with the Python variable naming rules. For example, if you have a file [path/to/datafiles/]1_example/captions.yaml which includes a variable bar, writting the template as {{1_example.captions.bar}} returns a jinja2.exceptions.TemplateSyntaxError since the folder 1_example starts with a number. Instead, you can call this file with when the template is {{extra['1_example']['captions']['bar']}}.

Jinja2 Template Engine Configuration

You may provide Jinja2 configuration as plugin options:

plugins:
    - markdownextradata:
        jinja_options:
          comment_start_string: __CUSTOMCOMMENTSTART__

The above example will make it so that instead of {#, the template engine will interpret __CUSTOMCOMMENTSTART__ as comment start delimiter. This is useful in cases where you write Markdown that contains Jinja-like syntax that's colliding with the template engine. Alternatively, it lets you control what the variable delimiter is (instead of the default {{ }}).

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].