Skip to content

Commit

Permalink
refactor(docs): tooltip plugin (#10440)
Browse files Browse the repository at this point in the history
* refactor(docs): tooltip plugin

* refactor(docs): tooltip plugin
  • Loading branch information
tolking committed Nov 5, 2022
1 parent fe66c08 commit 36c5aed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 3 additions & 5 deletions docs/.vitepress/plugins/tooltip.ts
Expand Up @@ -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
Expand All @@ -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

Expand Down
10 changes: 3 additions & 7 deletions internal/build/src/tasks/helper.ts
Expand Up @@ -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)) {
Expand Down

0 comments on commit 36c5aed

Please sign in to comment.