diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index 2d4b8a89d66..39f8b03b73d 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -90,6 +90,7 @@ All changes included in 1.6: - Upgrade `mermaidjs` to 11.2.0. - Upgrade Pandoc to 3.4. - Upgrade `deno` to 1.46.3. +- ([#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`. - ([#10162](https://github.com/quarto-dev/quarto-cli/issues/10162)): Use Edge on `macOS` as a Chromium browser when available. - ([#10235](https://github.com/quarto-dev/quarto-cli/issues/10235)): Configure the CI schedule trigger to activate exclusively for the upstream repository. - ([#10295](https://github.com/quarto-dev/quarto-cli/issues/10235)): Fix regression to return error status to shell when `CommandError` is thrown. diff --git a/src/command/render/output.ts b/src/command/render/output.ts index fdf2e1a0c40..cf08086e6f1 100644 --- a/src/command/render/output.ts +++ b/src/command/render/output.ts @@ -181,7 +181,7 @@ export function outputRecipe( }); } - if (!recipe.output) { + const deriveAutoOutput = () => { // no output specified: derive an output path from the extension // derive new output file @@ -200,15 +200,16 @@ export function outputRecipe( // assign output updateOutput(output); + }; + + if (!recipe.output) { + deriveAutoOutput(); } else if (recipe.output === kStdOut) { - // output to stdout: direct pandoc to write to a temp file then we'll - // forward to stdout (necessary b/c a postprocesor may need to act on - // the output before its complete) - updateOutput(options.services.temp.createFile({ suffix: "." + ext })); + deriveAutoOutput(); recipe.isOutputTransient = true; completeActions.push(() => { - writeFileToStdout(recipe.output); - Deno.removeSync(recipe.output); + writeFileToStdout(join(inputDir, recipe.output)); + Deno.removeSync(join(inputDir, recipe.output)); }); } else if (!isAbsolute(recipe.output)) { // relatve output file on the command line: make it relative to the input dir diff --git a/src/command/render/render.ts b/src/command/render/render.ts index 195bdd693cf..80986a16016 100644 --- a/src/command/render/render.ts +++ b/src/command/render/render.ts @@ -276,25 +276,38 @@ export async function renderPandoc( await withTimingAsync("postprocess-selfcontained", async () => { // ensure flags const flags = context.options.flags || {}; - - // call complete handler (might e.g. run latexmk to complete the render) - finalOutput = await recipe.complete(pandocOptions) || recipe.output; - // determine whether this is self-contained output + finalOutput = recipe.output; + + // note that we intentionally call isSelfContainedOutput twice + // the first needs to happen before recipe completion + // because ingestion of self-contained output needs + // to happen before recipe completion (which cleans up some files) selfContained = isSelfContainedOutput( flags, format, finalOutput, ); - // If this is self-contained, run pandoc to 'suck in' the dependencies - // which may have been added in the post processor if (selfContained && isHtmlFileOutput(format.pandoc)) { await pandocIngestSelfContainedContent( outputFile, format.pandoc[kResourcePath], ); } + + // call complete handler (might e.g. run latexmk to complete the render) + finalOutput = (await recipe.complete(pandocOptions)) || recipe.output; + + // note that we intentionally call isSelfContainedOutput twice + // the second call happens because some recipes change + // their output extension on completion (notably, .pdf files) + // and become self-contained for purposes of cleanup + selfContained = isSelfContainedOutput( + flags, + format, + finalOutput, + ); }); // compute the relative path to the files dir diff --git a/tests/docs/self-contained/simple.qmd b/tests/docs/self-contained/simple.qmd new file mode 100644 index 00000000000..dea0a3fa2f5 --- /dev/null +++ b/tests/docs/self-contained/simple.qmd @@ -0,0 +1,7 @@ +--- +format: + html: + self-contained: true +--- + +## Hello \ No newline at end of file diff --git a/tests/smoke/self-contained/stdout.test.ts b/tests/smoke/self-contained/stdout.test.ts new file mode 100644 index 00000000000..f03a8e6c730 --- /dev/null +++ b/tests/smoke/self-contained/stdout.test.ts @@ -0,0 +1,14 @@ +import { quarto } from "../../../src/quarto.ts"; +import { test } from "../../test.ts"; + +test({ + name: "https://github.com/quarto-dev/quarto-cli/issues/11068", + context: { + setup: async() => { + await quarto(["render", "docs/self-contained/simple.qmd", "-o", "-"]); + } + }, + execute: async () => {}, + verify: [], + type: "smoke" +});