Skip to content

Commit 8fd1bee

Browse files
authored
Merge pull request #10688 from quarto-dev/revealjs/fig-stretch-id
2 parents 1ce279b + 2600d55 commit 8fd1bee

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

news/changelog-1.6.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ All changes included in 1.6:
1414

1515
## `revealjs` Format
1616

17-
- Update to Reveal JS 5.1.0.
17+
- Update to Reveal JS 5.1.0
1818
- ([#7715](https://github.com/quarto-dev/quarto-cli/issues/7715)): Revealjs don't support anymore special Pandoc syntax making BulletList in Blockquotes become incremental list. This was confusing and unexpected behavior. Supported syntax for incremental list is documented at <https://quarto.org/docs/presentations/revealjs/#incremental-lists>.
19+
- ([#9742](https://github.com/quarto-dev/quarto-cli/issues/9742)): Links to cross-referenced images correctly works.
1920

2021
## `typst` Format
2122

src/format/reveal/format-reveal.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -783,23 +783,6 @@ const handleAnchors = (doc: Document) => {
783783
const codeLineAnchorEl = codeLineAnchor as Element;
784784
codeLineAnchorEl.removeAttribute("href");
785785
});
786-
787-
// https://github.com/quarto-dev/quarto-cli/issues/3533
788-
// redirect anchors to the slide they refer to
789-
const anchors = doc.querySelectorAll("a[href^='#/']");
790-
for (const anchor of anchors) {
791-
const anchorEl = anchor as Element;
792-
const href = anchorEl.getAttribute("href");
793-
if (href) {
794-
const target = doc.getElementById(href.replace(/^#\//, ""));
795-
if (target) {
796-
const slide = findParentSlide(target);
797-
if (slide && slide.getAttribute("id")) {
798-
anchorEl.setAttribute("href", `#/${slide.getAttribute("id")}`);
799-
}
800-
}
801-
}
802-
}
803786
};
804787

805788
const handleInterColumnDivSpaces = (doc: Document) => {
@@ -1002,7 +985,7 @@ function applyStretch(doc: Document, autoStretch: boolean) {
1002985
}
1003986
};
1004987

1005-
// Figure environment ? Get caption and alignment
988+
// Figure environment ? Get caption, id and alignment
1006989
const quartoFig = slideEl.querySelector("div.quarto-figure");
1007990
const caption = doc.createElement("p");
1008991
if (quartoFig) {
@@ -1011,6 +994,9 @@ function applyStretch(doc: Document, autoStretch: boolean) {
1011994
"quarto-figure-(center|left|right)",
1012995
);
1013996
if (align) imageEl.classList.add(align[0]);
997+
// Get id
998+
const quartoFigId = quartoFig?.id;
999+
if (quartoFigId) imageEl.id = quartoFigId;
10141000
// Get Caption
10151001
const figCaption = nodeEl.querySelector("figcaption");
10161002
if (figCaption) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Links to nested elements works
3+
format: revealjs
4+
_quarto:
5+
tests:
6+
revealjs:
7+
ensureHtmlElements:
8+
-
9+
- 'img.r-stretch#fig-elephant'
10+
- 'a[href="#/fig-elephant"]'
11+
- 'img.r-stretch#elephant'
12+
- 'a[href="#/elephant"]'
13+
- 'span#eq-EEE > span.math'
14+
- 'a[href="#/eq-EEE"]'
15+
- 'div.theorem#thm-TTT'
16+
- 'a[href="#/thm-TTT"]'
17+
- []
18+
---
19+
20+
<!-- TODO: Add test with puppeteer about link working -->
21+
22+
## Quarto Figure
23+
24+
![Elephant](https://quarto.org/docs/authoring/images/crossref-figure.png){#fig-elephant}
25+
26+
## Link to the figure
27+
28+
See [Figure Element](#fig-elephant)
29+
30+
## Image
31+
32+
![Elephant](https://quarto.org/docs/authoring/images/crossref-figure.png){#elephant}
33+
34+
## Link to the image
35+
36+
See [Figure Element](#elephant)
37+
38+
## Equation
39+
40+
$$
41+
\begin{aligned}
42+
f(X) = y.
43+
\end{aligned}
44+
$$ {#eq-EEE}
45+
46+
## Link to equation
47+
48+
See @eq-EEE.
49+
50+
## Theorem
51+
52+
::: {#thm-TTT}
53+
Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.
54+
:::
55+
56+
## Link to theorem
57+
58+
See @thm-TTT.

0 commit comments

Comments
 (0)