chore(collection/presentation): rewrite vertical slide links

This commit is contained in:
Elian Doran 2025-10-18 18:41:05 +03:00
parent c04c38e61d
commit bfa1c2a2dd
No known key found for this signature in database
2 changed files with 7 additions and 2 deletions

View File

@ -30,7 +30,8 @@ describe("Presentation model", () => {
children: [
{
id: "slide4",
title: "Second-sub"
title: "Second-sub",
content: `<p>Go to&nbsp;<a class="reference-link" href="#root/presentation/slide2">First-sub</a>.</p>`,
}
]
}
@ -68,6 +69,7 @@ describe("Presentation model", () => {
it("rewrites links to other slides", () => {
expect(data.slides[1].content.__html).toStrictEqual(`<div class="ck-content"><p>Go to&nbsp;<a class="reference-link" href="#/slide1"><span class="bx bx-folder"></span>First slide</a>.</p></div>`);
expect(data.slides[1].verticalSlides![0].content.__html).toStrictEqual(`<div class="ck-content"><p>Go to&nbsp;<a class="reference-link" href="#/slide2"><span class="bx bx-note"></span>First-sub</a>.</p></div>`);
});
it("doesn't rewrite links if they are not part of the slideshow", () => {

View File

@ -62,9 +62,12 @@ async function processContent(note: FNote): Promise<DangerouslySetInnerHTML> {
return { __html: $renderedContent.html() };
}
async function postProcessSlides(slides: PresentationSlideModel[]) {
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"`);
if ("verticalSlides" in slide && slide.verticalSlides) {
postProcessSlides(slide.verticalSlides);
}
}
}