mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 03:26:01 +08:00
feat: support button in markdown (#9876)
This commit is contained in:
parent
ace7ffab5f
commit
f7aacefcd6
@ -20,6 +20,7 @@ import { useChatContext } from '@/app/components/base/chat/chat/context'
|
|||||||
import VideoGallery from '@/app/components/base/video-gallery'
|
import VideoGallery from '@/app/components/base/video-gallery'
|
||||||
import AudioGallery from '@/app/components/base/audio-gallery'
|
import AudioGallery from '@/app/components/base/audio-gallery'
|
||||||
import SVGRenderer from '@/app/components/base/svg-gallery'
|
import SVGRenderer from '@/app/components/base/svg-gallery'
|
||||||
|
import Button from '@/app/components/base/button'
|
||||||
|
|
||||||
// Available language https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_HLJS.MD
|
// Available language https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_HLJS.MD
|
||||||
const capitalizationLanguageNameMap: Record<string, string> = {
|
const capitalizationLanguageNameMap: Record<string, string> = {
|
||||||
@ -240,6 +241,22 @@ const Link = ({ node, ...props }: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MarkdownButton = ({ node }: any) => {
|
||||||
|
const { onSend } = useChatContext()
|
||||||
|
const variant = node.properties.dataVariant
|
||||||
|
const message = node.properties.dataMessage
|
||||||
|
const size = node.properties.dataSize
|
||||||
|
|
||||||
|
return <Button variant={variant}
|
||||||
|
size={size}
|
||||||
|
className={cn('!h-8 !px-3 select-none')}
|
||||||
|
onClick={() => onSend?.(message)}
|
||||||
|
>
|
||||||
|
<span className='text-[13px]'>{node.children[0].value}</span>
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
MarkdownButton.displayName = 'MarkdownButton'
|
||||||
|
|
||||||
export function Markdown(props: { content: string; className?: string }) {
|
export function Markdown(props: { content: string; className?: string }) {
|
||||||
const latexContent = preprocessLaTeX(props.content)
|
const latexContent = preprocessLaTeX(props.content)
|
||||||
return (
|
return (
|
||||||
@ -271,6 +288,7 @@ export function Markdown(props: { content: string; className?: string }) {
|
|||||||
audio: AudioBlock,
|
audio: AudioBlock,
|
||||||
a: Link,
|
a: Link,
|
||||||
p: Paragraph,
|
p: Paragraph,
|
||||||
|
button: MarkdownButton,
|
||||||
}}
|
}}
|
||||||
linkTarget='_blank'
|
linkTarget='_blank'
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user