fix: render markdown in contraband entry descriptions and names
This commit is contained in:
parent
ec50baa369
commit
47aa7c05d6
1 changed files with 19 additions and 4 deletions
|
|
@ -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, '<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) {
|
||||
return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
|
@ -148,11 +163,11 @@
|
|||
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>`;
|
||||
} 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) {
|
||||
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) {
|
||||
|
|
@ -192,11 +207,11 @@
|
|||
if (r.url) {
|
||||
html += `<a href="${esc(r.url)}" target="_blank" rel="noopener">${esc(r.name || r.url)}</a>`;
|
||||
} else {
|
||||
html += esc(r.name);
|
||||
html += md(r.name);
|
||||
}
|
||||
html += `</div>`;
|
||||
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>`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue