Skip to content

Commit

Permalink
feat: support opening new tab in markdown button (#12213)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 authored Dec 30, 2024
1 parent 5624507 commit ab469aa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion web/app/components/base/markdown-blocks/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,30 @@ const MarkdownButton = ({ node }: any) => {
const { onSend } = useChatContext()
const variant = node.properties.dataVariant
const message = node.properties.dataMessage
const link = node.properties.dataLink
const size = node.properties.dataSize

function is_valid_url(url: string): boolean {
try {
const parsed_url = new URL(url)
return ['http:', 'https:'].includes(parsed_url.protocol)
}
catch {
return false
}
}

return <Button
variant={variant}
size={size}
className={cn('!h-8 !px-3 select-none')}
onClick={() => onSend?.(message)}
onClick={() => {
if (is_valid_url(link)) {
window.open(link, '_blank')
return
}
onSend?.(message)
}}
>
<span className='text-[13px]'>{node.children[0]?.value || ''}</span>
</Button>
Expand Down

0 comments on commit ab469aa

Please sign in to comment.