https://github.com/bioruebe/markdown-it-variable
A markdown-it plugin, which allows defining variables
https://github.com/bioruebe/markdown-it-variable
markdown-it markdown-it-plugin variable variables
Last synced: 7 months ago
JSON representation
A markdown-it plugin, which allows defining variables
- Host: GitHub
- URL: https://github.com/bioruebe/markdown-it-variable
- Owner: Bioruebe
- License: mit
- Created: 2023-04-07T22:23:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-21T09:28:37.000Z (almost 2 years ago)
- Last Synced: 2025-06-03T11:51:37.091Z (8 months ago)
- Topics: markdown-it, markdown-it-plugin, variable, variables
- Language: TypeScript
- Homepage:
- Size: 139 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# markdown-it-variable
[](https://www.npmjs.com/package/markdown-it-variable)  
> A markdown-it plugin, which allows defining variables, which can then be referenced in the document and are auto-replaced with the specified content
## Usage
### Install
```bash
npm install markdown-it-variable
```
### Enable
```js
// 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);
```
### Syntax
You can define variables at any position of the document:
```md
{{> variableName variableContent }}
{{> anotherVariable moreContent }}
```
Then, reference it anywhere:
```md
This will be replaced: {{ variableName }}
```
will be rendered as
```html
This will be replaced: variableContent
```
#### Variable definition
- 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.
#### Variable content
- Formatting via Markdown is possible:
```md
{{> 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:
```md
This is the {{title}}
```