markdown-it-chain
raw JSON → 1.3.0 verified Sat Apr 25 auth: no javascript maintenance
A chaining API for markdown-it, similar to webpack-chain, enabling declarative configuration of markdown-it options and plugins. Version 1.3.0 is the latest and only stable release; no further updates are expected. It requires markdown-it >=5.0.0 as a peer dependency. The package provides a fluent, jQuery-like chain for setting HTML/typographer options and registering plugins with before/after ordering. Its key differentiator is providing a structured, webpack-chain-inspired API for markdown-it, which is useful for complex configurations where order of plugins matters. It is not actively maintained and has no built-in TypeScript types.
Common errors
error TypeError: Config is not a constructor ↓
cause Using ES module import (import Config from 'markdown-it-chain') which yields undefined because package has no default export in ESM context.
fix
Switch to CommonJS require: const Config = require('markdown-it-chain'); or use createRequire in ESM.
error Error: Cannot find module 'markdown-it' ↓
cause Missing peer dependency markdown-it which is required at runtime when calling .toMd().
fix
Install markdown-it: npm install markdown-it --save
error TypeError: config.options.html is not a function ↓
cause Using .html() without calling .options chain first; options methods are only available after accessing the ChainedMap via config.options.
fix
Ensure you use config.options.html(...).end(); use .set() if direct access needed.
Warnings
breaking Package is CommonJS-only; ESM environments like Node >=14 with 'type': 'module' require dynamic import or transpilation. ↓
fix Use dynamic import: const Config = (await import('markdown-it-chain')).default; or transpile with bundler.
deprecated No updates since initial 1.3.0 release (2019); consider alternatives like direct markdown-it usage or other configuration helpers. ↓
fix Use plain markdown-it API or evaluate if chaining is needed.
gotcha Plugin ordering via .before() and .after() only works when multiple plugins are added to the same config instance; relative order may confuse. ↓
fix Explicitly call .before() or .after() on the plugin being ordered, referencing the name of the other plugin.
gotcha The .use() method expects an array as second argument (plugin options); omitting array brackets for single option may cause undefined behavior. ↓
fix Always pass plugin options as an array: .use(plugin, [options]) even if single option.
Install
npm install markdown-it-chain yarn add markdown-it-chain pnpm add markdown-it-chain Imports
- default wrong
import Config from 'markdown-it-chain'correctconst Config = require('markdown-it-chain') - Config wrong
import { Config } from 'markdown-it-chain'correctimport Config from 'markdown-it-chain' - ChainedMap wrong
import { ChainedMap } from 'markdown-it-chain'correctnot exported directly; accessed via config.options or config.plugin()
Quickstart
const Config = require('markdown-it-chain');
const config = new Config();
config
.options
.html(true)
.linkify(true)
.end()
.plugin('toc')
.use(require('markdown-it-table-of-contents'), [{ includeLevel: [2, 3] }])
.end()
.plugin('anchor')
.use(require('markdown-it-anchor'), [{ permalink: true, permalinkBefore: true, permalinkSymbol: '$' }])
.before('toc');
const md = config.toMd();
const result = md.render('[[TOC]]\n# h1\n## h2\n## h3');
console.log(result);