fixed PDFs not displayed
This commit is contained in:
parent
a84b59ab24
commit
5ca346dade
|
|
@ -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, '"');
|
||||||
|
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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue