From b0c557272da226de8ee9e05f930f35c5c0b717ae Mon Sep 17 00:00:00 2001 From: Philip Okugbe <16838612+Philipinho@users.noreply.github.com> Date: Mon, 4 Aug 2025 08:01:18 +0100 Subject: [PATCH] fix nested taskList in markdown export (#1443) --- .../src/integrations/export/turndown-utils.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/server/src/integrations/export/turndown-utils.ts b/apps/server/src/integrations/export/turndown-utils.ts index 54fdef12..b20e6733 100644 --- a/apps/server/src/integrations/export/turndown-utils.ts +++ b/apps/server/src/integrations/export/turndown-utils.ts @@ -69,8 +69,17 @@ function taskList(turndownService: TurndownService) { 'input[type="checkbox"]', ) as HTMLInputElement; const isChecked = checkbox.checked; - - return `- ${isChecked ? '[x]' : '[ ]'} ${content.trim()} \n`; + + // Process content like regular list items + content = content + .replace(/^\n+/, '') // remove leading newlines + .replace(/\n+$/, '\n') // replace trailing newlines with just a single one + .replace(/\n/gm, '\n '); // indent nested content with 2 spaces + + // Create the checkbox prefix + const prefix = `- ${isChecked ? '[x]' : '[ ]'} `; + + return prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : ''); }, }); }