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-injectVerified import paths — ran on the pinned version, not inferred.
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.
Ensure your project is configured for ES modules (e.g., `"type": "module"` in `package.json`) and use `import` statements for `md-node-inject`.
Upgrade your Node.js runtime environment to version 14 or later to ensure compatibility and prevent execution errors.
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.Replace all `require()` calls, particularly for `md-node-inject`, with corresponding `import` statements. `require` is not available in native ES modules.