From 845b36ecb1e8b90ebcc18908b49afb00f5f0798c Mon Sep 17 00:00:00 2001 From: Tabatha Zeitke Date: Fri, 29 Mar 2024 17:06:36 -0500 Subject: [PATCH] wip --- scripts/actions/utils/deserialization-helpers.js | 8 ++++---- scripts/actions/utils/handlers.js | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/actions/utils/deserialization-helpers.js b/scripts/actions/utils/deserialization-helpers.js index be1d21d14ca..18d845bc4d0 100644 --- a/scripts/actions/utils/deserialization-helpers.js +++ b/scripts/actions/utils/deserialization-helpers.js @@ -15,7 +15,7 @@ const hasChildren = (node) => node.children && node.children.length; const inlineCodeAttribute = () => (tree) => { visit(tree, 'inlineCode', (node) => { - node.type = 'mdxJsxTextElement'; + node.type = 'mdxSpanElement'; node.name = 'InlineCode'; node.children = [u('text', node.value)]; }); @@ -37,7 +37,7 @@ const deserializeAttributeValue = (h, node) => { } if (node.type === 'element') { - const tree = deserializeComponent(h, node, { type: 'mdxJsxTextElement' }); + const tree = deserializeComponent(h, node, { type: 'mdxSpanElement' }); const transformedTree = attributeProcessor.runSync(tree); return mdxValueExpression(attributeProcessor.stringify(transformedTree)); @@ -55,7 +55,7 @@ const deserializeComponent = ( const name = dataComponent || node.tagName; const props = dataProps ? deserializeJSValue(dataProps) : []; const inferredType = - node.tagName === 'span' ? 'mdxJsxTextElement' : 'mdxJsxFlowElement'; + node.tagName === 'span' ? 'mdxSpanElement' : 'mdxBlockElement'; const hasWrappedChildren = hasChildren(node) ? node.children.some( @@ -75,7 +75,7 @@ const deserializeComponent = ( const attributes = textProps.reduce((attributes, node) => { const { dataProp: name } = node.properties; - const value = deserializeAttributeValue(h, node.children[0]); + const value = deserializeAttributeValue(state, node.children[0]); const idx = attributes.findIndex((attr) => attr.name === name); return idx === -1 diff --git a/scripts/actions/utils/handlers.js b/scripts/actions/utils/handlers.js index f97698549b2..8f1b9dfc964 100644 --- a/scripts/actions/utils/handlers.js +++ b/scripts/actions/utils/handlers.js @@ -20,17 +20,21 @@ module.exports = { 'data-component': 'CodeBlock', 'data-props': serializeJSValue(omit(node, ['type'])), }), - deserialize: (state, node) => ({ - type: 'code', - children: state.all(deserializeJSValue(node.properties.dataProps)), - }), + deserialize: (state, node) => { + const { lang, value } = deserializeJSValue(node.properties.dataProps); + return { + type: 'code', + value, + lang, + }; + }, }, import: { deserialize: (_state, node) => { const value = Buffer.from(node.properties.dataValue, 'base64').toString(); return { - type: 'import', + type: 'mdxjsEsm', value, }; },