Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +16 -3
templates/index.html
CHANGED
|
@@ -931,7 +931,21 @@
|
|
| 931 |
}
|
| 932 |
function nl2br(s) { return esc(s).replace(/\n/g, "<br>"); }
|
| 933 |
function renderInlineMarkdown(s) {
|
| 934 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 935 |
out = out.replace(/`([^`]+)`/g, "<code>$1</code>");
|
| 936 |
out = out.replace(/\*\*\*([^*]+)\*\*\*/g, "<strong><em>$1</em></strong>");
|
| 937 |
out = out.replace(/___([^_]+)___/g, "<strong><em>$1</em></strong>");
|
|
@@ -940,8 +954,7 @@
|
|
| 940 |
out = out.replace(/\*([^*\s][^*]*[^*\s]|\S)\*/g, "<em>$1</em>");
|
| 941 |
out = out.replace(/_([^_\s][^_]*[^_\s]|\S)_/g, "<em>$1</em>");
|
| 942 |
out = out.replace(/~~([^~]+)~~/g, "<s>$1</s>");
|
| 943 |
-
out = out.replace(/
|
| 944 |
-
out = out.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noreferrer">$1</a>');
|
| 945 |
return out;
|
| 946 |
}
|
| 947 |
function renderMarkdown(md) {
|
|
|
|
| 931 |
}
|
| 932 |
function nl2br(s) { return esc(s).replace(/\n/g, "<br>"); }
|
| 933 |
function renderInlineMarkdown(s) {
|
| 934 |
+
// Extract images and links before escaping so URLs are never mangled by italic/bold regexes
|
| 935 |
+
const tokens = [];
|
| 936 |
+
const raw = String(s || "").replace(
|
| 937 |
+
/!\[([^\]]*)\]\((https?:\/\/[^\s)]+)\)|\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,
|
| 938 |
+
(match, imgAlt, imgSrc, linkText, linkHref) => {
|
| 939 |
+
const idx = tokens.length;
|
| 940 |
+
if (imgSrc !== undefined) {
|
| 941 |
+
tokens.push(`<img class="md-img" src="${imgSrc}" alt="${esc(imgAlt)}" loading="lazy">`);
|
| 942 |
+
} else {
|
| 943 |
+
tokens.push(`<a href="${linkHref}" target="_blank" rel="noreferrer">${esc(linkText)}</a>`);
|
| 944 |
+
}
|
| 945 |
+
return `\x00${idx}\x00`;
|
| 946 |
+
}
|
| 947 |
+
);
|
| 948 |
+
let out = esc(raw);
|
| 949 |
out = out.replace(/`([^`]+)`/g, "<code>$1</code>");
|
| 950 |
out = out.replace(/\*\*\*([^*]+)\*\*\*/g, "<strong><em>$1</em></strong>");
|
| 951 |
out = out.replace(/___([^_]+)___/g, "<strong><em>$1</em></strong>");
|
|
|
|
| 954 |
out = out.replace(/\*([^*\s][^*]*[^*\s]|\S)\*/g, "<em>$1</em>");
|
| 955 |
out = out.replace(/_([^_\s][^_]*[^_\s]|\S)_/g, "<em>$1</em>");
|
| 956 |
out = out.replace(/~~([^~]+)~~/g, "<s>$1</s>");
|
| 957 |
+
out = out.replace(/\x00(\d+)\x00/g, (_, i) => tokens[Number(i)]);
|
|
|
|
| 958 |
return out;
|
| 959 |
}
|
| 960 |
function renderMarkdown(md) {
|