Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tabathadelane committed Mar 29, 2024
1 parent 20a2260 commit 845b36e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions scripts/actions/utils/deserialization-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
});
Expand All @@ -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));
Expand All @@ -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(
Expand All @@ -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
Expand Down
14 changes: 9 additions & 5 deletions scripts/actions/utils/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
},
Expand Down

0 comments on commit 845b36e

Please sign in to comment.