diff --git a/apps/server/src/collaboration/collaboration.util.ts b/apps/server/src/collaboration/collaboration.util.ts index ed182cf7f..e5c55c77a 100644 --- a/apps/server/src/collaboration/collaboration.util.ts +++ b/apps/server/src/collaboration/collaboration.util.ts @@ -57,6 +57,7 @@ import { JSONContent, } from '@tiptap/core'; import { generateHTML, generateJSON } from '../common/helpers/prosemirror/html'; +import { collapseBlankLines } from '../common/helpers'; // @tiptap/html library works best for generating prosemirror json state but not HTML // see: https://github.com/ueberdosis/tiptap/issues/5352 // see:https://github.com/ueberdosis/tiptap/issues/4089 @@ -146,7 +147,7 @@ export function htmlToJson(html: string) { } export function jsonToText(tiptapJson: JSONContent) { - return generateText(tiptapJson, tiptapExtensions); + return collapseBlankLines(generateText(tiptapJson, tiptapExtensions)); } export function jsonToNode(tiptapJson: JSONContent) { diff --git a/apps/server/src/common/helpers/index.ts b/apps/server/src/common/helpers/index.ts index 80e9a9028..c9fac94c5 100644 --- a/apps/server/src/common/helpers/index.ts +++ b/apps/server/src/common/helpers/index.ts @@ -1,4 +1,5 @@ export * from './utils'; +export * from './text.utils'; export * from './nanoid.utils'; export * from './file.helper'; export * from './constants'; diff --git a/apps/server/src/common/helpers/text.utils.spec.ts b/apps/server/src/common/helpers/text.utils.spec.ts new file mode 100644 index 000000000..6d049a541 --- /dev/null +++ b/apps/server/src/common/helpers/text.utils.spec.ts @@ -0,0 +1,14 @@ +import { collapseBlankLines } from './text.utils'; + +describe('collapseBlankLines', () => { + it.each([ + ['a\n\n\n\nb', 'a\n\nb'], + ['a\n\nb', 'a\n\nb'], + ['a\nb', 'a\nb'], + ['\n\n\n\na\n\n\n', '\n\na\n\n'], + ['no newlines', 'no newlines'], + ['', ''], + ])('collapses %j to %j', (input, expected) => { + expect(collapseBlankLines(input)).toBe(expected); + }); +}); diff --git a/apps/server/src/common/helpers/text.utils.ts b/apps/server/src/common/helpers/text.utils.ts new file mode 100644 index 000000000..8a9cd1a27 --- /dev/null +++ b/apps/server/src/common/helpers/text.utils.ts @@ -0,0 +1,3 @@ +export function collapseBlankLines(text: string): string { + return text.replace(/\n{2,}/g, '\n\n'); +} diff --git a/apps/server/src/ee b/apps/server/src/ee index 5d371309c..75045365f 160000 --- a/apps/server/src/ee +++ b/apps/server/src/ee @@ -1 +1 @@ -Subproject commit 5d371309ca9a23b9e98c93b449b7fb6af0c13a11 +Subproject commit 75045365f132f15af769b6b5f5be738f77ab1e48