A markdown-it plugin, which allows defining variables, which can then be referenced in the document and are auto-replaced with the specified content
npm install markdown-it-variable
// ESM
import MarkdownIt from "markdown-it";
import MarkdownItVariable from "markdown-it-variable";
const md = new MarkdownIt().use(MarkdownItVariable, options);
// CommonJS
const markdownIt = require("markdown-it");
const markdownItVariable = require("markdown-it-variable");
const md = markdownIt().use(markdownItVariable);
You can define variables at any position of the document:
{{> variableName variableContent }}
{{> anotherVariable moreContent }}
Then, reference it anywhere:
This will be replaced: {{ variableName }}
will be rendered as
This will be replaced: variableContent
-
Each variable must be on its own line.
-
The variable name must not contain any spaces or special characters, only alphanumeric characters are allowed.
-
The definitions will not be rendered to keep your document clean. However, if a variable is not referenced, the definition will be visible to make you aware of this fact.
-
Definitions can be placed anywhere in the document.
-
Formatting via Markdown is possible:
{{> title *Markdown-it* **Variables** plugin }}
-
Variables can only span a single line, you cannot reference whole paragraphes or complex markup such as lists.
-
Variable content can contain markup handled by other plugins.
-
Spaces around the brackets are optional:
This is the {{title}}