Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛠 fix for empty blocks in notebooks #134

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 5 additions & 0 deletions .changeset/friendly-cooks-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@myst-theme/jupyter': patch
---

Patch myst-block bug
4 changes: 2 additions & 2 deletions packages/jupyter/src/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function notebookFromMdast(
//Object.assign(notebook.metadata, ipynb.metadata);
notebook.cells = (mdast.children as GenericParent[]).map((block: GenericParent) => {
if (block.type !== 'block') console.warn(`Unexpected block type ${block.type}`);
if (block.children.length == 2 && block.children[0].type === 'code') {
if (block.children && block.children.length == 2 && block.children[0].type === 'code') {
const [codeCell, output] = block.children;

// use the block.key to identify the cell but maintain a mapping
Expand All @@ -105,7 +105,7 @@ export function notebookFromMdast(
const cell = new core.ThebeNonExecutableCell(
block.key,
notebook.id,
block.children.reduce((acc, child) => acc + '\n' + (child.value ?? ''), ''),
block.children?.reduce((acc, child) => acc + '\n' + (child.value ?? ''), ''),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the if-statement will also fall through to here. This will mean that the content is undefined?

Is that fine? I am not sure what the ThebeNonExecutableCell does in this case!

Copy link
Contributor Author

@stevejpurves stevejpurves Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch -- the no children condition only occurs with empty markdown (both code and raw cells have children) cells, so we want to create the non executable cell with an empty source string in that case

block.data ?? {},
notebook.rendermime,
);
Expand Down