🐛 fix(vscode): 定义卡片里注释的 [Name] 渲染成链接,按卡片那份文件解析

This commit is contained in:
cruldra committed 2026-10-15 17:36:50 +11:00
1 parent af91b03857
commit bea1f2e679
19 files changed
+319 -151

No files matched your search

@@ -1,22 +1,17 @@
import type { ReactElement } from 'react'
import type { MarkdownKind } from './markdown'
import type { PreviewText } from './types'
import { createContext, memo, useContext, useMemo } from 'react'
import { memo, useMemo } from 'react'
import { cn } from '@/lib/utils'
import { renderMarkdown } from './markdown'
import { SegmentText } from './SegmentText'
/** 卡片里的 Markdown 说明按哪种渲染:页面上是注释;定义卡片浮窗里是 peek(别的文件的注释,不认不带路径的引用)。 */
export const MarkdownKindContext = createContext<Exclude<MarkdownKind, 'answer'>>('comment')
/**
* 预览里的一段文字:着色的词按源码排版;Markdown 说明渲染成段落、列表、代码块。
* `find` 是卡片上这段字的记号(见 [textKey](vscode/webview-ui/src/codeReader/viewState.ts#textKey)),查找栏按它找到这段字画高亮。
*/
export const TextPreview = memo(({ text, className, find }: { text: PreviewText, className?: string, find?: string }): ReactElement => {
const kind = useContext(MarkdownKindContext)
if ('markdown' in text)
return <MarkdownPreview html={renderMarkdown(text.markdown, kind)} className={className} find={find} />
return <MarkdownPreview html={renderMarkdown(text.markdown)} className={className} find={find} />
return (
<p className={cn('cr-code', className)} data-find={find}>
<SegmentText segments={text} />