markdown-it-variable
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

markdown-it-variable

npm Tests markdown-it

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

npm install markdown-it-variable

Enable

// 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:

{{> variableName variableContent }}
{{> anotherVariable moreContent }}

Then, reference it anywhere:

This will be replaced: {{ variableName }}

will be rendered as

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:

    {{> 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}}

Package Sidebar

Install

npm i markdown-it-variable

Weekly Downloads

35

Version

1.0.2

License

MIT

Unpacked Size

16.8 kB

Total Files

8

Last publish

Collaborators

  • bioruebe