{"id":11279,"library":"md-node-inject","title":"Markdown AST Injection Utility","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","markdown","ast","inject","injection","typescript"],"install":[{"cmd":"npm install md-node-inject","lang":"bash","label":"npm"},{"cmd":"yarn add md-node-inject","lang":"bash","label":"yarn"},{"cmd":"pnpm add md-node-inject","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for parsing Markdown content into an AST, which `md-node-inject` operates on.","package":"markdown-to-ast","optional":false},{"reason":"Required for serializing the modified AST back into a Markdown string after injection.","package":"ast-to-markdown","optional":false}],"imports":[{"note":"md-node-inject is an ESM-only package since version 2.0.0 and must be imported using ES module syntax.","wrong":"const inject = require('md-node-inject');","symbol":"inject","correct":"import inject from 'md-node-inject';"}],"quickstart":{"code":"import ast from 'markdown-to-ast';\nimport toMarkdown from 'ast-to-markdown';\nimport inject from 'md-node-inject';\n\nconst mdContent = `\n  # Sample\n  Description\n\n  # API\n\n  # License\n  MIT\n`;\n\nconst mdApiContent = `\n  ## method()\n  Method description\n`;\n\nconst mdContentAst = ast.parse(mdContent);\nconst mdApiContentAst = ast.parse(mdApiContent);\n\nconst injectionSection = 'API';\nconst mergedContentAst = inject(injectionSection, mdContentAst, mdApiContentAst);\n\nconst mergedContent = toMarkdown(mergedContentAst);\n\nconsole.log(mergedContent);","lang":"javascript","description":"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."},"warnings":[{"fix":"Ensure your project is configured for ES modules (e.g., `\"type\": \"module\"` in `package.json`) and use `import` statements for `md-node-inject`.","message":"md-node-inject is an ESM-only package. It cannot be loaded using CommonJS `require()` and requires ES module syntax.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your Node.js runtime environment to version 14 or later to ensure compatibility and prevent execution errors.","message":"The package requires Node.js version 14 or higher due to its exclusive reliance on ES modules and modern JavaScript features.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to `require()` the `md-node-inject` package, which is an ESM-only module, in a CommonJS environment.","error":"ERR_REQUIRE_ESM"},{"fix":"Replace all `require()` calls, particularly for `md-node-inject`, with corresponding `import` statements. `require` is not available in native ES modules.","cause":"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.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}