Skip to content

Commit a58ff6c

Browse files
Rapsssitojeertmans
andauthored
fix(convert): fix missing slides in HTML presentation after #508 (#515)
* fix(convert): fix missing slides after #508 * Update template.html * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Jérome Eertmans <[email protected]> --------- Co-authored-by: Jérome Eertmans <[email protected]>
1 parent bf512f2 commit a58ff6c

File tree

3 files changed

+73
-25
lines changed

3 files changed

+73
-25
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
(unreleased)=
1111
## [Unreleased](https://github.com/jeertmans/manim-slides/compare/v5.3.0...HEAD)
1212

13+
(unreleased-fixed)=
14+
### Fixed
15+
16+
- Fixed HTML template to avoid missing slides when exporting with `--one-file`.
17+
[@Rapsssito](https://github.com/Rapsssito) [#515](https://github.com/jeertmans/manim-slides/pull/515)
18+
1319
(v5.3.0)=
1420
## [v5.3.0](https://github.com/jeertmans/manim-slides/compare/v5.2.0...v5.3.0)
1521

docs/source/_static/template.html

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,26 +316,47 @@
316316
});
317317

318318
{% if one_file %}
319-
// Fix found by @t-fritsch and @Rapsssito on GitHub
320-
// see: https://github.com/hakimel/reveal.js/discussions/3362#discussioncomment-11733074.
321-
function fixBase64VideoBackground(event) {
322-
// Analyze all slides backgrounds
323-
for (const slide of Reveal.getBackgroundsElement().querySelectorAll('.slide-background')) {
324-
// Get the slide video and its sources for each background
325-
const video = slide.querySelector('video');
326-
const sources = video.querySelectorAll('source');
327-
// Update the source of the video
328-
sources.forEach((source, i) => {
329-
const src = source.getAttribute('src');
330-
if(src.match(/^data:video.*;base64$/)) {
331-
const nextSrc = sources[i+1]?.getAttribute('src');
332-
video.setAttribute('src', `${src},${nextSrc}`);
319+
// Fix found by @t-fritsch and @Rapsssito on GitHub
320+
// see: https://github.com/hakimel/reveal.js/discussions/3362#discussioncomment-11733074.
321+
function setVideoBase64(video) {
322+
const sources = video.querySelectorAll('source');
323+
// Update the source of the video
324+
sources.forEach((source, i) => {
325+
const src = source.getAttribute('src');
326+
if(src.match(/^data:video.*;base64$/)) {
327+
const nextSrc = sources[i+1]?.getAttribute('src');
328+
video.setAttribute('src', `${src},${nextSrc}`);
329+
}
330+
});
331+
}
332+
333+
function fixBase64VideoBackground(event) {
334+
// Analyze all slides backgrounds
335+
for (const slide of Reveal.getBackgroundsElement().querySelectorAll('.slide-background')) {
336+
// Get the slide video and its sources for each background
337+
const video = slide.querySelector('video');
338+
if (video) {
339+
setVideoBase64(video);
340+
} else {
341+
// Listen to the creation of the video element
342+
const observer = new MutationObserver((mutationsList) => {
343+
for (const mutation of mutationsList) {
344+
if (mutation.type === 'childList') {
345+
for (const addedNode of mutation.addedNodes) {
346+
if (addedNode.tagName === 'VIDEO') {
347+
setVideoBase64(addedNode);
348+
observer.disconnect(); // Stop observing once the video is handled
349+
}
350+
}
351+
}
333352
}
334353
});
354+
observer.observe(slide, { childList: true, subtree: true });
335355
}
336356
}
337-
// Setup base64 videos
338-
Reveal.on( 'ready', fixBase64VideoBackground );
357+
}
358+
// Setup base64 videos
359+
Reveal.on( 'ready', fixBase64VideoBackground );
339360
{% endif %}
340361
</script>
341362

manim_slides/templates/revealjs.html

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,20 +323,41 @@
323323
{% if one_file -%}
324324
// Fix found by @t-fritsch and @Rapsssito on GitHub
325325
// see: https://github.com/hakimel/reveal.js/discussions/3362#discussioncomment-11733074.
326+
function setVideoBase64(video) {
327+
const sources = video.querySelectorAll('source');
328+
// Update the source of the video
329+
sources.forEach((source, i) => {
330+
const src = source.getAttribute('src');
331+
if(src.match(/^data:video.*;base64$/)) {
332+
const nextSrc = sources[i+1]?.getAttribute('src');
333+
video.setAttribute('src', `${src},${nextSrc}`);
334+
}
335+
});
336+
}
337+
326338
function fixBase64VideoBackground(event) {
327339
// Analyze all slides backgrounds
328340
for (const slide of Reveal.getBackgroundsElement().querySelectorAll('.slide-background')) {
329341
// Get the slide video and its sources for each background
330342
const video = slide.querySelector('video');
331-
const sources = video.querySelectorAll('source');
332-
// Update the source of the video
333-
sources.forEach((source, i) => {
334-
const src = source.getAttribute('src');
335-
if(src.match(/^data:video.*;base64$/)) {
336-
const nextSrc = sources[i+1]?.getAttribute('src');
337-
video.setAttribute('src', `${src},${nextSrc}`);
338-
}
339-
});
343+
if (video) {
344+
setVideoBase64(video);
345+
} else {
346+
// Listen to the creation of the video element
347+
const observer = new MutationObserver((mutationsList) => {
348+
for (const mutation of mutationsList) {
349+
if (mutation.type === 'childList') {
350+
for (const addedNode of mutation.addedNodes) {
351+
if (addedNode.tagName === 'VIDEO') {
352+
setVideoBase64(addedNode);
353+
observer.disconnect(); // Stop observing once the video is handled
354+
}
355+
}
356+
}
357+
}
358+
});
359+
observer.observe(slide, { childList: true, subtree: true });
360+
}
340361
}
341362
}
342363
// Setup base64 videos

0 commit comments

Comments
 (0)