import React from "react"; import { Link } from "react-router-dom"; const URL_REGEX = /(https?:\/\/[^\s]+)/g; export default function RichText({ text }) { if (!text) return null; const parts = text.split(URL_REGEX); return (

{parts.map((part, i) => { if (part.match(URL_REGEX)) { return ( e.stopPropagation()} className="rich-text-link" > {part} ); } const subParts = part.split(/((?:^|\s)@[a-zA-Z0-9.-]+\b)/g); return ( {subParts.map((subPart, j) => { const mentionMatch = subPart.match(/^(\s*)@([a-zA-Z0-9.-]+)$/); if (mentionMatch) { const prefix = mentionMatch[1]; const handle = mentionMatch[2]; if (handle.includes(".")) { return ( {prefix} e.stopPropagation()} > @{handle} ); } } return subPart; })} ); })}

); }