Skip to content

Commit

Permalink
refactor: store future AST as actual object
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Jan 14, 2025
1 parent b257932 commit bd0ee78
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 7 deletions.
5 changes: 2 additions & 3 deletions packages/myst-cli/src/transforms/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export function externalASTToInternal(ast: GenericParent) {
}
// Case 2: "compatible" AST
else if (parent && parent.type !== 'outputs' && '_future_ast' in node) {
const outputs = JSON.parse(node._future_ast);
parent.children[index!] = outputs;
parent.children[index!] = node._future_ast;
return SKIP;
}
// Case 3: "future" AST
Expand Down Expand Up @@ -109,7 +108,7 @@ export function externalASTToInternal(ast: GenericParent) {
export function internalASTToExternal(ast: GenericParent) {
const outputsNodes = selectAll('outputs', ast) as GenericParent[];
outputsNodes.forEach((outputsNode) => {
outputsNode._future_ast = JSON.stringify(outputsNode);
outputsNode._future_ast = structuredClone(outputsNode);

outputsNode.type = 'output';
outputsNode.data = outputsNode.children
Expand Down
105 changes: 101 additions & 4 deletions packages/mystmd/tests/notebook-fig-embed/outputs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,30 @@
"children": [
{
"type": "output",
"_future_ast": "{\"type\":\"outputs\",\"children\":[{\"type\":\"output\",\"id\":\"Ffu3R5cJjHblGUbO46YxC\",\"jupyter_data\":{\"output_type\":\"execute_result\",\"execution_count\":2,\"metadata\":{},\"data\":{\"text/html\":{\"content_type\":\"text/html\",\"hash\":\"a16fcedcd26437c820ccfc05d1f48a57\",\"path\":\"/a16fcedcd26437c820ccfc05d1f48a57.html\"},\"text/plain\":{\"content\":\"alt.Chart(...)\",\"content_type\":\"text/plain\"}}},\"key\":\"aicFc0saqi\"}],\"key\":\"dSx0jlrAGq\"}",
"_future_ast": {
"children": [
{
"jupyter_data": {
"data": {
"text/html": {
"content_type": "text/html",
"hash": "a16fcedcd26437c820ccfc05d1f48a57",
"path": "/a16fcedcd26437c820ccfc05d1f48a57.html"
},
"text/plain": {
"content": "alt.Chart(...)",
"content_type": "text/plain"
}
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
"type": "output"
}
],
"type": "outputs"
},
"data": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -145,7 +168,30 @@
},
{
"type": "output",
"_future_ast": "{\"type\":\"outputs\",\"children\":[{\"type\":\"output\",\"id\":\"Ffu3R5cJjHblGUbO46YxC\",\"jupyter_data\":{\"output_type\":\"execute_result\",\"execution_count\":2,\"metadata\":{},\"data\":{\"text/html\":{\"content_type\":\"text/html\",\"hash\":\"a16fcedcd26437c820ccfc05d1f48a57\",\"path\":\"/a16fcedcd26437c820ccfc05d1f48a57.html\"},\"text/plain\":{\"content\":\"alt.Chart(...)\",\"content_type\":\"text/plain\"}}},\"key\":\"Na254yM4lm\"}],\"key\":\"hODUzanXjz\"}",
"_future_ast": {
"children": [
{
"jupyter_data": {
"data": {
"text/html": {
"content_type": "text/html",
"hash": "a16fcedcd26437c820ccfc05d1f48a57",
"path": "/a16fcedcd26437c820ccfc05d1f48a57.html"
},
"text/plain": {
"content": "alt.Chart(...)",
"content_type": "text/plain"
}
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
"type": "output"
}
],
"type": "outputs"
},
"data": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -192,7 +238,32 @@
"children": [
{
"type": "output",
"_future_ast": "{\"type\":\"outputs\",\"children\":[{\"type\":\"output\",\"jupyter_data\":{\"output_type\":\"execute_result\",\"execution_count\":2,\"metadata\":{},\"data\":{\"text/html\":{\"content_type\":\"text/html\",\"hash\":\"a85dae82213ec48ea05754a345bab5ce\",\"path\":\"https://cdn.curvenote.com/0192bff5-9c9d-722f-92bf-e702aa8e1f46/public/a85dae82213ec48ea05754a345bab5ce.html\"},\"text/plain\":{\"content\":\"alt.VConcatChart(...)\",\"content_type\":\"text/plain\"}}},\"children\":[],\"key\":\"yzzP9Mn8wY\"}],\"visibility\":\"show\",\"key\":\"f7fQ28USQb\"}",
"_future_ast": {
"children": [
{
"children": [],
"jupyter_data": {
"data": {
"text/html": {
"content_type": "text/html",
"hash": "a85dae82213ec48ea05754a345bab5ce",
"path": "https://cdn.curvenote.com/01944f0b-783c-7ea2-8d19-f59b784cd49e/public/a85dae82213ec48ea05754a345bab5ce.html"
},
"text/plain": {
"content": "alt.VConcatChart(...)",
"content_type": "text/plain"
}
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
"type": "output"
}
],
"type": "outputs",
"visibility": "show"
},
"data": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -289,7 +360,33 @@
},
{
"type": "output",
"_future_ast": "{\"type\":\"outputs\",\"children\":[{\"type\":\"output\",\"jupyter_data\":{\"output_type\":\"execute_result\",\"execution_count\":2,\"metadata\":{},\"data\":{\"text/html\":{\"content_type\":\"text/html\",\"hash\":\"a85dae82213ec48ea05754a345bab5ce\",\"path\":\"https://cdn.curvenote.com/0192bff5-9c9d-722f-92bf-e702aa8e1f46/public/a85dae82213ec48ea05754a345bab5ce.html\"},\"text/plain\":{\"content\":\"alt.VConcatChart(...)\",\"content_type\":\"text/plain\"}}},\"children\":[],\"key\":\"gKECmUtMaA\"}],\"visibility\":\"show\",\"key\":\"Mt6Gpq3tTq\"}",
"_future_ast": {
"children": [
{
"children": [],
"jupyter_data": {
"data": {
"text/html": {
"content_type": "text/html",
"hash": "a85dae82213ec48ea05754a345bab5ce",
"path": "https://cdn.curvenote.com/01944f0b-783c-7ea2-8d19-f59b784cd49e/public/a85dae82213ec48ea05754a345bab5ce.html"
},
"text/plain": {
"content": "alt.VConcatChart(...)",
"content_type": "text/plain"
}
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
"type": "output"
}
],
"type": "outputs",
"visibility": "show"
},

"data": [
{
"output_type": "execute_result",
Expand Down

0 comments on commit bd0ee78

Please sign in to comment.