Skip to content

Commit 771dcdf

Browse files
agoose77fwkoch
authored andcommitted
refactor: move user expression lowering into function
1 parent 9c1167b commit 771dcdf

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

packages/myst-cli/src/process/notebook.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ export async function processNotebook(
8484
return mdast;
8585
}
8686

87+
/**
88+
* Embed the Jupyter output data for a user expression into the AST
89+
*/
90+
function embedInlineExpressions(
91+
userExpressions: IUserExpressionMetadata[] | undefined,
92+
block: GenericNode,
93+
) {
94+
const inlineNodes = selectAll('inlineExpression', block) as InlineExpression[];
95+
inlineNodes.forEach((inlineExpression) => {
96+
const data = findExpression(userExpressions, inlineExpression.value);
97+
if (!data) return;
98+
inlineExpression.result = data.result as unknown as Record<string, unknown>;
99+
});
100+
}
101+
87102
export async function processNotebookFull(
88103
session: ISession,
89104
file: string,
@@ -136,17 +151,7 @@ export async function processNotebookFull(
136151
return acc.concat(...cellMdast.children);
137152
}
138153
const block = blockParent(cell, cellMdast.children) as GenericNode;
139-
140-
// Embed expression results into expression
141-
const userExpressions = block.data?.[metadataSection] as
142-
| IUserExpressionMetadata[]
143-
| undefined;
144-
const inlineNodes = selectAll('inlineExpression', block) as InlineExpression[];
145-
inlineNodes.forEach((inlineExpression) => {
146-
const data = findExpression(userExpressions, inlineExpression.value);
147-
if (!data) return;
148-
inlineExpression.result = data.result as unknown as Record<string, unknown>;
149-
});
154+
embedInlineExpressions(block.data?.[metadataSection], block);
150155
return acc.concat(block);
151156
}
152157
if (cell.cell_type === CELL_TYPES.raw) {

0 commit comments

Comments
 (0)