🐛 fix(vscode): 代码阅读的 Markdown 预览固定同一份 HTML,悬停链接不再闪
This commit is contained in:
1 parent
079657da37
commit
3abc87dbef
5 files changed
+256
-10
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { ReactElement } from 'react'
|
||||
import type { MarkdownKind } from './markdown'
|
||||
import type { PreviewText } from './types'
|
||||
import { createContext, useContext } from 'react'
|
||||
import { createContext, useContext, useMemo } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { renderMarkdown } from './markdown'
|
||||
import { SegmentText } from './SegmentText'
|
||||
@@ -13,10 +13,15 @@ export const MarkdownKindContext = createContext<Exclude<MarkdownKind, 'answer'>
|
||||
export function TextPreview({ text, className }: { text: PreviewText, className?: string }): ReactElement {
|
||||
const kind = useContext(MarkdownKindContext)
|
||||
if ('markdown' in text)
|
||||
return <div className={cn('cr-markdown', className)} dangerouslySetInnerHTML={{ __html: renderMarkdown(text.markdown, kind) }} />
|
||||
return <MarkdownPreview html={renderMarkdown(text.markdown, kind)} className={className} />
|
||||
return (
|
||||
<p className={cn('cr-code', className)}>
|
||||
<SegmentText segments={text} />
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
export function MarkdownPreview({ html, className }: { html: string, className?: string }): ReactElement {
|
||||
const content = useMemo(() => ({ __html: html }), [html])
|
||||
return <div className={cn('cr-markdown', className)} dangerouslySetInnerHTML={content} />
|
||||
}
|
||||
Reference in new issue
Block a user