export const highlightEntities = (text: string) => { if (!text) return text; const entityPattern = /\[([^\]]+)\]/g; const parts = []; let lastIndex = 0; let match; while ((match = entityPattern.exec(text)) !== null) { if (match.index > lastIndex) { parts.push(text.slice(lastIndex, match.index)); } parts.push( {match[0]} ); lastIndex = match.index + match[0].length; } if (lastIndex < text.length) { parts.push(text.slice(lastIndex)); } return parts.length > 0 ? parts : text; };