refactor(docs): tooltip plugin (#10440)

* refactor(docs): tooltip plugin

* refactor(docs): tooltip plugin
This commit is contained in:
qiang 2022-11-05 15:15:29 +08:00 committed by GitHub
parent fe66c08fa5
commit 36c5aed076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 12 deletions

View File

@ -8,7 +8,7 @@ export default (md: MarkdownIt): void => {
}
md.inline.ruler.before('emphasis', 'tooltip', (state, silent) => {
const tooltipRegExp = /^\^\[([^\]]*)\](\[[^\]]*\])?/
const tooltipRegExp = /^\^\[([^\]]*)\](`[^`]*`)?/
const str = state.src.slice(state.pos, state.posMax)
if (!tooltipRegExp.test(str)) return false
@ -19,10 +19,8 @@ export default (md: MarkdownIt): void => {
if (!result) return false
const token = state.push('tooltip', 'tooltip', 0)
token.content = result[1]
token.info = (result[2] || '')
.replace(/^\[([^\]]*)\]$/, '$1')
.replace(/^`([^`]*)`$/, '$1')
token.content = result[1].replace(/\\\|/g, '|')
token.info = (result[2] || '').replace(/^`(.*)`$/, '$1')
token.level = state.level
state.pos += result[0].length

View File

@ -126,14 +126,10 @@ const findModule = (type: string): string | undefined => {
}
const rewriteType = (str: string): string => {
if (/\^\[/.test(str)) {
if (/\^\[([^\]]*)\](`[^`]*`)?/.test(str)) {
return str
.replaceAll(/\^\[([^\]]*)\](\[[^\]]*\])?/g, (_, type, details) => {
return (
(details || '')
.replace(/^\[([^\]]*)\]$/, '$1')
.replace(/^`([^`]*)`$/, '$1') || type
)
.replaceAll(/\^\[([^\]]*)\](`[^`]*`)?/g, (_, type, details) => {
return details ? details.replace(/^`(.*)`$/, '$1') : type
})
.replaceAll(/\[[^\]]*\]\([^)]*\)/g, '')
} else if (/<.*>/.test(str)) {