From 2a44ea454b41a407a125e2de8c79d052bc355053 Mon Sep 17 00:00:00 2001 From: hugo Date: Sun, 15 Feb 2026 17:56:37 +0100 Subject: [PATCH] fix: importing list items fixed --- src/main/engine/ImportAnalysisEngine.ts | 24 ++++++++++++++++++++++++ src/main/engine/ImportExecutionEngine.ts | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/main/engine/ImportAnalysisEngine.ts b/src/main/engine/ImportAnalysisEngine.ts index 6e0aa37..cbdd443 100644 --- a/src/main/engine/ImportAnalysisEngine.ts +++ b/src/main/engine/ImportAnalysisEngine.ts @@ -170,6 +170,30 @@ export class ImportAnalysisEngine { codeBlockStyle: 'fenced', 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: -> ![alt](src) // This handles the common WordPress pattern of wrapping thumbnails in links to full-size images diff --git a/src/main/engine/ImportExecutionEngine.ts b/src/main/engine/ImportExecutionEngine.ts index bfdccc6..32cfdac 100644 --- a/src/main/engine/ImportExecutionEngine.ts +++ b/src/main/engine/ImportExecutionEngine.ts @@ -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: -> ![alt](src) // This handles the common WordPress pattern of wrapping thumbnails in links to full-size images this.turndown.addRule('linkedImage', {