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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Inline expression parsing #1056

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gorgeous-pans-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-execute": patch
---

Better error messages when connection to Jupyter fails
5 changes: 5 additions & 0 deletions .changeset/shy-taxis-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-cli": patch
---

Cell metadata from jupyter should not be serialized to `meta` on the block.
4 changes: 2 additions & 2 deletions packages/myst-cli/src/process/notebook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NotebookCell, RuleId, fileWarn } from 'myst-common';
import { NotebookCell, RuleId, copyNode, fileWarn } from 'myst-common';
import type { GenericNode, GenericParent } from 'myst-common';
import { selectAll } from 'unist-util-select';
import { nanoid } from 'nanoid';
Expand All @@ -22,7 +22,7 @@ import type { IUserExpressionMetadata } from '../transforms/index.js';

function blockParent(cell: ICell, children: GenericNode[]) {
const type = cell.cell_type === CELL_TYPES.code ? NotebookCell.code : NotebookCell.content;
return { type: 'block', meta: JSON.stringify({ type, ...cell.metadata }), children };
return { type: 'block', data: copyNode({ type, ...cell.metadata }), children };
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The meta --> data happens in a transform but the inline expressions happen before that transform is run. I think that storing things in meta is a relic of how we used to parse based on strings, and I think we may be able to drop that part. @fwkoch can you confirm?

Copy link
Member

@fwkoch fwkoch Apr 4, 2024

Choose a reason for hiding this comment

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

Yeah, I think this is fine to do here. meta -> data transform keeps anything that already exists in data, so putting things in data earlier is ok.

We can't totally drop the meta support yet, I don't think, because it's still used in myst-parser for keeping track of content on blockBreaks (which will be converted to blocks later) https://github.com/executablebooks/mystmd/blob/main/packages/myst-parser/src/tokensToMyst.ts#L468

But... we could probably do a JSON.parse there instead, e.g.

  myst_block_break: {
    type: 'blockBreak',
    noCloseToken: true,
    isLeaf: true,
    getAttrs(t) {
      return {
        data: JSON.parse(t.content) || undefined,
      };
    },

then we could maybe get rid of the meta transform entirely...?

There's still some other vestiges of meta we would need to clean up, e.g. https://github.com/executablebooks/mystmd/blob/main/packages/myst-to-md/src/misc.ts#L14 (but that one probably doesn't work anyway as is, since meta is deleted after transforming to data...)


/**
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-execute/src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export async function kernelExecutionTransform(tree: GenericParent, vfile: VFile
.startNew(sessionOpts)
.catch((err) => {
log.debug((err as Error).stack);
log.error('Jupyter connection error');
log.error(`Jupyter Connection Error: ${(err as Error).message}`);
})
.then(async (conn) => {
if (!conn) return;
Expand Down