diff --git a/apps/client/src/widgets/collections/presentation/index.tsx b/apps/client/src/widgets/collections/presentation/index.tsx index df7be7f2b..6ed58c796 100644 --- a/apps/client/src/widgets/collections/presentation/index.tsx +++ b/apps/client/src/widgets/collections/presentation/index.tsx @@ -140,6 +140,10 @@ function Presentation({ presentation, setApi } : { presentation: PresentationMod api.initialize().then(() => { setRevealApi(api); setApi(api); + + if (containerRef.current) { + rewireLinks(containerRef.current, api); + } }); return () => { @@ -177,7 +181,7 @@ function Presentation({ presentation, setApi } : { presentation: PresentationMod function Slide({ slide }: { slide: PresentationSlideBaseModel }) { return (
("a.reference-link"); + for (const link of links) { + link.addEventListener("click", () => { + /** + * Reveal.js has built-in navigation by either index or ID. However, the ID-based navigation doesn't work because it tries to look + * outside the shadom DOM (via document.getElementById). + */ + const url = new URL(link.href); + if (!url.hash.startsWith("#/slide-")) return; + const targetId = url.hash.substring(8); + const slide = container.querySelector(`#slide-${targetId}`); + if (!slide) return; + + const { h, v, f } = api.getIndices(slide); + api.slide(h, v, f); + }); + } +} diff --git a/apps/client/src/widgets/collections/presentation/model.ts b/apps/client/src/widgets/collections/presentation/model.ts index 14bd30c4d..21711b8a0 100644 --- a/apps/client/src/widgets/collections/presentation/model.ts +++ b/apps/client/src/widgets/collections/presentation/model.ts @@ -65,7 +65,7 @@ async function processContent(note: FNote): Promise { async function postProcessSlides(slides: (PresentationSlideModel | PresentationSlideBaseModel)[]) { for (const slide of slides) { if (slide.type !== "text") continue; - slide.content.__html = slide.content.__html.replaceAll(/href="[^"]*#root[a-zA-Z0-9_\/]*\/([a-zA-Z0-9_]+)[^"]*"/g, `href="#/$1"`); + slide.content.__html = slide.content.__html.replaceAll(/href="[^"]*#root[a-zA-Z0-9_\/]*\/([a-zA-Z0-9_]+)[^"]*"/g, `href="#/slide-$1"`); if ("verticalSlides" in slide && slide.verticalSlides) { postProcessSlides(slide.verticalSlides); }