Include "markdown-it-shiki-twoslash"
in the plugins section of the markdown-it parser:
import shikiTwoslash from "markdown-it-shiki-twoslash"
import MarkdownIt from "markdown-it"
const md = MarkdownIt()
md.use(shikiTwoslash, { theme: "nord" })
const html = md.render(file)
or even better:
import { markdownItShikiTwoslashSetup } from "markdown-it-shiki-twoslash"
import MarkdownIt from "markdown-it"
const md = MarkdownIt()
const shiki = await markdownItShikiTwoslashSetup({
theme: "nord",
})
md.use(shiki)
const html = md.render(file)
Because shiki uses WASM to handle the syntax highlighting, it has to be async code, this clashes with the markdown-it API which enforces synchronous code. In the first code sample, the plugin uses deasync
to convert that async work to sync. It's safe to say that you probably don't want deasync'd code in critical systems.