diff --git a/packages/shikiji-twoslash/src/renderer-rich.ts b/packages/shikiji-twoslash/src/renderer-rich.ts index 09196e2..ec06064 100644 --- a/packages/shikiji-twoslash/src/renderer-rich.ts +++ b/packages/shikiji-twoslash/src/renderer-rich.ts @@ -74,7 +74,7 @@ export interface RendererRichOptions { * * By default it pass-through the markdown. */ - renderMarkdownInline?(this: ShikijiTransformerContextCommon, markdown: string): ElementContent[] + renderMarkdownInline?(this: ShikijiTransformerContextCommon, markdown: string, context: string): ElementContent[] /** * Extensions for the genreated HAST tree. @@ -276,7 +276,7 @@ export function rendererRich(options: RendererRichOptions = {}): TwoslashRendere properties: { class: 'twoslash-popup-docs-tag-value', }, - children: renderMarkdownInline.call(this, tag[1]), + children: renderMarkdownInline.call(this, tag[1], `tag:${tag[0]}`), }, ] : [], diff --git a/packages/vitepress-plugin-twoslash/src/renderer-floating-vue.ts b/packages/vitepress-plugin-twoslash/src/renderer-floating-vue.ts index 1328265..1e6ea0b 100644 --- a/packages/vitepress-plugin-twoslash/src/renderer-floating-vue.ts +++ b/packages/vitepress-plugin-twoslash/src/renderer-floating-vue.ts @@ -133,7 +133,11 @@ function vPre(el: T): T { } function renderMarkdown(this: ShikijiTransformerContextCommon, md: string): ElementContent[] { - const mdast = fromMarkdown(md, { mdastExtensions: [gfmFromMarkdown()] }) + const mdast = fromMarkdown( + md.replace(/{@link ([^}]*)}/g, '$1'), // replace jsdoc links + { mdastExtensions: [gfmFromMarkdown()] }, + ) + return (toHast( mdast, { @@ -157,12 +161,11 @@ function renderMarkdown(this: ShikijiTransformerContextCommon, md: string): Elem ) as Element).children } -function renderMarkdownInline(this: ShikijiTransformerContext, md: string): ElementContent[] { - const children = renderMarkdown.call( - this, - md - .replace(/{@link ([^}]*)}/g, '$1'), // replace jsdoc links - ) +function renderMarkdownInline(this: ShikijiTransformerContext, md: string, context?: string): ElementContent[] { + if (context === 'tag:param') + md = md.replace(/^([\w$-]+)/, '`$1` ') + + const children = renderMarkdown.call(this, md) if (children.length === 1 && children[0].type === 'element' && children[0].tagName === 'p') return children[0].children return children