import type { PluginSimple } from '@mdit/helper'
import { tab } from '@mdit/plugin-tab'
import { stringifyProp } from './utils.js'
/**
* Markdown-it plugin for tabs
*
* 用于选项卡的 Markdown-it 插件
*
* @param md - MarkdownIt instance / MarkdownIt 实例
*/
export const tabs: PluginSimple = (md) => {
tab(md, {
name: 'tabs',
openRenderer: ({ active, data }, tokens, index) => {
const meta = tokens[index].meta ?? {}
const titles = data.map(({ title }) => md.renderInline(title))
const tabsData = data.map((item) => {
// The default id must be the plain title: the rendered HTML would be
// decoded by the HTML parser before Vue compiles the expression.
const { id = item.title } = item
return { id }
})
return `\
${titles
.map(
(title, titleIndex) => `\
${title}
`,
)
.join('')}\
`
},
closeRenderer: () => `\
`,
tabOpenRenderer: ({ index }) =>
`\
`,
tabCloseRenderer: () => `\
`,
})
}