diff --git a/web/app/components/base/markdown-blocks/link.tsx b/web/app/components/base/markdown-blocks/link.tsx index 458d455516..0274ee0141 100644 --- a/web/app/components/base/markdown-blocks/link.tsx +++ b/web/app/components/base/markdown-blocks/link.tsx @@ -9,17 +9,34 @@ import { isValidUrl } from './utils' const Link = ({ node, children, ...props }: any) => { const { onSend } = useChatContext() + const commonClassName = 'cursor-pointer underline !decoration-primary-700 decoration-dashed' if (node.properties?.href && node.properties.href?.toString().startsWith('abbr')) { const hidden_text = decodeURIComponent(node.properties.href.toString().split('abbr:')[1]) - return onSend?.(hidden_text)} title={node.children[0]?.value || ''}>{node.children[0]?.value || ''} + return onSend?.(hidden_text)} title={node.children[0]?.value || ''}>{node.children[0]?.value || ''} } else { const href = props.href || node.properties?.href - if(!href || !isValidUrl(href)) + if (href && /^#[a-zA-Z0-9_\-]+$/.test(href.toString())) { + const handleClick = (e: React.MouseEvent) => { + e.preventDefault() + // scroll to target element if exists within the answer container + const answerContainer = e.currentTarget.closest('.chat-answer-container') + + if (answerContainer) { + const targetId = CSS.escape(href.toString().substring(1)) + const targetElement = answerContainer.querySelector(`[id="${targetId}"]`) + if (targetElement) + targetElement.scrollIntoView({ behavior: 'smooth' }) + } + } + return {children || 'ScrollView'} + } + + if (!href || !isValidUrl(href)) return {children} - return {children || 'Download'} + return {children || 'Download'} } }