Skip to content

Commit 4383667

Browse files
committed
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.
1 parent 73805d3 commit 4383667

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/core/jupyter/jupyter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { ensureDirSync, walkSync } from "../../deno_ral/fs.ts";
1010
import { dirname, extname, join, relative } from "../../deno_ral/path.ts";
11+
import { warning } from "../../deno_ral/log.ts";
1112
import * as colors from "fmt/colors";
1213
import { decodeBase64 as base64decode } from "encoding/base64";
1314
import { stringify } from "../yaml.ts";
@@ -1554,10 +1555,13 @@ async function mdFromCodeCell(
15541555

15551556
for (const { index, output } of sortedOutputs) {
15561557
// compute output label
1557-
const outputLabel = label && labelCellContainer && isDisplayData(output)
1558+
const outputLabel = label && (labelCellContainer || Array.isArray(sortedOutputs)) && isDisplayData(output)
15581559
? (label + "-" + nextOutputSuffix++)
15591560
: label;
1560-
1561+
// If the user specifies a top-level array for images but also labels give a warning.
1562+
if (labelCellContainer === false && Array.isArray(sortedOutputs) == true) {
1563+
warning("Warning: using top-level figures with labels might result in unwanted behaviour.")
1564+
}
15611565
// If this output has been marked to not be displayed
15621566
// just continue
15631567
if (output.metadata?.[kQuartoOutputDisplay] === false) {

0 commit comments

Comments
 (0)