Spaces:
Running
Running
Update src/components/MessageBubble.jsx
Browse files- src/components/MessageBubble.jsx +16 -16
src/components/MessageBubble.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import React from 'react';
|
| 2 |
import CodeBlock from './CodeBlock';
|
| 3 |
|
| 4 |
-
|
| 5 |
// ✅ Handle base64 images
|
| 6 |
const imageRegex = /\[IMAGE_START\](.*?)\[IMAGE_END\]/gs;
|
| 7 |
text = text.replace(imageRegex, (match, base64) => {
|
|
@@ -40,21 +40,21 @@ import CodeBlock from './CodeBlock';
|
|
| 40 |
};
|
| 41 |
text = text.replace(/:([a-z0-9_+-]+):/g, (match, name) => emojiMap[name] || match);
|
| 42 |
// ✅ Unordered list (bullets)
|
| 43 |
-
const listify = (lines, tag) =>
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
);
|
| 58 |
// ✅ Markdown-style tables
|
| 59 |
text = text.replace(
|
| 60 |
/^\|(.+?)\|\n\|([-:| ]+)\|\n((?:\|.*\|\n?)*)/gm,
|
|
|
|
| 1 |
import React from 'react';
|
| 2 |
import CodeBlock from './CodeBlock';
|
| 3 |
|
| 4 |
+
const formatText = (text) => {
|
| 5 |
// ✅ Handle base64 images
|
| 6 |
const imageRegex = /\[IMAGE_START\](.*?)\[IMAGE_END\]/gs;
|
| 7 |
text = text.replace(imageRegex, (match, base64) => {
|
|
|
|
| 40 |
};
|
| 41 |
text = text.replace(/:([a-z0-9_+-]+):/g, (match, name) => emojiMap[name] || match);
|
| 42 |
// ✅ Unordered list (bullets)
|
| 43 |
+
const listify = (lines, tag) =>
|
| 44 |
+
`<${tag}>` +
|
| 45 |
+
lines.map(item => `<li>${item.replace(/^(\-|\d+\.)\s*/, '').trim()}</li>`).join('') +
|
| 46 |
+
`</${tag}>`;
|
| 47 |
+
text = text.replace(
|
| 48 |
+
/((?:^[-*] .+(?:\n|$))+)/gm,
|
| 49 |
+
(match) => listify(match.trim().split('\n'), 'ul')
|
| 50 |
+
);
|
| 51 |
+
// ✅ Ordered list (fix separate `1.` items issue)
|
| 52 |
+
text = text.replace(/^(\d+\. .+)$/gm, '__ORDERED__START__$1__ORDERED__END__');
|
| 53 |
+
text = text.replace(
|
| 54 |
+
/__ORDERED__START__(\d+\. .+?)__ORDERED__END__/gs,
|
| 55 |
+
(_, line) => `<ol><li>${line.replace(/^\d+\.\s*/, '')}</li></ol>`
|
| 56 |
+
);
|
| 57 |
+
text = text.replace(/<\/ol>\s*<ol>/g, '');
|
| 58 |
// ✅ Markdown-style tables
|
| 59 |
text = text.replace(
|
| 60 |
/^\|(.+?)\|\n\|([-:| ]+)\|\n((?:\|.*\|\n?)*)/gm,
|