https://github.com/demsking/md-node-inject
Markdown AST injection utility
https://github.com/demsking/md-node-inject
ast inject injection markdown
Last synced: 2 months ago
JSON representation
Markdown AST injection utility
- Host: GitHub
- URL: https://github.com/demsking/md-node-inject
- Owner: demsking
- License: mit
- Created: 2017-09-16T07:03:05.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2022-07-18T07:51:53.000Z (almost 4 years ago)
- Last Synced: 2025-06-11T22:29:07.382Z (about 1 year ago)
- Topics: ast, inject, injection, markdown
- Language: JavaScript
- Homepage: https://gitlab.com/demsking/md-node-inject
- Size: 280 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Markdown AST injection utility
[](https://www.npmjs.com/package/md-node-inject)
[](https://gitlab.com/demsking/md-node-inject/pipelines)
[](https://gitlab.com/demsking/md-node-inject/pipelines)
[](https://www.buymeacoffee.com/demsking)
## Install
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
: Node 14+ is needed to use it and it must be imported instead of required.
```sh
npm install md-node-inject
```
## Usage
```js
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:**
```md
# Sample
Description
# API
## method()
Method description
# License
MIT
```
## Development Setup
1. [Install Nix Package Manager](https://nixos.org/manual/nix/stable/installation/installing-binary.html)
2. [Install `direnv` with your OS package manager](https://direnv.net/docs/installation.html#from-system-packages)
3. [Hook it `direnv` into your shell](https://direnv.net/docs/hook.html)
4. At the top-level of your project run:
```sh
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](https://gitlab.com/demsking/md-node-inject/blob/main/LICENSE) file for more details.