@hanseartic/remark-env-directive
Version:
substitute environment variables in markdown directive plugin for remark
58 lines (43 loc) • 1.27 kB
Markdown
This remark-plugin allows to resolve an environment variable from a given value into markdown files.
```shell
npm i @hanseartic/remark-env-directive
```
```shell
yarn add @hanseartic/remark-env-directive
```
This plugin needs the [`remark-directive`](https://github.com/remarkjs/remark-directive) plugin to generally enable directives.
Given a markdown file `example.md`:
```markdown
:env[VALUE_IN_ENV_VAR]
```
and a processing module `example.js`:
```javascript
import {read} from 'to-vfile'
import {unified} from 'unified'
import remarkParse from 'remark-parse'
// necessary to enable directives in general
import remarkDirective from 'remark-directive'
// the env-var directive itself
import envDirective from '@hanseartic/remark-env-directive'
main()
async function main() {
const file = await unified()
.use(remarkParse)
.use(remarkDirective)
.use(envDirective)
.process(await read('example.md'))
console.log(String(file))
}
```
Following result could be rendered by `VALUE_IN_ENV_VAR="Hi from the environment" node example`:
```markdown
Hi from the environment
```