From 47aa7c05d67af3ac06a0f065a08caf60124233b2 Mon Sep 17 00:00:00 2001 From: jae Date: Fri, 3 Apr 2026 22:24:16 +0000 Subject: [PATCH] fix: render markdown in contraband entry descriptions and names --- js/contraband.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/js/contraband.js b/js/contraband.js index 1c62a6f..62ceee9 100644 --- a/js/contraband.js +++ b/js/contraband.js @@ -17,6 +17,21 @@ 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, '$1'); + // Bold: **text** + h = h.replace(/\*\*([^*]+)\*\*/g, '$1'); + // Italic: *text* + h = h.replace(/\*([^*]+)\*/g, '$1'); + // Inline code: `text` + h = h.replace(/`([^`]+)`/g, '$1'); + return h; + } + function fmt(n) { return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); } @@ -148,11 +163,11 @@ if (entry.url) { html += `
${esc(entry.name || entry.url)}
`; } else if (entry.name) { - html += `
${esc(entry.name)}
`; + html += `
${md(entry.name)}
`; } if (entry.description) { - html += `
${esc(entry.description)}
`; + html += `
${md(entry.description)}
`; } if (entry.extra_links && entry.extra_links.length > 0) { @@ -192,11 +207,11 @@ if (r.url) { html += `${esc(r.name || r.url)}`; } else { - html += esc(r.name); + html += md(r.name); } html += ``; if (r.description) { - html += `
${esc(r.description)}
`; + html += `
${md(r.description)}
`; } html += ``; }