(content)
| 210 | }; |
| 211 | |
| 212 | export const formatStreamingMessage = (content) => { |
| 213 | if (!content) return ""; |
| 214 | |
| 215 | try { |
| 216 | let textContent = String(content || ""); |
| 217 | |
| 218 | textContent = textContent.trim(); |
| 219 | |
| 220 | textContent = textContent.replace(/\n{3,}/g, "\n\n"); |
| 221 | |
| 222 | textContent = textContent.replace( |
| 223 | /([^`\n])([ ]{2,})([^`\n])/g, |
| 224 | "$1 $3", |
| 225 | ); |
| 226 | |
| 227 | const html = marked.parse(textContent, { async: false }); |
| 228 | return sanitizeRenderedHtml(renderMath(html)); |
| 229 | } catch (error) { |
| 230 | console.error("Streaming markdown rendering error:", error); |
| 231 | return escapeHtml(String(content)); |
| 232 | } |
| 233 | }; |
no test coverage detected