Skip to content

Commit

Permalink
fix(mjml-react): don't trim children, only the final content
Browse files Browse the repository at this point in the history
  • Loading branch information
mastertheblaster committed Feb 3, 2021
1 parent 27fe167 commit 03e853c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils/render-to-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const reconciler = ReactReconciler({
return res;
},
appendChildToContainer(container, child) {
trimContent(child);
container.resultObj = child;
},
appendInitialChild(parent, child) {
Expand Down Expand Up @@ -152,7 +153,15 @@ function escapeTextForBrowser(text) {
if (typeof text === 'boolean' || typeof text === 'number') {
return '' + text;
}
return escapeHtml(text.trim());
return escapeHtml(text);
}

function noop() {}

function trimContent(child) {
if (child.content) {
child.content = child.content.trim();
} else if (child.children) {
child.children.forEach(trimContent);
}
}
9 changes: 9 additions & 0 deletions test/render-to-json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ const useCases = [
<MjmlComment>{'<b /> & $ " '}</MjmlComment>,

<MjmlText>10$ & Free Delivery</MjmlText>,

<MjmlButton
spacesFromBothEnds=" both "
spaceFromLeft=" left"
spaceFromRight="right "
spaceInBetween=" in between "
>
{' '}Hello World ! <span> Hello World ! </span>{' '}
</MjmlButton>,
];

useCases.forEach((tree, i) => {
Expand Down

0 comments on commit 03e853c

Please sign in to comment.