Update server and markdown renderer

This commit is contained in:
dev
2026-10-31 11:14:27 +03:00
parent 00b7e96260
commit a4644b473b
2 changed files with 23 additions and 4 deletions
+14 -1
View File
@@ -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(/&amp;/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 };
})();