Skip to content

Rendering

markdown-exit compatible with markdown-it render API and supports async rendering out of the box.

Basic Usage

ts
import { createMarkdownExit } from 'markdown-exit'

const md = createMarkdownExit()
const html = md.render('# Hello World')

Inline Rendering

Render inline markdown content without paragraph wrapping.

ts
const html = md.renderInline('**markdown-exit** is awesome!')

Syntax Highlighting

You can provide a custom syntax highlighter function via the highlight option.

ts
import { createHighlighterCoreSync } from 'shiki/core'
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'

const shiki = createHighlighterCoreSync({
  themes: [nord],
  langs: [js],
  engine: createJavaScriptRegexEngine()
})

const md = createMarkdownExit({
  highlight(str, lang) {
    return shiki.highlight(str, { lang, theme: 'nord' })
  }
})

Async Rendering

If your highlight or any render rules are asynchronous, you can use renderAsync or renderInlineAsync to render markdown asynchronously for better performance.

For example, multiple code blocks highlighted with an async highlighter (like Shiki) can be processed in parallel to speed up rendering.

ts
import { codeToHtml } from 'shiki'

const md = createMarkdownExit({
  async highlight(code, lang) {
    return await codeToHtml(code, { lang, theme: 'nord' })
  }
})

const html = await md.renderAsync(markdown)

Thanks Anthony Fu for inspiring async rendering by markdown-it-async.

Released under the MIT License.