Skip to content

Commit

Permalink
feat: support button in markdown (langgenius#9876)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazywoola authored and JunXu01 committed Nov 9, 2024
1 parent a89b40d commit f1f4053
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions web/app/components/base/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useChatContext } from '@/app/components/base/chat/chat/context'
import VideoGallery from '@/app/components/base/video-gallery'
import AudioGallery from '@/app/components/base/audio-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
const capitalizationLanguageNameMap: Record<string, string> = {
Expand Down Expand Up @@ -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 }) {
const latexContent = preprocessLaTeX(props.content)
return (
Expand Down Expand Up @@ -271,6 +288,7 @@ export function Markdown(props: { content: string; className?: string }) {
audio: AudioBlock,
a: Link,
p: Paragraph,
button: MarkdownButton,
}}
linkTarget='_blank'
>
Expand Down

0 comments on commit f1f4053

Please sign in to comment.