mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
docs(build): add a plugin to display the type details (#10435)
This commit is contained in:
@@ -5,6 +5,7 @@ import mdContainer from 'markdown-it-container'
|
||||
import { docRoot } from '@element-plus/build-utils'
|
||||
import externalLinkIcon from '../plugins/external-link-icon'
|
||||
import tableWrapper from '../plugins/table-wrapper'
|
||||
import tooltip from '../plugins/tooltip'
|
||||
import { ApiTableContainer } from '../plugins/api-table'
|
||||
import { highlight } from '../utils/highlight'
|
||||
import type Token from 'markdown-it/lib/token'
|
||||
@@ -27,6 +28,7 @@ interface ContainerOpts {
|
||||
export const mdPlugin = (md: MarkdownIt) => {
|
||||
md.use(externalLinkIcon)
|
||||
md.use(tableWrapper)
|
||||
md.use(tooltip)
|
||||
md.use(mdContainer, 'demo', {
|
||||
validate(params) {
|
||||
return !!params.trim().match(/^demo\s*(.*)$/)
|
||||
|
||||
31
docs/.vitepress/plugins/tooltip.ts
Normal file
31
docs/.vitepress/plugins/tooltip.ts
Normal file
@@ -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
|
||||
})
|
||||
}
|
||||
@@ -12,7 +12,7 @@ defineProps({
|
||||
<code class="api-typing mr-1">
|
||||
{{ type }}
|
||||
</code>
|
||||
<el-tooltip effect="light" trigger="click">
|
||||
<el-tooltip v-if="details" effect="light" trigger="click">
|
||||
<el-button text :icon="Warning" class="p-2 text-4" />
|
||||
<template #content>
|
||||
<slot>
|
||||
|
||||
Reference in New Issue
Block a user