Skip to content

Commit a60f4be

Browse files
authored
postprocess revealjs slides so that anchor clicks resolve correctly (#4623)
* postprocess revealjs slides so that anchor clicks resolve correctly. Closes #3533 * be more defensive in case slides have no id
1 parent 7e8cf6d commit a60f4be

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

news/changelog-1.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
- Authors on the title slides now correctly object customization of the `$presentation-title-slide-text-align` scss variable ([#3843](https://github.com/quarto-dev/quarto-cli/issues/3843))
5555
- Properly support `show-notes: separate-page` [#3996](https://github.com/quarto-dev/quarto-cli/issues/3996)
5656
- Improve footnote / aside layout for centered slides. [#4297](https://github.com/quarto-dev/quarto-cli/issues/4297)
57+
- Ensure anchors refer to the containing slide in case of crossrefs ([#3533](https://github.com/quarto-dev/quarto-cli/issues/4297)).
5758

5859
## EPUB Format
5960

src/format/reveal/format-reveal.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,23 @@ function revealHtmlPostprocessor(
682682
}
683683
}
684684

685+
// https://github.com/quarto-dev/quarto-cli/issues/3533
686+
// redirect anchors to the slide they refer to
687+
const anchors = doc.querySelectorAll("a[href^='#/']");
688+
for (const anchor of anchors) {
689+
const anchorEl = anchor as Element;
690+
const href = anchorEl.getAttribute("href");
691+
if (href) {
692+
const target = doc.getElementById(href.replace(/^#\//, ""));
693+
if (target) {
694+
const slide = findParentSlide(target);
695+
if (slide && slide.getAttribute("id")) {
696+
anchorEl.setAttribute("href", `#/${slide.getAttribute("id")}`);
697+
}
698+
}
699+
}
700+
}
701+
685702
// return result
686703
return Promise.resolve(result);
687704
};

0 commit comments

Comments
 (0)