From 2ba98ddaddcb4dcd170e20ca08f90dd4d2dc8c5c Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Mon, 28 Oct 2024 15:50:14 +0100 Subject: [PATCH] Handle NBSP in tiptap parsing (#8148) 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 https://github.com/ueberdosis/tiptap/pull/254) --- .../__tests__/parseEditorContent.test.ts | 29 +++++++++++++++++++ .../utils/parseEditorContent.ts | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/twenty-front/src/modules/workflow/search-variables/utils/__tests__/parseEditorContent.test.ts b/packages/twenty-front/src/modules/workflow/search-variables/utils/__tests__/parseEditorContent.test.ts index 1302ebb04a0f..537530d23a1c 100644 --- a/packages/twenty-front/src/modules/workflow/search-variables/utils/__tests__/parseEditorContent.test.ts +++ b/packages/twenty-front/src/modules/workflow/search-variables/utils/__tests__/parseEditorContent.test.ts @@ -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}}', + ); + }); }); diff --git a/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts b/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts index ebad7f0e9734..c27e655d0021 100644 --- a/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts +++ b/packages/twenty-front/src/modules/workflow/search-variables/utils/parseEditorContent.ts @@ -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') {