md-node-inject
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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.

Package Sidebar

Install

npm i md-node-inject

Weekly Downloads

2,712

Version

2.0.0

License

MIT

Unpacked Size

5.27 kB

Total Files

6

Last publish

Collaborators

  • demsking