Skip to content

Commit 6be2beb

Browse files
committed
use better key prefix
1 parent e007711 commit 6be2beb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/core/jupyter/jupyter.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,11 +925,19 @@ export function jupyterCellWithOptions(
925925
const validMetadata: Record<string, string | number | boolean> = {};
926926
for (const key of Object.keys(cell.metadata)) {
927927
const value = cell.metadata[key];
928+
let jsonEncodedKeyIndex = 0;
928929
if (value !== undefined) {
929930
if (value && typeof value === "object") {
931+
// https://github.com/quarto-dev/quarto-cli/issues/9089
930932
// we need to json-encode this and signal the encoding in the key
933+
// we can't use the key as is since it may contain invalid characters
934+
// and modifying the key might introduce collisions
935+
// we ensure the key is unique with a counter, and assume
936+
// "quarto-private-*" to be a private namespace for quarto.
937+
// we'd prefer to use _quarto-* instead, but Pandoc doesn't allow keys to start
938+
// with an underscore.
931939
validMetadata[
932-
`quarto-json-encoded-${key.replaceAll(/[^A-Za-z]/g, "_")}`
940+
`quarto-private-${++jsonEncodedKeyIndex}`
933941
] = JSON.stringify({ key, value });
934942
} else if (
935943
typeof value === "string" || typeof value === "number" ||

0 commit comments

Comments
 (0)