Skip to content

Commit e7f43aa

Browse files
authored
Fix format detection for extension format strings (#14588)
Format detection predicates (isPdfOutput, isHtmlOutput, isRevealjsOutput, isJatsOutput) use startsWith() which predates the extension format naming convention (<name>-<base>, e.g. acm-pdf). Extension formats place the base format at the end, so startsWith always returned false for them. Add parseFormatString() fallback in isFormatTo(), isRevealjsOutput(), and isJatsOutput() to extract the base format when startsWith fails. Fixes seven call sites across preview (PDF.js viewer), watch (revealjs), manuscript (notebook filtering, MECA bundles), and website (HTML-first ordering) flows. Fixes #14582
1 parent 33d0b0c commit e7f43aa

8 files changed

Lines changed: 169 additions & 7 deletions

File tree

‎news/changelog-1.10.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@ All changes included in 1.10:
9393
- ([#14359](https://github.com/quarto-dev/quarto-cli/issues/14359)): Fix intermediate `.quarto_ipynb` file not being deleted after rendering a `.qmd` with Jupyter engine, causing numbered variants (`_1`, `_2`, ...) to accumulate on disk across renders.
9494
- ([#14461](https://github.com/quarto-dev/quarto-cli/issues/14461)): Fix `quarto render --to pdf` aborting with `ERROR: Problem running 'fmtutil-sys --all' to rebuild format tree.` when an automatically-installed LaTeX package's post-update format rebuild fails. Format-tree rebuild is now treated as best-effort housekeeping (matching upstream `tinytex` R behavior) — the failure is logged as a warning and the package install completes.
9595
- ([#14472](https://github.com/quarto-dev/quarto-cli/issues/14472)): Add support for Kotlin in code annotations and YAML cell options. (author: @barendgehrels)
96-
- ([#14529](https://github.com/quarto-dev/quarto-cli/issues/14529)): Fix bundled Julia engine path leaking into rendered YAML metadata and pandoc log output when running an installed Quarto. The internal subtree-engine filter only matched the source-tree share-path layout (`resources/extension-subtrees/`) and missed installed layouts where the path is `share/extension-subtrees/`.
96+
- ([#14529](https://github.com/quarto-dev/quarto-cli/issues/14529)): Fix bundled Julia engine path leaking into rendered YAML metadata and pandoc log output when running an installed Quarto. The internal subtree-engine filter only matched the source-tree share-path layout (`resources/extension-subtrees/`) and missed installed layouts where the path is `share/extension-subtrees/`.
97+
- ([#14582](https://github.com/quarto-dev/quarto-cli/issues/14582)): Fix format detection for extension formats (e.g. `acm-pdf`) in project preview, manuscript notebooks, MECA bundles, and website format ordering.

‎src/config/format.ts‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { kBaseFormat, kPreferHtml } from "../config/constants.ts";
88
import { Format, FormatPandoc } from "./types.ts";
9+
import { parseFormatString } from "../core/pandoc/pandoc-formats.ts";
910

1011
export function isPdfOutput(format: string): boolean;
1112
export function isPdfOutput(format: FormatPandoc): boolean;
@@ -97,14 +98,20 @@ export function isJatsOutput(format?: string | FormatPandoc) {
9798
format = format?.to || "html";
9899
}
99100

100-
return [
101+
const jatsFormats = [
101102
"jats",
102103
"jats_archiving",
103104
"jats_articleauthoring",
104105
"jats_publishing",
105-
].find((formatStr) => {
106-
return (format as string).startsWith(formatStr);
107-
}) !== undefined;
106+
];
107+
const formatStr = format as string;
108+
if (jatsFormats.some((f) => formatStr.startsWith(f))) return true;
109+
try {
110+
const base = parseFormatString(formatStr).baseFormat;
111+
return jatsFormats.some((f) => base.startsWith(f));
112+
} catch {
113+
return false;
114+
}
108115
}
109116

110117
export function isPresentationOutput(format: FormatPandoc) {
@@ -123,7 +130,12 @@ export function isRevealjsOutput(format?: string | FormatPandoc) {
123130
format = format?.to;
124131
}
125132
format = format || "html";
126-
return format.startsWith("revealjs");
133+
if (format.startsWith("revealjs")) return true;
134+
try {
135+
return parseFormatString(format).baseFormat.startsWith("revealjs");
136+
} catch {
137+
return false;
138+
}
127139
}
128140

129141
export function isNativeOutput(format: FormatPandoc) {
@@ -146,7 +158,12 @@ function isFormatTo(format: string | FormatPandoc, to: string) {
146158
const formatStr = typeof format === "string"
147159
? format
148160
: (format?.to || "html");
149-
return formatStr.startsWith(to);
161+
if (formatStr.startsWith(to)) return true;
162+
try {
163+
return parseFormatString(formatStr).baseFormat.startsWith(to);
164+
} catch {
165+
return false;
166+
}
150167
}
151168

152169
export function isMarkdownOutput(

‎tests/docs/manual/preview/README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,22 @@ format edit is detected on the **first** render request.
216216
- **Expected:** No preview process restart. Render runs in the same process.
217217
- **Catches:** Over-eager invalidation triggering 404 when the format is in fact unchanged
218218

219+
## Extension Format PDF Preview (#14582)
220+
221+
### P1: Core functionality
222+
223+
#### T26: Book preview with extension PDF format
224+
- **Setup**: `extension-pdf-book/` fixture
225+
- **Steps**: `quarto preview . --to dummy-extension-pdf --no-browser --port 4444`
226+
- **Expected**: Browse URL contains `web/viewer.html`. PDF.js viewer loads in browser with live-reload.
227+
- **Catches**: `isFormatTo` startsWith check failing for extension format strings.
228+
229+
#### T27: Book preview with extension HTML format (no regression)
230+
- **Setup**: Same fixture
231+
- **Steps**: `quarto preview . --to dummy-extension-html --no-browser --port 4444`
232+
- **Expected**: Normal HTML preview with live-reload. No PDF.js viewer.
233+
- **Catches**: Fix doesn't accidentally enable PDF mode for non-PDF extension formats.
234+
219235
## Test File Templates
220236

221237
**Minimal Python .qmd:**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: dummy-extension
2+
contributes:
3+
formats:
4+
pdf: default
5+
html: default
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
project:
2+
type: book
3+
4+
book:
5+
title: "Bug reproduction"
6+
chapters:
7+
- index.qmd
8+
- chapter1.qmd
9+
10+
format:
11+
dummy-extension-pdf: default
12+
dummy-extension-html: default
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Introduction
2+
3+
This is chapter 1.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Preface"
3+
---
4+
5+
This is the preface.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { unitTest } from "../test.ts";
2+
import { assert } from "testing/asserts";
3+
import {
4+
isHtmlOutput,
5+
isJatsOutput,
6+
isPdfOutput,
7+
isRevealjsOutput,
8+
isTypstOutput,
9+
} from "../../src/config/format.ts";
10+
11+
unitTest(
12+
"isPdfOutput - direct formats",
13+
// deno-lint-ignore require-await
14+
async () => {
15+
assert(isPdfOutput("pdf"));
16+
assert(isPdfOutput("beamer"));
17+
assert(!isPdfOutput("html"));
18+
assert(!isPdfOutput("typst"));
19+
assert(!isPdfOutput("docx"));
20+
},
21+
);
22+
23+
unitTest(
24+
"isPdfOutput - extension formats",
25+
// deno-lint-ignore require-await
26+
async () => {
27+
assert(isPdfOutput("acm-pdf"));
28+
assert(isPdfOutput("dummy-extension-pdf"));
29+
assert(isPdfOutput("acm-2023-pdf"));
30+
assert(isPdfOutput("journal-beamer"));
31+
assert(!isPdfOutput("acm-html"));
32+
assert(!isPdfOutput("my-ext-typst"));
33+
},
34+
);
35+
36+
unitTest(
37+
"isPdfOutput - modifiers and edge cases",
38+
// deno-lint-ignore require-await
39+
async () => {
40+
assert(!isPdfOutput("default"));
41+
assert(!isPdfOutput(""));
42+
assert(isPdfOutput("pdf+draft"));
43+
assert(isPdfOutput("acm-pdf+draft"));
44+
},
45+
);
46+
47+
unitTest(
48+
"isHtmlOutput - extension formats",
49+
// deno-lint-ignore require-await
50+
async () => {
51+
assert(isHtmlOutput("html"));
52+
assert(isHtmlOutput("acm-html"));
53+
assert(isHtmlOutput("nature-html"));
54+
assert(!isHtmlOutput("acm-pdf"));
55+
},
56+
);
57+
58+
unitTest(
59+
"isTypstOutput - extension formats",
60+
// deno-lint-ignore require-await
61+
async () => {
62+
assert(isTypstOutput("typst"));
63+
assert(isTypstOutput("orange-book-typst"));
64+
assert(!isTypstOutput("acm-pdf"));
65+
},
66+
);
67+
68+
unitTest(
69+
"isRevealjsOutput - extension formats",
70+
// deno-lint-ignore require-await
71+
async () => {
72+
assert(isRevealjsOutput("revealjs"));
73+
assert(isRevealjsOutput("clean-revealjs"));
74+
assert(isRevealjsOutput("my-theme-revealjs"));
75+
assert(!isRevealjsOutput("html"));
76+
assert(!isRevealjsOutput("acm-pdf"));
77+
},
78+
);
79+
80+
unitTest(
81+
"isJatsOutput - extension formats",
82+
// deno-lint-ignore require-await
83+
async () => {
84+
assert(isJatsOutput("jats"));
85+
assert(isJatsOutput("jats_archiving"));
86+
assert(isJatsOutput("plos-jats"));
87+
assert(isJatsOutput("my-journal-jats_archiving"));
88+
assert(!isJatsOutput("html"));
89+
assert(!isJatsOutput("acm-pdf"));
90+
},
91+
);
92+
93+
unitTest(
94+
"format detection - malformed inputs",
95+
// deno-lint-ignore require-await
96+
async () => {
97+
assert(!isPdfOutput("---"));
98+
assert(!isPdfOutput("123"));
99+
assert(isHtmlOutput("")); // empty defaults to "html" internally
100+
assert(!isRevealjsOutput(""));
101+
assert(!isJatsOutput(""));
102+
},
103+
);

0 commit comments

Comments
 (0)