Skip to content

Commit baabedf

Browse files
authored
Merge pull request #11071 from quarto-dev/bugfix/11068
Use better output location when `-o -`
2 parents ee31c6b + 1da6a5d commit baabedf

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ All changes included in 1.6:
9090
- Upgrade `mermaidjs` to 11.2.0.
9191
- Upgrade Pandoc to 3.4.
9292
- Upgrade `deno` to 1.46.3.
93+
- ([#11068](https://github.com/quarto-dev/quarto-cli/issues/11068)): use standard location when writing to standard output to avoid breakage under `self-contained: true`.
9394
- ([#10162](https://github.com/quarto-dev/quarto-cli/issues/10162)): Use Edge on `macOS` as a Chromium browser when available.
9495
- ([#10235](https://github.com/quarto-dev/quarto-cli/issues/10235)): Configure the CI schedule trigger to activate exclusively for the upstream repository.
9596
- ([#10295](https://github.com/quarto-dev/quarto-cli/issues/10235)): Fix regression to return error status to shell when `CommandError` is thrown.

src/command/render/output.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export function outputRecipe(
181181
});
182182
}
183183

184-
if (!recipe.output) {
184+
const deriveAutoOutput = () => {
185185
// no output specified: derive an output path from the extension
186186

187187
// derive new output file
@@ -200,15 +200,16 @@ export function outputRecipe(
200200

201201
// assign output
202202
updateOutput(output);
203+
};
204+
205+
if (!recipe.output) {
206+
deriveAutoOutput();
203207
} else if (recipe.output === kStdOut) {
204-
// output to stdout: direct pandoc to write to a temp file then we'll
205-
// forward to stdout (necessary b/c a postprocesor may need to act on
206-
// the output before its complete)
207-
updateOutput(options.services.temp.createFile({ suffix: "." + ext }));
208+
deriveAutoOutput();
208209
recipe.isOutputTransient = true;
209210
completeActions.push(() => {
210-
writeFileToStdout(recipe.output);
211-
Deno.removeSync(recipe.output);
211+
writeFileToStdout(join(inputDir, recipe.output));
212+
Deno.removeSync(join(inputDir, recipe.output));
212213
});
213214
} else if (!isAbsolute(recipe.output)) {
214215
// relatve output file on the command line: make it relative to the input dir

src/command/render/render.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,25 +276,38 @@ export async function renderPandoc(
276276
await withTimingAsync("postprocess-selfcontained", async () => {
277277
// ensure flags
278278
const flags = context.options.flags || {};
279-
280-
// call complete handler (might e.g. run latexmk to complete the render)
281-
finalOutput = await recipe.complete(pandocOptions) || recipe.output;
282-
283279
// determine whether this is self-contained output
280+
finalOutput = recipe.output;
281+
282+
// note that we intentionally call isSelfContainedOutput twice
283+
// the first needs to happen before recipe completion
284+
// because ingestion of self-contained output needs
285+
// to happen before recipe completion (which cleans up some files)
284286
selfContained = isSelfContainedOutput(
285287
flags,
286288
format,
287289
finalOutput,
288290
);
289291

290-
// If this is self-contained, run pandoc to 'suck in' the dependencies
291-
// which may have been added in the post processor
292292
if (selfContained && isHtmlFileOutput(format.pandoc)) {
293293
await pandocIngestSelfContainedContent(
294294
outputFile,
295295
format.pandoc[kResourcePath],
296296
);
297297
}
298+
299+
// call complete handler (might e.g. run latexmk to complete the render)
300+
finalOutput = (await recipe.complete(pandocOptions)) || recipe.output;
301+
302+
// note that we intentionally call isSelfContainedOutput twice
303+
// the second call happens because some recipes change
304+
// their output extension on completion (notably, .pdf files)
305+
// and become self-contained for purposes of cleanup
306+
selfContained = isSelfContainedOutput(
307+
flags,
308+
format,
309+
finalOutput,
310+
);
298311
});
299312

300313
// compute the relative path to the files dir
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
format:
3+
html:
4+
self-contained: true
5+
---
6+
7+
## Hello
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { quarto } from "../../../src/quarto.ts";
2+
import { test } from "../../test.ts";
3+
4+
test({
5+
name: "https://github.com/quarto-dev/quarto-cli/issues/11068",
6+
context: {
7+
setup: async() => {
8+
await quarto(["render", "docs/self-contained/simple.qmd", "-o", "-"]);
9+
}
10+
},
11+
execute: async () => {},
12+
verify: [],
13+
type: "smoke"
14+
});

0 commit comments

Comments
 (0)