Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.11.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ All changes included in 1.11:
### Websites

- ([#14974](https://github.com/quarto-dev/quarto-cli/issues/14974)): Fix math in `.llms.md` files from `llms-txt` coming out garbled with the default `mathjax` method, and with `katex` and `webtex`. Math is now written as `$...$` and `$$...$$` with the `mathjax`, `katex`, `webtex` and `mathml` methods.
- ([#15004](https://github.com/quarto-dev/quarto-cli/issues/15004)): Fix notebook preview pages and notebook sources missing from the output directory when a website with embedded notebooks is rendered from a directory other than the project directory.

## Lua API

Expand Down
26 changes: 11 additions & 15 deletions src/format/html/format-html-notebook-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,33 +223,29 @@ export const notebookPreviewer = (
);
}

// Forward along resources and supporting files from previews
// Forward along resources and supporting files from previews.
// Supporting files must be absolute so they resolve regardless of
// the cwd; the stored (project-relative) entries are not mutated.
const absoluteSupporting = (entries: string[]) =>
entries.map((s) =>
project && !isAbsolute(s) ? join(project.dir, s) : s
);
const supporting: string[] = [];
const resources: string[] = [];
if (renderedNotebook[kRenderedIPynb]) {
const renderedIpynb = renderedNotebook[kRenderedIPynb];
if (renderedIpynb) {
if (project) {
supporting.push(
relative(project.dir, renderedIpynb.hrefPath),
);
} else {
supporting.push(renderedIpynb.hrefPath);
}
supporting.push(...renderedIpynb.supporting);
supporting.push(renderedIpynb.hrefPath);
supporting.push(...absoluteSupporting(renderedIpynb.supporting));
resources.push(...renderedIpynb.resourceFiles.files);
}
}

if (renderedNotebook[kHtmlPreview]) {
const htmlPreview = renderedNotebook[kHtmlPreview];
if (htmlPreview) {
if (project) {
supporting.push(relative(project.dir, htmlPreview.hrefPath));
} else {
supporting.push(htmlPreview.hrefPath);
}
supporting.push(...htmlPreview.supporting);
supporting.push(htmlPreview.hrefPath);
supporting.push(...absoluteSupporting(htmlPreview.supporting));
resources.push(...htmlPreview.resourceFiles.files);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/format/html/format-html-notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ export async function emplaceNotebookPreviews(

if (nbPath.resources) {
resources.push(...nbPath.resources.map((file) => {
return project ? relative(project?.dir, file) : file;
return project && isAbsolute(file)
? relative(project.dir, file)
: file;
}));
}

Expand Down
3 changes: 3 additions & 0 deletions tests/docs/site-qmd-embed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.quarto/

**/*.quarto_ipynb
2 changes: 2 additions & 0 deletions tests/docs/site-qmd-embed/_quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
project:
type: website
9 changes: 9 additions & 0 deletions tests/docs/site-qmd-embed/computations.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Computations
jupyter: python3
---

```{python}
#| label: answer
print(42)
```
5 changes: 5 additions & 0 deletions tests/docs/site-qmd-embed/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Home
---

{{< embed computations.qmd#answer >}}
2 changes: 2 additions & 0 deletions tests/docs/site/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/.quarto/

**/*.quarto_ipynb
54 changes: 51 additions & 3 deletions tests/smoke/site/render-site.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,57 @@
* Copyright (C) 2020-2022 Posit Software, PBC
*
*/
import { existsSync } from "../../../src/deno_ral/fs.ts";
import { join } from "../../../src/deno_ral/path.ts";
import { docs } from "../../utils.ts";
import { fileExists } from "../../verify.ts";
import { testSite } from "./site.ts";

testSite(docs("site/index.qmd"), docs("site/index.qmd"), [
".quarto-embed-nb-cell", // Embed is present
], []);
// The test runs from tests/, outside the project directory, so this also
// covers notebook preview files reaching _site when cwd != project dir.
const siteNotebooks = join(docs("site"), "_site", "notebooks");

testSite(
docs("site/index.qmd"),
docs("site/index.qmd"),
[
".quarto-embed-nb-cell", // Embed is present
],
[],
undefined,
fileExists(join(siteNotebooks, "computations-preview.html")),
fileExists(join(siteNotebooks, "computations.out.ipynb")),
fileExists(
join(
siteNotebooks,
"computations_files",
"figure-html",
"fig-visualization-output-1.png",
),
),
);

// A qmd source embed gets a preview page and a downloadable copy of the source.
const siteQmdEmbed = join(docs("site-qmd-embed"), "_site");
// A cached embed rendering from a previous render changes what is emitted
// (see #10756), so each run starts without the scratch directory; testSite
// removes it on teardown.
const removeQmdEmbedScratch = () => {
const scratch = join(docs("site-qmd-embed"), ".quarto");
if (existsSync(scratch)) {
Deno.removeSync(scratch, { recursive: true });
}
return Promise.resolve();
};

testSite(
docs("site-qmd-embed/index.qmd"),
docs("site-qmd-embed/index.qmd"),
[
".quarto-embed-nb-cell", // Embed is present
],
[],
{ setup: removeQmdEmbedScratch },
fileExists(join(siteQmdEmbed, "computations.embed-preview.html")),
fileExists(join(siteQmdEmbed, "computations.qmd")),
);
17 changes: 10 additions & 7 deletions tests/smoke/site/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*
* Copyright (C) 2020-2022 Posit Software, PBC
*/
import { existsSync } from "../../../src/deno_ral/fs.ts";
import { dirname } from "../../../src/deno_ral/path.ts";
import { removeIfExists } from "../../../src/core/path.ts";
import { dirname, join } from "../../../src/deno_ral/path.ts";
import { testQuartoCmd, Verify, TestContext, mergeTestContexts } from "../../test.ts";
import { projectOutputForInput } from "../../utils.ts";
import { findProjectDir, projectOutputForInput } from "../../utils.ts";
import { ensureHtmlElements, noErrorsOrWarnings } from "../../verify.ts";

export const testSite = (
Expand All @@ -26,11 +26,14 @@ export const testSite = (
);

const baseContext: TestContext = {
teardown: async () => {
const siteDir = dirname(output.outputPath);
if (existsSync(siteDir)) {
await Deno.remove(siteDir, { recursive: true });
teardown: () => {
removeIfExists(dirname(output.outputPath));
// Remove the project scratch so its state can't leak into later renders
const projectDir = findProjectDir(input);
if (projectDir) {
removeIfExists(join(projectDir, ".quarto"));
}
return Promise.resolve();
},
};

Expand Down
Loading