Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/crossref/docx.test.ts
12925 views
1
/*
2
* latex.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
8
import { ensureDocxRegexMatches } from "../../verify.ts";
9
import { testRender } from "../render/render.ts";
10
import { crossref } from "./utils.ts";
11
12
const allQmd = crossref("all-docx.qmd", "docx");
13
14
function bookmarkStart(name: string) {
15
return RegExp(
16
`<w:bookmarkStart[\\s]*w:id="[0-9]+"[\\s]*w:name="${name}"[\\s]*\\/>`,
17
);
18
}
19
20
function anchor(name: string) {
21
return RegExp(
22
`<w:hyperlink w:anchor="${name}">`,
23
);
24
}
25
26
function text(text: string) {
27
return RegExp(
28
`>${text}<`,
29
);
30
}
31
32
const simpleFigRegexes = [
33
bookmarkStart("fig-elephant"),
34
anchor("fig-elephant"),
35
// These tests no longer pass after we started introducing non-breaking
36
// spaces between 'Figure' and '1' (although upon cracking the file
37
// it seems like there are no non-breaking spaces and these strings
38
// are in fact in the file)
39
text("Figure\\u00A01: Elephant"),
40
text("Figure\\u00A01"),
41
];
42
43
const tableRegexes = [
44
bookmarkStart("tbl-letters"),
45
anchor("tbl-letters"),
46
// (see comment above re: non-breaking spaces)
47
text("Table\\u00A01: My Caption"),
48
];
49
50
const mathRegexes = [
51
text("Theorem 1 \\(Line\\)"),
52
bookmarkStart("thm-line"),
53
anchor("thm-line"),
54
];
55
56
const _subTableRegexes = [
57
bookmarkStart("tbl-first"),
58
bookmarkStart("tbl-second"),
59
anchor("tbl-first"),
60
anchor("tbl-second"),
61
text("Table 2: Main Caption"),
62
text("(a) First Table"),
63
text("(b) Second Table"),
64
];
65
66
const _subFigRegexes = [
67
bookmarkStart("fig-elephants"),
68
bookmarkStart("fig-abbas"),
69
bookmarkStart("fig-surus"),
70
anchor("fig-elephants"),
71
anchor("fig-abbas"),
72
anchor("fig-surus"),
73
text("Figure 2: Famous Elephants"),
74
text("Figure 2"),
75
text("Figure 2 (b)"),
76
];
77
78
testRender(allQmd.input, "docx", true, [
79
ensureDocxRegexMatches(allQmd.output.outputPath, [
80
...simpleFigRegexes,
81
...tableRegexes,
82
...mathRegexes,
83
// ...subFigRegexes,
84
// ...subTableRegexes,
85
]),
86
]);
87
88