Skip to content
Closed
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
5 changes: 4 additions & 1 deletion src/core/jupyter/jupyter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ export async function quartoMdToJupyter(
}
delete yaml[key];
} else {
if (!kJupyterCellOptionKeys.includes(key)) {
// an option value of null means that it is an nbdev-style directive
if (!kJupyterCellOptionKeys.includes(key) && yaml[key] !== null) {
cell.metadata[key] = yaml[key];
delete yaml[key];
}
Expand Down Expand Up @@ -844,6 +845,8 @@ export function jupyterCellOptionsAsComment(
});
const commentChars = langCommentChars(language);
const yamlOutput = mdTrimEmptyLines(lines(cellYaml)).map((line) => {
// an option value of null means that the key is a nbdev-style directive
line = line.replace(/: null$/, "");
line = optionCommentPrefix(commentChars[0]) + line +
optionCommentSuffix(commentChars[1]);
return line + "\n";
Expand Down
11 changes: 11 additions & 0 deletions src/core/lib/partition-cell-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function partitionCellOptions(
yamlOption += line[line.length - 1];
}
}
yamlOption = fixNbdevDirective(yamlOption);
yamlLines.push(yamlOption);
optionsSource.push(line);
continue;
Expand Down Expand Up @@ -96,6 +97,16 @@ export function partitionCellOptions(
};
}

function fixNbdevDirective(line: string) {
// convert non-yaml nbdev-style directives to yaml keys with a null value
if (line.match(/^\w+\s*$/)) { // e.g. export
return line.replace(/(\s*)$/, ": null$1");
} else if (line.match(/^\w+\s+[^:\s]/)) { // e.g. default_exp foo
return line.replace(/(\s*)$/, ": null$1");
}
return line;
};

export async function parseAndValidateCellOptions(
mappedYaml: MappedString,
language: string,
Expand Down