From 438366757fef32bb51c4d968e055162afa088a83 Mon Sep 17 00:00:00 2001 From: Peter Kandolf Date: Fri, 11 Apr 2025 11:09:05 +0200 Subject: [PATCH 1/5] feat: allow labels for multiple top-level figures Emit a warning if a user combines multiple top-level figures with labels. Use the same mechanism as for sub-figures to number them. This will result in the original label without a number no existing, as it would no make any sense to have it. Without this change the label points to the last figure. --- src/core/jupyter/jupyter.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/jupyter/jupyter.ts b/src/core/jupyter/jupyter.ts index a3e5923f79..be67aa1f59 100644 --- a/src/core/jupyter/jupyter.ts +++ b/src/core/jupyter/jupyter.ts @@ -8,6 +8,7 @@ import { ensureDirSync, walkSync } from "../../deno_ral/fs.ts"; import { dirname, extname, join, relative } from "../../deno_ral/path.ts"; +import { warning } from "../../deno_ral/log.ts"; import * as colors from "fmt/colors"; import { decodeBase64 as base64decode } from "encoding/base64"; import { stringify } from "../yaml.ts"; @@ -1554,10 +1555,13 @@ async function mdFromCodeCell( for (const { index, output } of sortedOutputs) { // compute output label - const outputLabel = label && labelCellContainer && isDisplayData(output) + const outputLabel = label && (labelCellContainer || Array.isArray(sortedOutputs)) && isDisplayData(output) ? (label + "-" + nextOutputSuffix++) : label; - + // If the user specifies a top-level array for images but also labels give a warning. + if (labelCellContainer === false && Array.isArray(sortedOutputs) == true) { + warning("Warning: using top-level figures with labels might result in unwanted behaviour.") + } // If this output has been marked to not be displayed // just continue if (output.metadata?.[kQuartoOutputDisplay] === false) { From 710bd9e65ec0f39fe30658850fbf39a9bbe78c16 Mon Sep 17 00:00:00 2001 From: Peter Kandolf Date: Fri, 11 Apr 2025 11:35:30 +0200 Subject: [PATCH 2/5] feat: fine tune warning --- src/core/jupyter/jupyter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/jupyter/jupyter.ts b/src/core/jupyter/jupyter.ts index be67aa1f59..def46f1a68 100644 --- a/src/core/jupyter/jupyter.ts +++ b/src/core/jupyter/jupyter.ts @@ -1560,7 +1560,7 @@ async function mdFromCodeCell( : label; // If the user specifies a top-level array for images but also labels give a warning. if (labelCellContainer === false && Array.isArray(sortedOutputs) == true) { - warning("Warning: using top-level figures with labels might result in unwanted behaviour.") + warning("Warning: using multiple top-level figures with labels might result in unwanted behaviour.") } // If this output has been marked to not be displayed // just continue From 7124535f0ffa6363ba76875de15874da180ea44e Mon Sep 17 00:00:00 2001 From: Peter Kandolf Date: Fri, 11 Apr 2025 11:48:23 +0200 Subject: [PATCH 3/5] docs: incldue change in changelog --- news/changelog-1.7.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.7.md b/news/changelog-1.7.md index 2071de9389..056122e91b 100644 --- a/news/changelog-1.7.md +++ b/news/changelog-1.7.md @@ -173,6 +173,7 @@ All changes included in 1.7: - ([#11951](https://github.com/quarto-dev/quarto-cli/issues/11951)): Raw LaTeX table without `tbl-` prefix label for using Quarto crossref are now correctly passed through unmodified. - ([#11967](https://github.com/quarto-dev/quarto-cli/issues/11967)): Produce a better error message when YAML metadata with `!expr` tags are used outside of `knitr` code cells. - ([#12117](https://github.com/quarto-dev/quarto-cli/issues/12117)): Color output to stdout and stderr is now correctly rendered for `html` format in the Jupyter and Julia engines. +- ([#12167](https://github.com/quarto-dev/quarto-cli/issues/12167)): Figure numbering for multiple top-level figures and not as Sub-Figures. - ([#12264](https://github.com/quarto-dev/quarto-cli/issues/12264)): Upgrade `dart-sass` to 1.85.1. - ([#12238](https://github.com/quarto-dev/quarto-cli/issues/12238)): Do not truncate very long console errors (e.g. in Jupyter Notebook with backtrace). - ([#12338](https://github.com/quarto-dev/quarto-cli/issues/12338)): Add an additional workaround for the SCSS parser used in color variable extraction. From 2542e4d2c7ecd795536a8c8f555dff40615a8bc0 Mon Sep 17 00:00:00 2001 From: Peter Kandolf Date: Fri, 11 Apr 2025 14:53:37 +0200 Subject: [PATCH 4/5] fix: correctly check for length of array --- src/core/jupyter/jupyter.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/jupyter/jupyter.ts b/src/core/jupyter/jupyter.ts index def46f1a68..edebed5073 100644 --- a/src/core/jupyter/jupyter.ts +++ b/src/core/jupyter/jupyter.ts @@ -1555,11 +1555,18 @@ async function mdFromCodeCell( for (const { index, output } of sortedOutputs) { // compute output label - const outputLabel = label && (labelCellContainer || Array.isArray(sortedOutputs)) && isDisplayData(output) + const outputLabel = label && + ( + labelCellContainer || + (Array.isArray(sortedOutputs) && (sortedOutputs.length > 1)) + ) && + isDisplayData(output) ? (label + "-" + nextOutputSuffix++) : label; // If the user specifies a top-level array for images but also labels give a warning. - if (labelCellContainer === false && Array.isArray(sortedOutputs) == true) { + if (labelCellContainer === false && + (Array.isArray(sortedOutputs) == true && (sortedOutputs.length > 1)) + ) { warning("Warning: using multiple top-level figures with labels might result in unwanted behaviour.") } // If this output has been marked to not be displayed From 733f8b77fa7f3a6007e5480280cf592f97d6e648 Mon Sep 17 00:00:00 2001 From: Peter Kandolf Date: Fri, 11 Apr 2025 20:54:34 +0200 Subject: [PATCH 5/5] fix: nicer structure and warning is only emitted when necessary --- src/core/jupyter/jupyter.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/core/jupyter/jupyter.ts b/src/core/jupyter/jupyter.ts index edebed5073..3fc1a4a20a 100644 --- a/src/core/jupyter/jupyter.ts +++ b/src/core/jupyter/jupyter.ts @@ -1555,20 +1555,22 @@ async function mdFromCodeCell( for (const { index, output } of sortedOutputs) { // compute output label - const outputLabel = label && + let outputLabel_tmp = label; + if (label && ( labelCellContainer || (Array.isArray(sortedOutputs) && (sortedOutputs.length > 1)) ) && - isDisplayData(output) - ? (label + "-" + nextOutputSuffix++) - : label; - // If the user specifies a top-level array for images but also labels give a warning. - if (labelCellContainer === false && - (Array.isArray(sortedOutputs) == true && (sortedOutputs.length > 1)) - ) { - warning("Warning: using multiple top-level figures with labels might result in unwanted behaviour.") + isDisplayData(output)) { + outputLabel_tmp = label + "-" + nextOutputSuffix++; + // If the user specifies a top-level array for images but also labels give a warning. + if (labelCellContainer === false && + (Array.isArray(sortedOutputs) == true && (sortedOutputs.length > 1)) + ) { + warning("Warning: using multiple top-level figures with labels might result in unwanted behaviour: " + label) + } } + const outputLabel = outputLabel_tmp // If this output has been marked to not be displayed // just continue if (output.metadata?.[kQuartoOutputDisplay] === false) {