Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
a8afd7f
1
Parent(s):
8a92b0a
add escape to avoid html being rendered in raw message
Browse files
web_assets/javascript/message-button.js
CHANGED
@@ -20,7 +20,7 @@ function convertBotMessage(gradioButtonMsg) {
|
|
20 |
const part = agentParts[i];
|
21 |
if (i % 2 === 0) {
|
22 |
if (part !== "" && part !== "\n") {
|
23 |
-
finalMessage += `<pre class="fake-pre">${part.trim()}</pre>`;
|
24 |
}
|
25 |
} else {
|
26 |
finalMessage += part.replace(' data-fancybox="gallery"', ''); // 避免 raw message 中的图片被 fancybox 处理
|
|
|
20 |
const part = agentParts[i];
|
21 |
if (i % 2 === 0) {
|
22 |
if (part !== "" && part !== "\n") {
|
23 |
+
finalMessage += `<pre class="fake-pre">${escapeMarkdown(part.trim())}</pre>`;
|
24 |
}
|
25 |
} else {
|
26 |
finalMessage += part.replace(' data-fancybox="gallery"', ''); // 避免 raw message 中的图片被 fancybox 处理
|
web_assets/javascript/utils.js
CHANGED
@@ -15,6 +15,44 @@ function isImgUrl(url) {
|
|
15 |
return false;
|
16 |
}
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
function downloadHistory(gradioUsername, historyname, format=".json") {
|
19 |
let fileUrl;
|
20 |
if (gradioUsername === null || gradioUsername.trim() === "") {
|
|
|
15 |
return false;
|
16 |
}
|
17 |
|
18 |
+
function escapeMarkdown(text) {
|
19 |
+
/*
|
20 |
+
Escape Markdown special characters to HTML-safe equivalents.
|
21 |
+
*/
|
22 |
+
const escapeChars = {
|
23 |
+
// ' ': ' ',
|
24 |
+
"_": "_",
|
25 |
+
"*": "*",
|
26 |
+
"[": "[",
|
27 |
+
"]": "]",
|
28 |
+
"(": "(",
|
29 |
+
")": ")",
|
30 |
+
"{": "{",
|
31 |
+
"}": "}",
|
32 |
+
"#": "#",
|
33 |
+
"+": "+",
|
34 |
+
"-": "-",
|
35 |
+
".": ".",
|
36 |
+
"!": "!",
|
37 |
+
"`": "`",
|
38 |
+
">": ">",
|
39 |
+
"<": "<",
|
40 |
+
"|": "|",
|
41 |
+
"$": "$",
|
42 |
+
":": ":",
|
43 |
+
};
|
44 |
+
|
45 |
+
text = text.replace(/ {4}/g, " "); // Replace 4 spaces with non-breaking spaces
|
46 |
+
|
47 |
+
let escapedText = "";
|
48 |
+
for (let i = 0; i < text.length; i++) {
|
49 |
+
const currentChar = text.charAt(i);
|
50 |
+
escapedText += escapeChars[currentChar] || currentChar;
|
51 |
+
}
|
52 |
+
|
53 |
+
return escapedText;
|
54 |
+
}
|
55 |
+
|
56 |
function downloadHistory(gradioUsername, historyname, format=".json") {
|
57 |
let fileUrl;
|
58 |
if (gradioUsername === null || gradioUsername.trim() === "") {
|