Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526
  1. /**
  2. * @fileoverview Link component for rendering <a> tags in Markdown.
  3. * Extracted from the main markdown renderer for modularity.
  4. * Handles special rendering for "abbr:" type links for interactive chat actions.
  5. */
  6. import React from 'react'
  7. import { useChatContext } from '@/app/components/base/chat/chat/context'
  8. import { isValidUrl } from './utils'
  9. const Link = ({ node, children, ...props }: any) => {
  10. const { onSend } = useChatContext()
  11. if (node.properties?.href && node.properties.href?.toString().startsWith('abbr')) {
  12. const hidden_text = decodeURIComponent(node.properties.href.toString().split('abbr:')[1])
  13. return <abbr className="cursor-pointer underline !decoration-primary-700 decoration-dashed" onClick={() => onSend?.(hidden_text)} title={node.children[0]?.value || ''}>{node.children[0]?.value || ''}</abbr>
  14. }
  15. else {
  16. const href = props.href || node.properties?.href
  17. if(!isValidUrl(href))
  18. return <span>{children}</span>
  19. return <a href={href} target="_blank" className="cursor-pointer underline !decoration-primary-700 decoration-dashed">{children || 'Download'}</a>
  20. }
  21. }
  22. export default Link