mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-14 17:31:02 +08:00
32 lines
865 B
TypeScript
32 lines
865 B
TypeScript
|
import type MarkdownIt from 'markdown-it'
|
||
|
|
||
|
export default (md: MarkdownIt): void => {
|
||
|
md.renderer.rules.tooltip = (tokens, idx) => {
|
||
|
const token = tokens[idx]
|
||
|
|
||
|
return `<api-typing type="${token.content}" details="${token.info}" />`
|
||
|
}
|
||
|
|
||
|
md.inline.ruler.before('emphasis', 'tooltip', (state, silent) => {
|
||
|
const tooltipRegExp = /^\^\[([^\]]*)\](\[[^\]]*\])?/
|
||
|
const str = state.src.slice(state.pos, state.posMax)
|
||
|
|
||
|
if (!tooltipRegExp.test(str)) return false
|
||
|
if (silent) return true
|
||
|
|
||
|
const result = str.match(tooltipRegExp)
|
||
|
|
||
|
if (!result) return false
|
||
|
|
||
|
const token = state.push('tooltip', 'tooltip', 0)
|
||
|
token.content = result[1]
|
||
|
token.info = (result[2] || '')
|
||
|
.replace(/^\[([^\]]*)\]$/, '$1')
|
||
|
.replace(/^`([^`]*)`$/, '$1')
|
||
|
token.level = state.level
|
||
|
state.pos += result[0].length
|
||
|
|
||
|
return true
|
||
|
})
|
||
|
}
|