Untitled
unknown
plain_text
10 months ago
749 B
2
Indexable
const formatDescription = (description) => { if (!description) return ''; const urlRegex = /https:\/\/[a-zA-Z0-9.-]+\.pl\/reservation\/[a-zA-Z0-9_-]+/g; const parts = description.split(urlRegex); const matches = [...description.matchAll(urlRegex)]; return parts.reduce((acc, part, index) => { acc.push(<span key={`text-${index}`}>{part}</span>); if (matches[index]) { acc.push( <a key={`link-${index}`} href={matches[index][0]} target="_blank" rel="noopener noreferrer"> {matches[index][0]} </a> ); } return acc; }, []); };
Editor is loading...
Leave a Comment