Skip to content

Commit

Permalink
feat: add one do not translate component and serialize/deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
roadlittledawn committed Dec 6, 2021
1 parent ba4c2b6 commit b457abe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
35 changes: 10 additions & 25 deletions scripts/actions/utils/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,12 @@ module.exports = {
serialize: serializeComponent,
},
DoNotTranslate: {
deserialize: (h, node) => {
console.dir('serialized node', node);
const results = h(
node,
'code',
deserializeJSValue(node.properties.dataProps)
);
console.dir('deserialized results', results);
return results;
},
serialize: (h, node) => {
console.dir('mdx node', node);
const results = h(
node,
'div',
{
'data-type': 'component',
'data-component': 'DoNotTranslate',
'data-props': serializeJSValue(omit(node, ['type'])),
},
[h(node, 'div')]
);
console.dir('serialized node', results);
return results;
},
deserialize: deserializeComponent,
serialize: (h, node) =>
serializeComponent(h, node, {
classNames: 'notranslate',
wrapChildren: false,
}),
},
ExternalLink: {
deserialize: deserializeComponent,
Expand Down Expand Up @@ -326,4 +307,8 @@ module.exports = {
deserialize: deserializeComponent,
serialize: serializeComponent,
},
br: {
deserialize: deserializeComponent,
serialize: serializeComponent,
},
};
2 changes: 2 additions & 0 deletions scripts/actions/utils/serialization-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const serializeComponent = (
node,
{
tagName,
classNames = '',
textAttributes = [],
wrapChildren = true,
identifyComponent = true,
Expand All @@ -89,6 +90,7 @@ const serializeComponent = (
'data-type': 'component',
'data-component': identifyComponent ? getComponentName(node) : null,
'data-props': serializeProps(node),
class: classNames || null,
}),
textAttributes
.map((name) => serializeTextProp(h, node, name))
Expand Down

0 comments on commit b457abe

Please sign in to comment.