markdown-it-async
Enhance markdown-it to support async highlight function.
Usage
import MarkdownItAsync from 'markdown-it-async'
const md = MarkdownItAsync({
async highlight(code, lang) {
const { codeToHtml } = await import('shiki')
return await codeToHtml(code, { lang, theme: 'vitesse-dark' })
}
})
const html = await md.renderAsync(markdown)
How it works?
This package is a thin wrapper around markdown-it to support async highlight function. It uses the approch suggested in markdown-it's docs, by putting placeholders in sync mode and then replace them with async results.
The goal is to make it easy to use and absorb the "hack" into the library itself.
Sponsors
License
MIT License © 2024-PRESENT Anthony Fu