Skip to content

The open alternative to Salesforce, designed for AI.

fix(rich-text): keep nested task item content out of markdown code blocks (#28821)

UDIT_SINGH@070f1858843655
diff --git a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-rich-text.util.spec.ts b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-rich-text.util.spec.ts
index 3ab72a0e5d9..cd7e5de7c0d 100644
--- a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-rich-text.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-rich-text.util.spec.ts
@@ -21,6 +21,90 @@ const BLOCKNOTE_VALUE = JSON.stringify([
},
]);
+const NESTED_TASKS_VALUE = JSON.stringify({
+ type: 'doc',
+ attrs: { schemaVersion: 1 },
+ content: [
+ {
+ type: 'taskList',
+ content: [
+ {
+ type: 'taskItem',
+ attrs: { checked: true },
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Done top' }],
+ },
+ {
+ type: 'taskList',
+ content: [
+ {
+ type: 'taskItem',
+ attrs: { checked: false },
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Open child' }],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ {
+ type: 'taskItem',
+ attrs: { checked: false },
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Plan launch' }],
+ },
+ {
+ type: 'bulletList',
+ content: [
+ {
+ type: 'listItem',
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Draft email' }],
+ },
+ ],
+ },
+ {
+ type: 'listItem',
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Book room' }],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ {
+ type: 'taskItem',
+ attrs: { checked: false },
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Call Ada' }],
+ },
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Ask about the renewal' }],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+});
+
const nodeTypesOf = (tiptap: string | null | undefined) =>
JSON.parse(tiptap ?? '{}').content.map((node: { type: string }) => node.type);
@@ -68,6 +152,16 @@ describe('transformRichTextValue', () => {
expect(nodeTypesOf(result.tiptap)).toEqual(['heading', 'bulletList']);
});
+ it('should rebuild the same TipTap from the derived markdown of nested task items', () => {
+ const { markdown } = transformRichTextValue({ tiptap: NESTED_TASKS_VALUE });
+
+ const result = transformRichTextValue({ markdown });
+
+ expect(JSON.parse(result.tiptap ?? '{}')).toEqual(
+ JSON.parse(NESTED_TASKS_VALUE),
+ );
+ });
+
it('should convert BlockNote sent by older clients to TipTap and keep it as sent', () => {
const result = transformRichTextValue({
blocknote: BLOCKNOTE_VALUE,
diff --git a/packages/twenty-shared/src/utils/tiptap/__tests__/tiptap-document.test.ts b/packages/twenty-shared/src/utils/tiptap/__tests__/tiptap-document.test.ts
index a6327b41f66..ab5ad0d4747 100644
--- a/packages/twenty-shared/src/utils/tiptap/__tests__/tiptap-document.test.ts
+++ b/packages/twenty-shared/src/utils/tiptap/__tests__/tiptap-document.test.ts
@@ -205,6 +205,106 @@ describe('TipTap document primitives', () => {
).toBe(['- Parent', '', ' 3. Child'].join('\n'));
});
+ it('indents nested task item content to the task content column', () => {
+ expect(
+ tipTapDocumentToMarkdown({
+ type: 'doc',
+ content: [
+ {
+ type: 'taskList',
+ content: [
+ {
+ type: 'taskItem',
+ attrs: { checked: true },
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Done top' }],
+ },
+ {
+ type: 'taskList',
+ content: [
+ {
+ type: 'taskItem',
+ attrs: { checked: false },
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Open child' }],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ {
+ type: 'taskItem',
+ attrs: { checked: false },
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Plan launch' }],
+ },
+ {
+ type: 'bulletList',
+ content: [
+ {
+ type: 'listItem',
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Draft email' }],
+ },
+ ],
+ },
+ {
+ type: 'listItem',
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Book room' }],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ {
+ type: 'taskItem',
+ attrs: { checked: false },
+ content: [
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Call Ada' }],
+ },
+ {
+ type: 'paragraph',
+ content: [{ type: 'text', text: 'Ask about the renewal' }],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ }),
+ ).toBe(
+ [
+ '- [x] Done top',
+ '',
+ ' - [ ] Open child',
+ '- [ ] Plan launch',
+ '',
+ ' - Draft email',
+ ' - Book room',
+ '- [ ] Call Ada',
+ '',
+ ' Ask about the renewal',
+ ].join('\n'),
+ );
+ });
+
it('escapes literal Markdown text and link destinations', () => {
expect(
tipTapDocumentToMarkdown({
diff --git a/packages/twenty-shared/src/utils/tiptap/tiptap-document-to-markdown.ts b/packages/twenty-shared/src/utils/tiptap/tiptap-document-to-markdown.ts
index 2429ae6f4ed..651c36a6e74 100644
--- a/packages/twenty-shared/src/utils/tiptap/tiptap-document-to-markdown.ts
+++ b/packages/twenty-shared/src/utils/tiptap/tiptap-document-to-markdown.ts
@@ -138,7 +138,11 @@ const renderSkillTag = (node: TipTapNode): string => {
return typeof label === 'string' ? label : '';
};
-const renderListItem = (item: TipTapNode, marker: string): string => {
+const renderListItem = (
+ item: TipTapNode,
+ marker: string,
+ checkbox = '',
+): string => {
const [firstLine = '', ...continuationLines] = renderChildren(item)
.trim()
.split('\n');
@@ -147,7 +151,7 @@ const renderListItem = (item: TipTapNode, marker: string): string => {
.map((line) => (line === '' ? '' : `${indentation}${line}`))
.join('\n');
- return `${marker}${firstLine}${
+ return `${marker}${checkbox}${firstLine}${
indentedContinuation === '' ? '' : `\n${indentedContinuation}`
}\n`;
};
@@ -198,7 +202,8 @@ const renderTipTapNodeToMarkdown = (node: TipTapNode): string => {
.map((item) =>
renderListItem(
item,
- item.attrs?.checked === true ? '- [x] ' : '- [ ] ',
+ '- ',
+ item.attrs?.checked === true ? '[x] ' : '[ ] ',
),
)
.join('')}\n`;