Skip to content

Commit 5246d7d

Browse files
committed
target references and footnotes slides for citation and footnote links
1 parent 68ead14 commit 5246d7d

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

news/changelog-1.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
## RevealJS Format
3737

3838
- Don't ignore auto stretch rules when speaker notes are present
39+
- Target references and footnotes slides for citation and footnote links
3940

4041
## Miscellaneous
4142

src/format/reveal/format-reveal.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -601,38 +601,51 @@ function revealHtmlPostprocessor(
601601
footnoteSection.remove();
602602
}
603603
} else {
604-
// we are keeping footnotes at the end so disable the links (we use popups)
605-
// and tweak the footnotes slide (add a title add smaller/scrollable)
606-
const notes = doc.querySelectorAll('a[role="doc-noteref"]');
607-
for (const note of notes) {
608-
const noteEl = note as Element;
609-
noteEl.setAttribute("onclick", "return false;");
610-
}
604+
let footnotesId: string | undefined;
611605
const footnotes = doc.querySelectorAll('section[role="doc-endnotes"]');
612606
if (footnotes.length === 1) {
613607
const footnotesEl = footnotes[0] as Element;
608+
footnotesId = footnotesEl?.getAttribute("id") || "footnotes";
609+
footnotesEl.setAttribute("id", footnotesId);
614610
insertFootnotesTitle(doc, footnotesEl, format.language, slideLevel);
615611
footnotesEl.classList.add("smaller");
616612
footnotesEl.classList.add("scrollable");
617613
footnotesEl.classList.remove("center");
618614
removeFootnoteBacklinks(footnotesEl);
619615
}
620-
}
621616

622-
// disable citation links (we use a popup for them)
623-
const cites = doc.querySelectorAll('a[role="doc-biblioref"]');
624-
for (const cite of cites) {
625-
const citeEl = cite as Element;
626-
citeEl.setAttribute("onclick", "return false;");
617+
// we are keeping footnotes at the end so disable the links (we use popups)
618+
// and tweak the footnotes slide (add a title add smaller/scrollable)
619+
const notes = doc.querySelectorAll('a[role="doc-noteref"]');
620+
for (const note of notes) {
621+
const noteEl = note as Element;
622+
noteEl.setAttribute("data-footnote-href", noteEl.getAttribute("href"));
623+
noteEl.setAttribute("href", footnotesId ? `#/${footnotesId}` : "");
624+
noteEl.setAttribute("onclick", footnotesId ? "" : "return false;");
625+
}
627626
}
628627

629628
// add scrollable to refs slide
629+
let refsId: string | undefined;
630630
const refs = doc.querySelector("#refs");
631631
if (refs) {
632+
const refsSlide = findParentSlide(refs);
633+
if (refsSlide) {
634+
refsId = refsSlide?.getAttribute("id") || "references";
635+
refsSlide.setAttribute("id", refsId);
636+
}
632637
applyClassesToParentSlide(refs, ["smaller", "scrollable"]);
633638
removeClassesFromParentSlide(refs, ["center"]);
634639
}
635640

641+
// handle citation links
642+
const cites = doc.querySelectorAll('a[role="doc-biblioref"]');
643+
for (const cite of cites) {
644+
const citeEl = cite as Element;
645+
citeEl.setAttribute("href", refsId ? `#/${refsId}` : "");
646+
citeEl.setAttribute("onclick", refsId ? "" : "return false;");
647+
}
648+
636649
// apply stretch to images as required
637650
applyStretch(doc, format.metadata[kAutoStretch] as boolean);
638651

src/resources/formats/html/templates/quarto-html.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
283283
for (var i=0; i<noterefs.length; i++) {
284284
const ref = noterefs[i];
285285
tippyHover(ref, function() {
286-
let href = ref.getAttribute('href');
286+
// use id or data attribute instead here
287+
let href = ref.getAttribute('data-footnote-href');
287288
try { href = new URL(href).hash; } catch {}
288289
const id = href.replace(/^#\/?/, "");
289290
const note = window.document.getElementById(id);

0 commit comments

Comments
 (0)