mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-15 02:40:46 +08:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
|
import markdown from 'markdown-it'
|
||
|
|
||
|
import type MarkdownIt from 'markdown-it'
|
||
|
|
||
|
const ApiMd = new markdown()
|
||
|
|
||
|
export const ApiTableContainer = (md: MarkdownIt) => {
|
||
|
const fence = md.renderer.rules.fence!
|
||
|
|
||
|
ApiMd.renderer.rules = md.renderer.rules
|
||
|
md.renderer.rules.fence = (...args) => {
|
||
|
const [tokens, idx, ...rest] = args
|
||
|
const [options, env] = rest
|
||
|
const token = tokens[idx]
|
||
|
if (token.info === 'api') {
|
||
|
const newTokens = md.parse(token.content, env)
|
||
|
|
||
|
let result = ''
|
||
|
const { rules } = md.renderer
|
||
|
newTokens.forEach((newToken, idx) => {
|
||
|
const { type } = newToken
|
||
|
if (type === 'inline') {
|
||
|
result += md.renderer.renderInline(newToken.children!, options, env)
|
||
|
} else if (typeof rules[type] !== 'undefined') {
|
||
|
result += rules[newToken.type]!(
|
||
|
newTokens,
|
||
|
idx,
|
||
|
options,
|
||
|
env,
|
||
|
md.renderer
|
||
|
)
|
||
|
} else {
|
||
|
result += md.renderer.renderToken(newTokens, idx, options)
|
||
|
}
|
||
|
})
|
||
|
return result
|
||
|
}
|
||
|
return fence.call(md, ...args)
|
||
|
}
|
||
|
}
|