Skip to content

Commit

Permalink
Handle NBSP in tiptap parsing (#8148)
Browse files Browse the repository at this point in the history
Tiptap uses non breaking spaces between nodes (like variables). Those
html characters are not properly handles in emails. Replacing by regular
spaces during parsing.

I tried to fix it in settings but looks like this is only for preserving
those nbsp and not for removal (see
ueberdosis/tiptap#254)
  • Loading branch information
thomtrp authored Oct 28, 2024
1 parent fc8c9d9 commit 2ba98dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,33 @@ describe('parseEditorContent', () => {

expect(parseEditorContent(input)).toBe('First line\nSecond line');
});

it('should handle spaces between variables correctly', () => {
const input: JSONContent = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'variableTag',
attrs: { variable: '{{user.firstName}}' },
},
{
type: 'text',
text: '\u00A0', // NBSP character
},
{
type: 'variableTag',
attrs: { variable: '{{user.lastName}}' },
},
],
},
],
};

expect(parseEditorContent(input)).toBe(
'{{user.firstName}} {{user.lastName}}',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const parseEditorContent = (json: JSONContent): string => {
}

if (node.type === 'text') {
return node.text || '';
// Replace   with regular space
return node?.text?.replace(/\u00A0/g, ' ') ?? '';
}

if (node.type === 'hardBreak') {
Expand Down

0 comments on commit 2ba98dd

Please sign in to comment.