fix: importing list items fixed

This commit is contained in:
2026-02-15 17:56:37 +01:00
parent 0aeeda616e
commit 2a44ea454b
2 changed files with 48 additions and 0 deletions

View File

@@ -85,6 +85,30 @@ export class ImportExecutionEngine extends EventEmitter {
bulletListMarker: '-',
});
// Custom rule for list items: use single space after marker instead of multiple spaces
this.turndown.addRule('listItem', {
filter: 'li',
replacement: (content, node, options) => {
content = content
.replace(/^\n+/, '') // Remove leading newlines
.replace(/\n+$/, '\n') // Replace trailing newlines with single newline
.replace(/\n/gm, '\n '); // Indent subsequent lines with 2 spaces
const parent = node.parentNode as HTMLElement;
const isOrdered = parent?.nodeName === 'OL';
let prefix = options.bulletListMarker + ' ';
if (isOrdered) {
const start = parent.getAttribute('start');
const index = Array.prototype.indexOf.call(parent.children, node);
const startNum = start ? parseInt(start, 10) : 1;
prefix = (startNum + index) + '. ';
}
return prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '');
},
});
// Custom rule for linked images: <a><img></a> -> ![alt](src)
// This handles the common WordPress pattern of wrapping thumbnails in links to full-size images
this.turndown.addRule('linkedImage', {