fix: render markdown in contraband entry descriptions and names

This commit is contained in:
jae 2026-04-03 22:24:16 +00:00
parent ec50baa369
commit 47aa7c05d6

View file

@ -17,6 +17,21 @@
return d.innerHTML; return d.innerHTML;
} }
// Mini markdown → HTML (escape first, then convert patterns)
function md(s) {
if (!s) return '';
let h = esc(s);
// Links: [text](url)
h = h.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>');
// Bold: **text**
h = h.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
// Italic: *text*
h = h.replace(/\*([^*]+)\*/g, '<em>$1</em>');
// Inline code: `text`
h = h.replace(/`([^`]+)`/g, '<code>$1</code>');
return h;
}
function fmt(n) { function fmt(n) {
return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
} }
@ -148,11 +163,11 @@
if (entry.url) { if (entry.url) {
html += `<div class="crt-entry-name"><a href="${esc(entry.url)}" target="_blank" rel="noopener">${esc(entry.name || entry.url)}</a></div>`; html += `<div class="crt-entry-name"><a href="${esc(entry.url)}" target="_blank" rel="noopener">${esc(entry.name || entry.url)}</a></div>`;
} else if (entry.name) { } else if (entry.name) {
html += `<div class="crt-entry-name">${esc(entry.name)}</div>`; html += `<div class="crt-entry-name">${md(entry.name)}</div>`;
} }
if (entry.description) { if (entry.description) {
html += `<div class="crt-entry-desc">${esc(entry.description)}</div>`; html += `<div class="crt-entry-desc">${md(entry.description)}</div>`;
} }
if (entry.extra_links && entry.extra_links.length > 0) { if (entry.extra_links && entry.extra_links.length > 0) {
@ -192,11 +207,11 @@
if (r.url) { if (r.url) {
html += `<a href="${esc(r.url)}" target="_blank" rel="noopener">${esc(r.name || r.url)}</a>`; html += `<a href="${esc(r.url)}" target="_blank" rel="noopener">${esc(r.name || r.url)}</a>`;
} else { } else {
html += esc(r.name); html += md(r.name);
} }
html += `</div>`; html += `</div>`;
if (r.description) { if (r.description) {
html += `<div class="crt-result-desc">${esc(r.description)}</div>`; html += `<div class="crt-result-desc">${md(r.description)}</div>`;
} }
html += `</div>`; html += `</div>`;
} }