Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +31 -12
templates/index.html
CHANGED
|
@@ -82,20 +82,39 @@
|
|
| 82 |
};
|
| 83 |
|
| 84 |
const formatText = (text) => {
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
// Convert ### Role: to **Role**: for styling
|
| 92 |
-
text = text.replace(/###\s*(System|User|Assistant):/g, (_, role) => `<strong>${role}:</strong>`);
|
| 93 |
|
| 94 |
-
return text
|
| 95 |
-
.replace(/\n/g, "<br>")
|
| 96 |
-
.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>")
|
| 97 |
-
.replace(/\*(.*?)\*/g, "<em>$1</em>");
|
| 98 |
-
};
|
| 99 |
|
| 100 |
const renderCode = (text) => {
|
| 101 |
const codeBlocks = text.split(/```/);
|
|
|
|
| 82 |
};
|
| 83 |
|
| 84 |
const formatText = (text) => {
|
| 85 |
+
// Images
|
| 86 |
+
const imageRegex = /\[BASE64_IMAGE_START\](.*?)\[BASE64_IMAGE_END\]/gs;
|
| 87 |
+
text = text.replace(imageRegex, (match, base64) => {
|
| 88 |
+
const src = `data:image/png;base64,${base64.trim()}`;
|
| 89 |
+
return `<img src="${src}" alt="Generated Image" class="chat-image"/>`;
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
// Headings (### becomes <h3>)
|
| 93 |
+
text = text.replace(/^### (.*)$/gm, '<h3>$1</h3>');
|
| 94 |
+
|
| 95 |
+
// Horizontal rule (--- becomes <hr>)
|
| 96 |
+
text = text.replace(/^---$/gm, '<hr>');
|
| 97 |
+
|
| 98 |
+
// Bold (**text**)
|
| 99 |
+
text = text.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
|
| 100 |
+
|
| 101 |
+
// Italics (*text*)
|
| 102 |
+
text = text.replace(/\*(.*?)\*/g, '<em>$1</em>');
|
| 103 |
+
|
| 104 |
+
// Lists (- item)
|
| 105 |
+
text = text.replace(/^- (.*)$/gm, '<li>$1</li>');
|
| 106 |
+
// Wrap list items in <ul> if any <li> found
|
| 107 |
+
if (text.includes('<li>')) {
|
| 108 |
+
text = text.replace(/(<li>.*<\/li>)/gs, '<ul>$1</ul>');
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// Line breaks
|
| 112 |
+
text = text.replace(/\n/g, "<br>");
|
| 113 |
+
|
| 114 |
+
return text;
|
| 115 |
+
};
|
| 116 |
|
|
|
|
|
|
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
const renderCode = (text) => {
|
| 120 |
const codeBlocks = text.split(/```/);
|