# remark-variables

> Adds variables support to remark

Latest version **1.4.9** (published 2020-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install remark-variables
pnpm add remark-variables
yarn add remark-variables
bun add remark-variables
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.9 |
| Published | 2020-04-03 |
| First published | 2018-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Paul Zimmer |
| Maintainers | mrzmmr |
| Keywords | remark, plugin, unified, markdown, template |

## Links

- npm: https://www.npmjs.com/package/remark-variables
- Repository: https://github.com/mrzmmr/remark-variables
- Homepage: https://github.com/mrzmmr/remark-variables#readme
- Issues: https://github.com/mrzmmr/remark-variables/issues
- npm.io page: https://npm.io/package/remark-variables

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.4.9 (latest) — 2020-04-03
- 1.4.8 — 2019-12-10
- 1.4.7 — 2019-07-25
- 1.4.6 — 2019-07-20
- 1.4.5 — 2018-10-05
- 1.4.4 — 2018-10-05
- 1.4.2 — 2018-10-04
- 1.4.1 — 2018-09-28
- 1.4.0 — 2018-09-28
- 1.3.0 — 2018-09-28
- 1.2.3 — 2018-09-27
- 1.2.2 — 2018-09-26
- 1.2.1 — 2018-09-26
- 1.2.0 — 2018-09-25
- 1.1.1 — 2018-09-25
- … 2 more at https://npm.io/package/remark-variables/versions

## README

# remark-variables

[![Travis](https://img.shields.io/travis/mrzmmr/remark-variables.svg)](https://travis-ci.org/mrzmmr/remark-variables)
[![Coverage
Status](https://coveralls.io/repos/github/mrzmmr/remark-variables/badge.svg?branch=master)](https://coveralls.io/github/mrzmmr/remark-variables?branch=master)

This plugin adds variables support to [remark](https://github.com/remarkjs/remark) using a customizable template syntax. Variables are checked against both the [vfile](https://github.com/vfile/vfile#vfiledata)'s, and [processor](https://github.com/unifiedjs/unified#processordatakey-value)'s **[data](https://github.com/vfile/vfile#vfiledata)** property and can use both dot and bracket syntax. For example, `foo.bar[0]` resolve to `vfile.data.foo.bar[0]` if it exists, or do nothing if the property does not exist. By default, this plugin uses double curly braces `{{`, `}}` to denote variables but can be configured.

## Install

```
npm install --save remark-variables
```

## Usage

If we have a file, example.md

```
# {{ title }}

- {{ list[0] }} (string)
- {{ list[1] }} (number)
- {{ list[2] }} (boolean)

> {{ subtitle }}
```

and

```js
var unified = require('unified')
var parser = require('remark-parse')
var compiler = require('remark-stringify')
var variables = require('remark-variables')
var reporter = require('vfile-reporter')
var toVfile = require('to-vfile')

var markdown = toVfile('./example.md')

// Set the processor
var processor = unified()
  .use(parser)
  .use(compiler)
  .use(variables)

// Add some data
processor = processor()
  .data('title', 'Example')
  .data('subtitle', 'Variables in markdown!')
  .data('list', [ 'other text', 0, true ])

// And process
processor().process(markdown, function (err, file) {
  console.error(reporter(err || file))
  console.log(file.toString())
})
```

the output would be

```
./example.md: no issues found
# Example

-   other text (string)
-   0 (number)
-   true (boolean)

> Variables in markdown!
```

### Options

Type: `Object` | `Array` | `String`

If options is a string, then it is used as the opening and closing fence markers, for example: `.use(variables, ':')` would match `:some.variable[0]:` look for `vfile.data.some.variable[0]`. If options is an array, options[0] and options[1] are used as fence markers.

#### fence

Type: `Array`

Default: [ '{{', '}}' ]

Markers used to denote a variable to be replaced.

## License

MIT &copy; Paul Zimmer

---
_Source: https://npm.io/package/remark-variables · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
