Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/crossref/figures.test.ts
12925 views
1
/*
2
* figures.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { ensureFileRegexMatches, ensureHtmlElements } from "../../verify.ts";
8
import { testRender } from "../render/render.ts";
9
import { crossref } from "./utils.ts";
10
11
const simpleQmd = crossref("simple.qmd", "html");
12
testRender(simpleQmd.input, "html", false, [
13
ensureHtmlElements(simpleQmd.output.outputPath, [
14
"section#simple-figure > h2",
15
"div#fig-elephant > figure > figcaption.quarto-float-fig.quarto-float-caption",
16
"section#simple-sub-figure > h2",
17
"section#simple-sub-figure > div.quarto-layout-panel > figure div.quarto-layout-row",
18
"section#simple-sub-figure > div.quarto-layout-panel > figure > figcaption.quarto-float-fig.quarto-float-caption",
19
]),
20
ensureFileRegexMatches(simpleQmd.output.outputPath, [
21
/Figure 1: Elephant/,
22
/Figure 2: Famous Elephants/,
23
/\(a\) Surus/,
24
/\(b\) Abbas/,
25
/Figure 1/,
26
/Figure 2/,
27
/Figure 2 \(b\)/,
28
], [
29
/\?@fig-/,
30
]),
31
]);
32
33
const pythonQmd = crossref("python.qmd", "html");
34
testRender(pythonQmd.input, "html", false, [
35
ensureHtmlElements(pythonQmd.output.outputPath, [
36
"section#python-crossref-figure div#fig-plot > figure img.figure-img",
37
"section#python-crossref-figure div#fig-plot > figure > figcaption",
38
]),
39
ensureFileRegexMatches(pythonQmd.output.outputPath, [
40
/Figure 1: Plot/,
41
/Figure 1/,
42
], [
43
/\?@fig-/,
44
]),
45
]);
46
47
const pythonSubfigQmd = crossref("python-subfig.qmd", "html");
48
testRender(pythonSubfigQmd.input, "html", false, [
49
ensureHtmlElements(pythonSubfigQmd.output.outputPath, [
50
"section#python-crossref-figure div.quarto-layout-panel > figure div.quarto-layout-row",
51
"section#python-crossref-figure div.quarto-layout-panel > figure > figcaption.quarto-float-fig.quarto-float-caption",
52
"section#python-crossref-figure div.quarto-layout-panel > figure img.figure-img",
53
]),
54
ensureFileRegexMatches(pythonSubfigQmd.output.outputPath, [
55
/Figure 1: Plots/,
56
/Figure 1/,
57
/Figure 1 \(b\)/,
58
/\(a\) Plot 1/,
59
/\(b\) Plot 2/,
60
], [
61
/\?@fig-/,
62
]),
63
]);
64
65
for (const file of ["julia.qmd", "julianative.qmd"]) {
66
const juliaQmd = crossref(file, "html");
67
testRender(juliaQmd.input, "html", false, [
68
ensureHtmlElements(juliaQmd.output.outputPath, [
69
"section#julia-crossref-figure div#fig-plot > figure img.figure-img",
70
"section#julia-crossref-figure div#fig-plot > figure > figcaption",
71
]),
72
ensureFileRegexMatches(juliaQmd.output.outputPath, [
73
/Figure 1: Plot/,
74
/Figure 1/,
75
], [
76
/\?@fig-/,
77
]),
78
]);
79
}
80
81
for (const file of ["julia-subfig.qmd", "julianative-subfig.qmd"]) {
82
const juliaSubfigQmd = crossref(file, "html");
83
testRender(juliaSubfigQmd.input, "html", false, [
84
ensureHtmlElements(juliaSubfigQmd.output.outputPath, [
85
"section#julia-crossref-figure div.quarto-layout-panel > figure div.quarto-layout-row",
86
"section#julia-crossref-figure div.quarto-layout-panel > figure > figcaption.quarto-float-fig.quarto-float-caption",
87
]),
88
ensureFileRegexMatches(juliaSubfigQmd.output.outputPath, [
89
/Figure 1: Plots/,
90
/Figure 1/,
91
/Figure 1 \(b\)/,
92
/\(a\) Plot 1/,
93
/\(b\) Plot 2/,
94
], [
95
/\?@fig-/,
96
]),
97
]);
98
}
99
100
const knitrQmd = crossref("knitr.qmd", "html");
101
testRender(knitrQmd.input, "html", false, [
102
ensureHtmlElements(knitrQmd.output.outputPath, [
103
"section#knitr-crossref-figure div#fig-plot > figure img.figure-img",
104
"section#knitr-crossref-figure div#fig-plot > figure > figcaption",
105
]),
106
ensureFileRegexMatches(knitrQmd.output.outputPath, [
107
/Figure 1: Plot/,
108
/Figure 1/,
109
], [
110
/\?@fig-/,
111
]),
112
]);
113
114