Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +101 -44
templates/index.html
CHANGED
|
@@ -206,6 +206,48 @@
|
|
| 206 |
margin-top: 4px;
|
| 207 |
display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
|
| 208 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
/* ββ Vote ββ */
|
| 210 |
.vote-row { display: flex; gap: 4px; align-items: center; margin-top: 6px; }
|
| 211 |
.vote-btn {
|
|
@@ -879,45 +921,75 @@
|
|
| 879 |
function renderInlineMarkdown(s) {
|
| 880 |
let out = esc(String(s || ""));
|
| 881 |
out = out.replace(/`([^`]+)`/g, "<code>$1</code>");
|
|
|
|
|
|
|
| 882 |
out = out.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
|
| 883 |
-
out = out.replace(/
|
|
|
|
|
|
|
|
|
|
| 884 |
out = out.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noreferrer">$1</a>');
|
| 885 |
return out;
|
| 886 |
}
|
| 887 |
function renderMarkdown(md) {
|
| 888 |
const lines = String(md || "").replace(/\r\n/g, "\n").split("\n");
|
| 889 |
const out = [];
|
| 890 |
-
let inList = false;
|
| 891 |
-
|
|
|
|
| 892 |
const closeBlocks = () => {
|
| 893 |
-
if (inList)
|
|
|
|
| 894 |
if (inQuote) { out.push("</blockquote>"); inQuote = false; }
|
| 895 |
};
|
| 896 |
for (const raw of lines) {
|
| 897 |
const line = raw.trimEnd();
|
| 898 |
-
if (
|
| 899 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 900 |
closeBlocks();
|
| 901 |
-
const
|
| 902 |
-
out.push(`<h${
|
| 903 |
continue;
|
| 904 |
}
|
| 905 |
-
if (/^
|
| 906 |
-
|
|
|
|
|
|
|
| 907 |
if (!inQuote) { out.push("<blockquote>"); inQuote = true; }
|
| 908 |
-
out.push(`<p>${renderInlineMarkdown(line.replace(/^>
|
| 909 |
continue;
|
| 910 |
}
|
| 911 |
if (/^[-*]\s+/.test(line)) {
|
| 912 |
-
if (inQuote)
|
| 913 |
-
if (
|
|
|
|
| 914 |
out.push(`<li>${renderInlineMarkdown(line.replace(/^[-*]\s+/, ""))}</li>`);
|
| 915 |
continue;
|
| 916 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 917 |
closeBlocks();
|
| 918 |
out.push(`<p>${renderInlineMarkdown(line)}</p>`);
|
| 919 |
}
|
| 920 |
closeBlocks();
|
|
|
|
| 921 |
return out.join("");
|
| 922 |
}
|
| 923 |
function fmtTime(iso) {
|
|
@@ -958,45 +1030,30 @@
|
|
| 958 |
async function animateText(el, text) {
|
| 959 |
if (!el) return;
|
| 960 |
const mode = S.animMode;
|
| 961 |
-
const
|
| 962 |
-
|
| 963 |
-
ai: { size: 10, delay: 60 },
|
| 964 |
-
human: { size: 5, delay: 90 },
|
| 965 |
-
diffusion: { size: 2, delay: 130 },
|
| 966 |
-
"diffusion-v2": { size: 1, delay: 170 },
|
| 967 |
-
};
|
| 968 |
-
const cfg = configs[mode] || configs.ai;
|
| 969 |
el.classList.remove("answer-reveal", "revealed");
|
|
|
|
| 970 |
if (mode === "none") {
|
| 971 |
-
el.innerHTML =
|
| 972 |
setJumpLatest(false);
|
| 973 |
return;
|
| 974 |
}
|
| 975 |
-
const
|
| 976 |
-
|
| 977 |
-
const parts = [];
|
| 978 |
-
let wordCount = 0;
|
| 979 |
-
for (const part of words) {
|
| 980 |
-
buffer += part;
|
| 981 |
-
if (!/^\s+$/.test(part)) wordCount += 1;
|
| 982 |
-
if (wordCount >= cfg.size && buffer.trim()) {
|
| 983 |
-
parts.push(buffer);
|
| 984 |
-
buffer = "";
|
| 985 |
-
wordCount = 0;
|
| 986 |
-
}
|
| 987 |
-
}
|
| 988 |
-
if (buffer) parts.push(buffer);
|
| 989 |
el.innerHTML = "";
|
| 990 |
-
for (const
|
| 991 |
-
const
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
|
|
|
|
|
|
|
|
|
| 996 |
scrollBottom();
|
| 997 |
-
await sleep(
|
| 998 |
}
|
| 999 |
-
el.innerHTML = renderMarkdown(text);
|
| 1000 |
}
|
| 1001 |
function showTyping() {
|
| 1002 |
removeTyping();
|
|
|
|
| 206 |
margin-top: 4px;
|
| 207 |
display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
|
| 208 |
}
|
| 209 |
+
/* ββ Markdown rendered elements ββ */
|
| 210 |
+
.bubble p,.best-answer-bubble p,.other-answer-text p,.version-text p { margin: 3px 0; white-space: normal; }
|
| 211 |
+
.bubble h1,.bubble h2,.bubble h3,.bubble h4,.bubble h5,.bubble h6,
|
| 212 |
+
.best-answer-bubble h1,.best-answer-bubble h2,.best-answer-bubble h3,
|
| 213 |
+
.best-answer-bubble h4,.best-answer-bubble h5,.best-answer-bubble h6,
|
| 214 |
+
.other-answer-text h1,.other-answer-text h2,.other-answer-text h3,
|
| 215 |
+
.version-text h1,.version-text h2,.version-text h3 {
|
| 216 |
+
font-weight: 700; line-height: 1.3; margin: 6px 0 2px; white-space: normal;
|
| 217 |
+
}
|
| 218 |
+
.bubble h1,.best-answer-bubble h1 { font-size: 1.15em; }
|
| 219 |
+
.bubble h2,.best-answer-bubble h2 { font-size: 1.05em; }
|
| 220 |
+
.bubble h3,.best-answer-bubble h3 { font-size: .97em; }
|
| 221 |
+
.bubble h4,.best-answer-bubble h4,.bubble h5,.best-answer-bubble h5,.bubble h6,.best-answer-bubble h6 { font-size: .9em; }
|
| 222 |
+
.bubble ul,.bubble ol,.best-answer-bubble ul,.best-answer-bubble ol,
|
| 223 |
+
.other-answer-text ul,.other-answer-text ol,.version-text ul,.version-text ol {
|
| 224 |
+
margin: 3px 0 3px 18px; padding: 0; white-space: normal;
|
| 225 |
+
}
|
| 226 |
+
.bubble li,.best-answer-bubble li,.other-answer-text li,.version-text li { margin: 1px 0; white-space: normal; }
|
| 227 |
+
.bubble code,.best-answer-bubble code,.other-answer-text code,.version-text code {
|
| 228 |
+
font-family: var(--mono); font-size: .87em;
|
| 229 |
+
background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1);
|
| 230 |
+
border-radius: 4px; padding: 1px 5px;
|
| 231 |
+
}
|
| 232 |
+
.bubble pre,.best-answer-bubble pre,.other-answer-text pre,.version-text pre {
|
| 233 |
+
background: rgba(0,0,0,.38); border: 1px solid var(--border);
|
| 234 |
+
border-radius: var(--radius-sm); padding: 10px 12px;
|
| 235 |
+
overflow-x: auto; margin: 6px 0; white-space: pre;
|
| 236 |
+
font-family: var(--mono); font-size: .84em; line-height: 1.5;
|
| 237 |
+
}
|
| 238 |
+
.bubble pre code,.best-answer-bubble pre code,.other-answer-text pre code,.version-text pre code {
|
| 239 |
+
background: none; border: none; padding: 0; font-size: inherit;
|
| 240 |
+
}
|
| 241 |
+
.bubble blockquote,.best-answer-bubble blockquote,
|
| 242 |
+
.other-answer-text blockquote,.version-text blockquote {
|
| 243 |
+
border-left: 3px solid var(--accent); margin: 4px 0;
|
| 244 |
+
padding: 2px 0 2px 12px; color: var(--muted); white-space: normal;
|
| 245 |
+
}
|
| 246 |
+
.bubble hr,.best-answer-bubble hr { border: none; border-top: 1px solid var(--border2); margin: 8px 0; }
|
| 247 |
+
.bubble a,.best-answer-bubble a,.other-answer-text a,.version-text a {
|
| 248 |
+
color: var(--accent); text-decoration: underline; text-underline-offset: 2px;
|
| 249 |
+
}
|
| 250 |
+
p.md-gap { min-height: 0.6em; margin: 0 !important; padding: 0; }
|
| 251 |
/* ββ Vote ββ */
|
| 252 |
.vote-row { display: flex; gap: 4px; align-items: center; margin-top: 6px; }
|
| 253 |
.vote-btn {
|
|
|
|
| 921 |
function renderInlineMarkdown(s) {
|
| 922 |
let out = esc(String(s || ""));
|
| 923 |
out = out.replace(/`([^`]+)`/g, "<code>$1</code>");
|
| 924 |
+
out = out.replace(/\*\*\*([^*]+)\*\*\*/g, "<strong><em>$1</em></strong>");
|
| 925 |
+
out = out.replace(/___([^_]+)___/g, "<strong><em>$1</em></strong>");
|
| 926 |
out = out.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
|
| 927 |
+
out = out.replace(/__([^_]+)__/g, "<strong>$1</strong>");
|
| 928 |
+
out = out.replace(/\*([^*\s][^*]*[^*\s]|\S)\*/g, "<em>$1</em>");
|
| 929 |
+
out = out.replace(/_([^_\s][^_]*[^_\s]|\S)_/g, "<em>$1</em>");
|
| 930 |
+
out = out.replace(/~~([^~]+)~~/g, "<s>$1</s>");
|
| 931 |
out = out.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noreferrer">$1</a>');
|
| 932 |
return out;
|
| 933 |
}
|
| 934 |
function renderMarkdown(md) {
|
| 935 |
const lines = String(md || "").replace(/\r\n/g, "\n").split("\n");
|
| 936 |
const out = [];
|
| 937 |
+
let inList = false, inOList = false, inQuote = false, inCode = false;
|
| 938 |
+
const codeBuf = [];
|
| 939 |
+
let lastWasBlank = false;
|
| 940 |
const closeBlocks = () => {
|
| 941 |
+
if (inList) { out.push("</ul>"); inList = false; }
|
| 942 |
+
if (inOList) { out.push("</ol>"); inOList = false; }
|
| 943 |
if (inQuote) { out.push("</blockquote>"); inQuote = false; }
|
| 944 |
};
|
| 945 |
for (const raw of lines) {
|
| 946 |
const line = raw.trimEnd();
|
| 947 |
+
if (inCode) {
|
| 948 |
+
if (/^```/.test(line)) { out.push(`<pre><code>${codeBuf.join("\n")}</code></pre>`); codeBuf.length = 0; inCode = false; }
|
| 949 |
+
else codeBuf.push(esc(line));
|
| 950 |
+
continue;
|
| 951 |
+
}
|
| 952 |
+
if (/^```/.test(line)) { closeBlocks(); inCode = true; continue; }
|
| 953 |
+
if (!line.trim()) {
|
| 954 |
+
closeBlocks();
|
| 955 |
+
if (!lastWasBlank) out.push('<p class="md-gap"></p>');
|
| 956 |
+
lastWasBlank = true;
|
| 957 |
+
continue;
|
| 958 |
+
}
|
| 959 |
+
lastWasBlank = false;
|
| 960 |
+
if (/^#{1,6}\s/.test(line)) {
|
| 961 |
closeBlocks();
|
| 962 |
+
const lvl = Math.min(6, line.match(/^#+/)[0].length);
|
| 963 |
+
out.push(`<h${lvl}>${renderInlineMarkdown(line.replace(/^#+\s+/, ""))}</h${lvl}>`);
|
| 964 |
continue;
|
| 965 |
}
|
| 966 |
+
if (/^(-{3,}|\*{3,}|_{3,})$/.test(line.trim())) { closeBlocks(); out.push("<hr>"); continue; }
|
| 967 |
+
if (/^> ?/.test(line)) {
|
| 968 |
+
if (inList) { out.push("</ul>"); inList = false; }
|
| 969 |
+
if (inOList) { out.push("</ol>"); inOList = false; }
|
| 970 |
if (!inQuote) { out.push("<blockquote>"); inQuote = true; }
|
| 971 |
+
out.push(`<p>${renderInlineMarkdown(line.replace(/^> ?/, ""))}</p>`);
|
| 972 |
continue;
|
| 973 |
}
|
| 974 |
if (/^[-*]\s+/.test(line)) {
|
| 975 |
+
if (inQuote) { out.push("</blockquote>"); inQuote = false; }
|
| 976 |
+
if (inOList) { out.push("</ol>"); inOList = false; }
|
| 977 |
+
if (!inList) { out.push("<ul>"); inList = true; }
|
| 978 |
out.push(`<li>${renderInlineMarkdown(line.replace(/^[-*]\s+/, ""))}</li>`);
|
| 979 |
continue;
|
| 980 |
}
|
| 981 |
+
if (/^\d+\.\s+/.test(line)) {
|
| 982 |
+
if (inQuote) { out.push("</blockquote>"); inQuote = false; }
|
| 983 |
+
if (inList) { out.push("</ul>"); inList = false; }
|
| 984 |
+
if (!inOList) { out.push("<ol>"); inOList = true; }
|
| 985 |
+
out.push(`<li>${renderInlineMarkdown(line.replace(/^\d+\.\s+/, ""))}</li>`);
|
| 986 |
+
continue;
|
| 987 |
+
}
|
| 988 |
closeBlocks();
|
| 989 |
out.push(`<p>${renderInlineMarkdown(line)}</p>`);
|
| 990 |
}
|
| 991 |
closeBlocks();
|
| 992 |
+
if (inCode) out.push(`<pre><code>${codeBuf.join("\n")}</code></pre>`);
|
| 993 |
return out.join("");
|
| 994 |
}
|
| 995 |
function fmtTime(iso) {
|
|
|
|
| 1030 |
async function animateText(el, text) {
|
| 1031 |
if (!el) return;
|
| 1032 |
const mode = S.animMode;
|
| 1033 |
+
const delays = { none: 0, ai: 60, human: 90, diffusion: 130, "diffusion-v2": 170 };
|
| 1034 |
+
const delay = delays[mode] ?? 60;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1035 |
el.classList.remove("answer-reveal", "revealed");
|
| 1036 |
+
const html = renderMarkdown(text);
|
| 1037 |
if (mode === "none") {
|
| 1038 |
+
el.innerHTML = html;
|
| 1039 |
setJumpLatest(false);
|
| 1040 |
return;
|
| 1041 |
}
|
| 1042 |
+
const tmp = document.createElement("div");
|
| 1043 |
+
tmp.innerHTML = html;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1044 |
el.innerHTML = "";
|
| 1045 |
+
for (const node of Array.from(tmp.childNodes)) {
|
| 1046 |
+
const n = node.cloneNode(true);
|
| 1047 |
+
if (n.nodeType === 1) {
|
| 1048 |
+
n.classList.add("answer-reveal");
|
| 1049 |
+
el.appendChild(n);
|
| 1050 |
+
requestAnimationFrame(() => n.classList.add("revealed"));
|
| 1051 |
+
} else {
|
| 1052 |
+
el.appendChild(n);
|
| 1053 |
+
}
|
| 1054 |
scrollBottom();
|
| 1055 |
+
await sleep(delay);
|
| 1056 |
}
|
|
|
|
| 1057 |
}
|
| 1058 |
function showTyping() {
|
| 1059 |
removeTyping();
|