Registry / serialization / md-node-inject

md-node-inject

JSON →
library2.0.0jsnpmunverified

md-node-inject is a utility for programmatically injecting Markdown Abstract Syntax Tree (AST) nodes into specific sections of another Markdown AST. Currently at stable version 2.0.0, this package is designed to work with parsed Markdown content, allowing for precise content integration without string manipulation. It differentiates itself by operating directly on ASTs, which prevents common issues associated with regex-based text replacement and ensures syntactically correct output. The library is ESM-only and requires Node.js v14 or higher for execution. It's often used in conjunction with other AST parsing and serialization libraries like `markdown-to-ast` and `ast-to-markdown` to form a complete Markdown processing pipeline.

npm install md-node-inject
INSTALL
IMPORT
SIG · MD-NODE-INJECT
M
md-node-inject
serializationjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inject
import inject from 'md-node-inject';
const inject = require('md-node-inject');
md-node-inject is an ESM-only package since version 2.0.0 and must be imported using ES module syntax.

This quickstart demonstrates parsing two Markdown strings into ASTs, injecting one AST (representing API documentation) into a specific section ('API') of the other, and then converting the resulting merged AST back into a Markdown string.

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);
Debug
Known issues
breakingmd-node-inject is an ESM-only package. It cannot be loaded using CommonJS `require()` and requires ES module syntax.
fix
Ensure your project is configured for ES modules (e.g., `"type": "module"` in `package.json`) and use `import` statements for `md-node-inject`.
affects: >=2.0.0
gotchaThe package requires Node.js version 14 or higher due to its exclusive reliance on ES modules and modern JavaScript features.
fix
Upgrade your Node.js runtime environment to version 14 or later to ensure compatibility and prevent execution errors.
affects: >=2.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to `require()` the `md-node-inject` package, which is an ESM-only module, in a CommonJS environment.
fix
Migrate your module loading to ES module syntax: change `const inject = require('md-node-inject');` to `import inject from 'md-node-inject';`. Also, ensure your `package.json` includes `"type": "module"` if running in Node.js.
ReferenceError: require is not defined
Using the `require()` function within an ES module file (e.g., a `.mjs` file or a file in a `"type": "module"` project) when `md-node-inject` is also an ES module.
fix
Replace all `require()` calls, particularly for `md-node-inject`, with corresponding `import` statements. `require` is not available in native ES modules.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
markdown-to-astrequiredRequired for parsing Markdown content into an AST, which `md-node-inject` operates on.
ast-to-markdownrequiredRequired for serializing the modified AST back into a Markdown string after injection.
Agent activity
2 hits · last 30 days
node
2
Resources
md-node-inject — npm install md-node-inject · libregistry