diff --git a/news/changelog-1.7.md b/news/changelog-1.7.md index 2071de93890..697df9bc858 100644 --- a/news/changelog-1.7.md +++ b/news/changelog-1.7.md @@ -64,7 +64,11 @@ All changes included in 1.7: ## Formats -## `html` +### `dashboard` + +- ([#11338](https://github.com/quarto-dev/quarto-cli/issues/11338)): Remove unused datatables imports when appropriate. + +### `html` - ([#1325](https://github.com/quarto-dev/quarto-cli/issues/1325)): Dark Mode pages should not flash light on reload. (Nor should Light Mode pages flash dark.) - ([#1470](https://github.com/quarto-dev/quarto-cli/issues/1470)): `respect-user-color-scheme` enables checking the media query `prefers-color-scheme` for user dark mode preference. Author preference still influences stylesheet order and NoJS experience. Defaults to `false`, leaving to author preference. @@ -76,7 +80,7 @@ All changes included in 1.7: - ([#12319](https://github.com/quarto-dev/quarto-cli/pull/12319)): Provide switchable light and dark brands for a page with `brand.light` and `brand.dark`. - ([#12356](https://github.com/quarto-dev/quarto-cli/issues/12356)): Remove duplicate id in HTML document when using `#lst-` prefix label for using Quarto crossref. -## `pdf` +### `pdf` - ([#11835](https://github.com/quarto-dev/quarto-cli/issues/11835)): Take markdown structure into account when detecting minimum heading level. - ([#11878](https://github.com/quarto-dev/quarto-cli/issues/11878), [#12085](https://github.com/quarto-dev/quarto-cli/issues/12085)): Correctly fixup raw LaTeX table having an unexpected table env with options (e.g `\begin{table}[!ht]`) to be handled as crossref table. @@ -92,16 +96,16 @@ All changes included in 1.7: - New Quarto partials: `babel-lang.tex`, `biblio-config.tex`. Quarto's partials uses `.tex` extension. - BREAKING CHANGE for templates authors: `common.latex` does now uses `pandoc.tex` partial from Quarto, which include now part of the content that was in main `template.tex`. If you modify `pandoc.tex` as part of a custom format, it should be updated to new content. -## `jats` +### `jats` - Update to Pandoc's template following Pandoc 3.6.3 support: - `article.jats_publishing` partials now support `author.roles` -## `revealjs` +### `revealjs` - ([#12307](https://github.com/quarto-dev/quarto-cli/issues/12307)): Tabsets using `tabby.js` in Revealjs now correctly render reactive content when `server: shiny` is used. -## `typst` format +### `typst` format - ([#11578](https://github.com/quarto-dev/quarto-cli/issues/11578)): Typst column layout widths use fractional `fr` units instead of percent `%` units for unitless and default widths in order to fill the enclosing block and not spill outside it. - ([#11676](https://github.com/quarto-dev/quarto-cli/pull/11676)): Convert unitless image widths from pixels to inches for column layouts. diff --git a/src/format/dashboard/format-dashboard-tables.ts b/src/format/dashboard/format-dashboard-tables.ts index ca0f3c6a71b..73057db298b 100644 --- a/src/format/dashboard/format-dashboard-tables.ts +++ b/src/format/dashboard/format-dashboard-tables.ts @@ -35,6 +35,9 @@ export function processDatatables( const scriptNodes = doc.querySelectorAll( ".cell-output script[type='module']", ); + + let keepDeps = false; + for (const scriptNode of scriptNodes) { const scriptEl = scriptNode as Element; const code = scriptEl.innerText; @@ -57,6 +60,7 @@ export function processDatatables( } if (hasConnectedDt) { + keepDeps = true; // Replace the table initialization const codeText = codeFiltered.join("\n"); // for iTables < 1.7, do fixups @@ -82,21 +86,23 @@ export function processDatatables( linkCssEl.remove(); } } - - // We found tables, clear the DT sentinel attr - const dtNodes = doc.querySelectorAll(`[${kDTTableSentinel}="true"]`); - dtNodes.forEach((node) => { - (node as Element).removeAttribute(kDTTableSentinel); - }); - } else { - // We didn't find any DT, remove the dependencies that we injected at the root level - const dtNodes = doc.querySelectorAll(`[${kDTTableSentinel}="true"]`); - dtNodes.forEach((node) => { - (node as Element).remove(); - }); } } + if (keepDeps) { + // We found tables, clear the DT sentinel attr + const dtNodes = doc.querySelectorAll(`[${kDTTableSentinel}="true"]`); + dtNodes.forEach((node) => { + (node as Element).removeAttribute(kDTTableSentinel); + }); + } else { + // We didn't find any DT, remove the dependencies that we injected at the root level + const dtNodes = doc.querySelectorAll(`[${kDTTableSentinel}="true"]`); + dtNodes.forEach((node) => { + (node as Element).remove(); + }); + } + return { resources, supporting, diff --git a/src/format/dashboard/format-dashboard.ts b/src/format/dashboard/format-dashboard.ts index a067d823daa..78543f3dc7e 100644 --- a/src/format/dashboard/format-dashboard.ts +++ b/src/format/dashboard/format-dashboard.ts @@ -36,6 +36,7 @@ import { ProjectContext } from "../../project/types.ts"; import { registerWriterFormatHandler } from "../format-handlers.ts"; import { kPageLayout, kPageLayoutCustom } from "../html/format-html-shared.ts"; import { htmlFormat } from "../html/format-html.ts"; +import { kDTTableSentinel } from "./format-dashboard-shared.ts"; import { join } from "../../deno_ral/path.ts"; import { @@ -199,7 +200,7 @@ export function dashboardFormat() { join("js", "dt", "datatables.min.js"), ), attribs: { - kDTTableSentinel: "true", + [kDTTableSentinel]: "true", }, }); stylesheets.push({ @@ -209,7 +210,7 @@ export function dashboardFormat() { join("js", "dt", "datatables.min.css"), ), attribs: { - kDTTableSentinel: "true", + [kDTTableSentinel]: "true", }, }); scripts.push({ @@ -219,7 +220,7 @@ export function dashboardFormat() { join("js", "dt", "pdfmake.min.js"), ), attribs: { - kDTTableSentinel: "true", + [kDTTableSentinel]: "true", }, }); scripts.push({ @@ -229,7 +230,7 @@ export function dashboardFormat() { join("js", "dt", "vfs_fonts.js"), ), attribs: { - kDTTableSentinel: "true", + [kDTTableSentinel]: "true", }, }); diff --git a/tests/docs/smoke-all/2025/04/11/issue-11338.qmd b/tests/docs/smoke-all/2025/04/11/issue-11338.qmd new file mode 100644 index 00000000000..2d2270535a7 --- /dev/null +++ b/tests/docs/smoke-all/2025/04/11/issue-11338.qmd @@ -0,0 +1,9 @@ +--- +format: dashboard +_quarto: + tests: + dashboard: + ensureFileRegexMatches: + - [] + - ["kdttablesentinel"] +--- \ No newline at end of file