Skip to content

demsking/md-node-inject

Repository files navigation

Markdown AST injection utility

npm Build status Test coverage Buy me a beer

Install

This package is ESM only : Node 14+ is needed to use it and it must be imported instead of required.

npm install md-node-inject

Usage

import ast from 'markdown-to-ast';
import toMarkdown from 'ast-to-markdown';
import inject from 'md-node-inject';

const mdContent = `
  # Sample
  Description

  # API

  # License
  MIT
`;

const mdApiContent = `
  ## method()
  Method description
`;

const mdContentAst = ast.parse(mdContent);
const mdApiContentAst = ast.parse(mdApiContent);

const injectionSection = 'API';
const mergedContentAst = inject(injectionSection, mdContentAst, mdApiContentAst);

const mergedContent = toMarkdown(mergedContentAst);

console.log(mergedContent);

Output:

# Sample
Description

# API
## method()
Method description

# License
MIT

Development Setup

  1. Install Nix Package Manager

  2. Install direnv with your OS package manager

  3. Hook it direnv into your shell

  4. At the top-level of your project run:

    direnv allow

    The next time your launch your terminal and enter the top-level of your project, direnv will check for changes.

License

Under the MIT license. See LICENSE file for more details.