fix nested taskList in markdown export (#1443)

This commit is contained in:
Philip Okugbe
2025-08-04 08:01:18 +01:00
committed by GitHub
parent dddfd48934
commit b0c557272d

View File

@ -70,7 +70,16 @@ function taskList(turndownService: TurndownService) {
) 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' : '');
},
});
}