WebIndex/plugins/markdown-it.ts
2025-01-24 00:44:37 +08:00

33 lines
707 B
TypeScript

import md, { type Options } from 'markdown-it'
import mm from 'markdown-it-mathjax3'
import anchor from 'markdown-it-anchor'
import toc from 'markdown-it-toc-done-right'
const options: Options = {
breaks: true,
html: true,
langPrefix: 'language-',
linkify: true,
quotes: '“”‘’',
typographer: true,
xhtmlOut: true,
}
export default defineNuxtPlugin(() => {
const render = md(options)
.use(mm, {
})
.use(anchor, {
})
.use(toc, {
containerId: 'toc',
itemClass: 'truncate',
// format: (x: string, fn: (s: string) => string) => `<!--<span class="truncate">${fn(x)}</span>-->`,
})
return {
provide: {
mdRender: render,
},
}
})