Update server and markdown renderer
This commit is contained in:
+14
-1
@@ -30,7 +30,7 @@
|
||||
text = text.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (m, alt, src) => {
|
||||
const url = safeUrl(src.replace(/&/g, '&'));
|
||||
if (!url) return alt;
|
||||
return `<img src="${esc(thumbUrl(url))}" data-img="${esc(url)}" alt="${esc(alt)}" loading="lazy" onerror="this.onerror=null;this.src='${esc(url)}'">`;
|
||||
return `<img src="${esc(thumbUrl(url))}" data-img="${esc(url)}" alt="${esc(alt)}" loading="lazy">`;
|
||||
});
|
||||
text = text.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (m, label, href) => {
|
||||
const url = safeUrl(href.replace(/&/g, '&'));
|
||||
@@ -188,5 +188,18 @@
|
||||
return out.join('\n');
|
||||
}
|
||||
|
||||
let fallbackBound = false;
|
||||
function bindImageFallbacks() {
|
||||
if (fallbackBound || typeof document === 'undefined') return;
|
||||
fallbackBound = true;
|
||||
document.addEventListener('error', (e) => {
|
||||
const img = e.target;
|
||||
if (!(img instanceof HTMLImageElement) || !img.hasAttribute('data-img')) return;
|
||||
const full = img.getAttribute('data-img');
|
||||
if (img.getAttribute('src') !== full) img.setAttribute('src', full);
|
||||
}, true);
|
||||
}
|
||||
bindImageFallbacks();
|
||||
|
||||
window.WhatIDoMD = { render, inline, esc, thumbUrl, safeUrl };
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user