fixed PDFs not displayed

This commit is contained in:
Gamosoft 2026-06-10 18:20:55 +02:00
parent a84b59ab24
commit 5ca346dade
1 changed files with 18 additions and 3 deletions

View File

@ -5771,8 +5771,10 @@ function noteApp() {
case 'video': case 'video':
return `<div class="media-embed media-video"><video controls preload="none" poster="" src="${mediaSrc}" title="${safeAlt}"></video></div>`; return `<div class="media-embed media-video"><video controls preload="none" poster="" src="${mediaSrc}" title="${safeAlt}"></video></div>`;
case 'document': case 'document':
// Local PDFs: show iframe preview // DOMPurify strips <iframe>, so emit a sentinel <span>
return `<div class="media-embed media-pdf"><iframe src="${mediaSrc}" title="${safeAlt}"></iframe></div>`; // that survives sanitization; the DOM walker below
// upgrades it to a media-pdf wrapper + iframe. Issue #239.
return `<span class="md-pdf-embed" data-src="${mediaSrc}" data-alt="${safeAlt}"></span>`;
default: // image default: // image
return `<img src="${mediaSrc}" alt="${safeAlt}" title="${safeAlt}">`; return `<img src="${mediaSrc}" alt="${safeAlt}" title="${safeAlt}">`;
} }
@ -5948,7 +5950,20 @@ function noteApp() {
img.setAttribute('title', altText); img.setAttribute('title', altText);
} }
}); });
// Upgrade PDF sentinels emitted by the wiki-embed pre-processor.
// Must run AFTER DOMPurify because iframes are stripped by the sanitizer.
tempDiv.querySelectorAll('span.md-pdf-embed').forEach(span => {
const src = span.dataset.src || '';
const alt = span.dataset.alt || '';
if (!src) return;
const safeAlt = alt.replace(/"/g, '&quot;');
const wrapper = document.createElement('div');
wrapper.className = 'media-embed media-pdf';
wrapper.innerHTML = `<iframe src="${src}" title="${safeAlt}"></iframe>`;
span.replaceWith(wrapper);
});
html = tempDiv.innerHTML; html = tempDiv.innerHTML;
// Debounced MathJax rendering (avoid re-running on every keystroke) // Debounced MathJax rendering (avoid re-running on every keystroke)