-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(build): add a plugin to display the type details (#10435)
- Loading branch information
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters