A Docsify plugin that allow preprocessing markdown documents with Mustache template engine. You can substitute variables in markdown documents using mustache syntax {{variable}}
and {{variable.property}}
. Variables can be load from various sources, including front matter section of markdown documents, external JSON or XML files and Docsify configuration.
Add following script tag to your index.html
after docsify.
<script src="//cdn.jsdelivr.net/npm/docsify-mustache-plus"></script>
Optionally add docsify-front-matter plugin to access markdown front matter variables.
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/front-matter.min.js"></script>
You can load Mustache variables with data
option. The value can be a string, object or array.
- string value interpreted as data file URL (relative or absolute). Both JSON and XML data file formats are supported.
- properties from JSON data file will be available as Mustache variables
- XML root element will be mapped to Mustache variable with root elements tag name as variable name
- object properties will be mapped to Mustache variables using property name as variable name
- array may be use to specify multiple string or object values as data sources
Example:
window.$docsify = {
mustache: {
data: [
'doc/vars.json',
'doc/pom.xml',
{
question: 'What is your favorite number?'
}
]
}
}
There is no way to access XML attributes, tag names used for hierarchy and for referring element's inner text.
The plugin loads package.json
and make it available for Mustache as package
variable. You can disable this feature setting noPackage
option to true
value:
window.$docsify = {
mustache: {
noPackage : true
}
}
Custom delimiters can be used in place of {{
and }}
by setting the new values in JavaScript or in templates.
window.$docsify = {
mustache: {
tags: ['<%', '%>']
}
}
Check the documentation site for more information.
This project is licensed under the MIT License. See the LICENSE for details.