Skip to content

Commit

Permalink
Merge pull request #7587 from quarto-dev/typst/correct-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv authored Nov 15, 2023
2 parents 3c1e3da + fb10edc commit 6fa1a24
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/resources/filters/quarto-post/typst.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ function render_typst_fixups()
img,
pandoc.RawInline("typst", "]"),
})
end,
Cite = function(cite)
if PANDOC_VERSION <= pandoc.types.Version('3.1.9') then
-- Patch for https://github.com/quarto-dev/quarto-cli/issues/7586
-- TODO: Remove when Pandoc > 3.1.9 is used https://github.com/jgm/pandoc/issues/9188
if PANDOC_WRITER_OPTIONS.extensions:includes("citations") then
citations = pandoc.List()
for _, citation in pairs(cite.citations) do
citations:insert(pandoc.RawInline('typst', "#cite(<" .. citation.id .. ">)"))
end
return citations
end
end
end
}
end
13 changes: 13 additions & 0 deletions tests/docs/smoke-all/typst/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ @article{Cronbach_1951
title = {Coefficient alpha and the internal structure of tests},
journal = {Psychometrika}
}

@article{Cronbach_1952,
doi = {10.1007/bf02310555},
year = 1951,
month = {sep},
publisher = {Springer Science and Business Media {LLC}},
vol = {16},
number = {3},
pages = {297--334},
author = {Lee J. Cronbach},
title = {Coefficient alpha and the internal structure of tests},
journal = {Psychometrika}
}
6 changes: 3 additions & 3 deletions tests/docs/smoke-all/typst/typst-citeproc.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
title: "Citeproc and Typst"
format:
typst:
output-ext: typ
keep-typ: true
bibliography: refs.bib
citeproc: true
_quarto:
tests:
typst:
ensureFileRegexMatches:
ensureTypstFileRegexMatches:
- ['<refs>', '<ref-Cronbach_1951>']
- ['\#bibliography\([^)]*\)']
---

Hello [@Cronbach_1951]
Hello [@Cronbach_1951, @Cronbach_1952]

# References
8 changes: 5 additions & 3 deletions tests/docs/smoke-all/typst/typst-no-citeproc.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
title: "Citeproc and Typst"
format:
typst:
output-ext: typ
keep-typ: true
bibliography: refs.bib
bibliographystyle: "chicago-author-date"
_quarto:
tests:
typst:
ensureFileRegexMatches:
ensureTypstFileRegexMatches:
- ['\#set bibliography\(style\: [^)]*\)', '\#bibliography\([^)]*\)', '\#cite\([^)]*\)']
- ['<refs>', '<ref-Cronbach_1951>']
---

Hello [@Cronbach_1951]
Hello @Cronbach_1951

Hello [@Cronbach_1951; @Cronbach_1952]
7 changes: 3 additions & 4 deletions tests/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,20 @@ export const ensureTypstFileRegexMatches = (
name: `Inspecting ${file} for Regex matches`,
verify: async (_output: ExecuteOutput[]) => {
const keptTyp = file.replace(".pdf", ".typ");
const tex = await Deno.readTextFile(keptTyp);
const typ = await Deno.readTextFile(keptTyp);

try {
// Move the docx to a temp dir and unzip it
matches.forEach((regex) => {
assert(
regex.test(tex),
regex.test(typ),
`Required match ${String(regex)} is missing from file ${file}.`,
);
});

if (noMatches) {
noMatches.forEach((regex) => {
assert(
!regex.test(tex),
!regex.test(typ),
`Illegal match ${String(regex)} was found in file ${file}.`,
);
});
Expand Down

0 comments on commit 6fa1a24

Please sign in to comment.