@hanseartic/remark-env-directive
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

env-var remark directive plugin

This remark-plugin allows to resolve an environment variable from a given value into markdown files.

Installation

npm

npm i @hanseartic/remark-env-directive

yarn

yarn add @hanseartic/remark-env-directive

Pre-Conditions

This plugin needs the remark-directive plugin to generally enable directives.

Usage

Given a markdown file example.md:

# Example with environment variable

:env[VALUE_IN_ENV_VAR]

and a processing module example.js:

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:

# Example with environment variable

Hi from the environment

Package Sidebar

Install

npm i @hanseartic/remark-env-directive

Weekly Downloads

7

Version

1.0.3

License

MIT

Unpacked Size

4.45 kB

Total Files

6

Last publish

Collaborators

  • hanseartic