markdown-it-enhancer
v15.1.0
Published
Markdown-it - modern pluggable markdown parser.
Maintainers
Readme
markdown-it-enhancer
This is a fork from markdown-it, there are some changes in this fork:
- ESM only.
- Source code migrate to TypeScript, now you don't need to install
@types/markdown-it. - Using vite to bundle, vitest to test.
- Async support. include parser rule, render rule, plugins,
highlightfunction.
Version
In order to sync the update of upstream, the patch version of this fork would start with 100.
Example:
When There are some fix in this fork. It will:
Install
npm install markdown-it-enchacer
# yarn add markdown-it-enchacer
# pnpm add markdown-it-enchacerAsync Parser Rule
import { MarkdownIt } from "markdown-it-enchancer";
// delay s seconds.
const delay = (s) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, s * 1000);
});
};
const md = new MarkdownIt();
// push a async ruler
md.block.ruler.push(
"async_rule",
async (_state, _startLine, _endLine, _slient) => {
// async operation
await delay(3);
},
);Async render rule
import { MarkdownIt } from "markdown-it-enchancer";
// delay s seconds.
const delay = (s) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, s * 1000);
});
};
const md = new MarkdownIt();
// set a async render rule.
md.renderer.rules.test = async (tokens, idx, options, env, renderer) => {
// some async operation
await delay(3);
return "test";
};Async plugin
import { MarkdownIt } from "markdown-it-enchancer";
// delay s seconds.
const delay = (s) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, s * 1000);
});
};
const md = new MarkdownIt();
md
.use(async (md, arg1, arg2) => {
// some async operation
await delay(3);
}, 'arg1', 'arg2')
.use(async (md, arg1, arg2) => {
// some async operation
await delay(3);
}, 'arg1', 'arg2')
.use(async (md, arg1, arg2) => {
// some async operation
await delay(3);
}, 'arg1', 'arg2');
// you must exec `await md.isReady()` to ensure the initializations of all plugins are success.
await md.isReady();Async highlight function
import { MarkdownIt } from "markdown-it-enchancer";
// delay s seconds.
const delay = (s) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, s * 1000);
});
};
const md = new MarkdownIt({
async highlight() {
// async operation
await delay(3);
return "highlight function";
}
});Others
maxAutoCompletedCells
Env support maxAutoCompletedCells property. See #1000
import { MarkdownIt } from "markdown-it-enchancer";
const md = new MarkdownIt();
md.render('md content', {
maxAutoCompletedCells: 100
});Plugins
There are some plugins that migrate to markdown-it-enhancer.
- markdown-it-katex -> markdown-it-katex-for-enhancer
- markdown-it-attrs -> markdown-it-attrs-for-enhancer
- markdown-it-anchor -> markdown-it-anchor-for-enhancer
- markdown-it-implicit-figures -> markdown-it-implicit-figures-for-enhancer
- markdown-it-sup -> markdown-it-sup-for-enhancer
- markdown-it-emoji -> markdown-it-emoji-for-enhancer
- markdown-it-task-lists -> markdown-it-task-lists-for-enhancer
- markdown-it-container -> markdown-it-container-for-enhancer
- markdown-it-sub -> markdown-it-sub-for-enhancer
- markdown-it-abbr -> markdown-it-abbr-for-enhancer
- markdown-it-for-inline -> markdown-it-for-inline-for-enhancer
