From b730f12ba06f9c2a00a3840afa6c5f99fac6eb91 Mon Sep 17 00:00:00 2001 From: hugo Date: Sun, 15 Feb 2026 09:31:42 +0100 Subject: [PATCH] fix: use alt -> title -> filename --- src/main/engine/ImportAnalysisEngine.ts | 7 +++++-- src/main/engine/ImportExecutionEngine.ts | 7 +++++-- tests/assets/import-test-cases.wxr | 4 +++- tests/engine/ImportExecutionEngine.e2e.test.ts | 3 +++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/engine/ImportAnalysisEngine.ts b/src/main/engine/ImportAnalysisEngine.ts index 5a13fb6..6e0aa37 100644 --- a/src/main/engine/ImportAnalysisEngine.ts +++ b/src/main/engine/ImportAnalysisEngine.ts @@ -201,10 +201,13 @@ export class ImportAnalysisEngine { // - Otherwise, use the original image src const imageUrl = hrefIsImage ? href : imgSrc; - // Derive alt text: use image alt if not empty, otherwise extract filename from the URL + // Derive alt text: prefer alt, then title, then filename let altText = imgAlt.trim(); if (!altText) { - // Extract filename from the image URL + altText = imgTitle.trim(); + } + if (!altText) { + // Extract filename from the image URL as last resort const urlPath = imageUrl.split('?')[0]; // Remove query string const filename = urlPath.split('/').pop() || ''; altText = filename; diff --git a/src/main/engine/ImportExecutionEngine.ts b/src/main/engine/ImportExecutionEngine.ts index 5e68a4d..1e65b04 100644 --- a/src/main/engine/ImportExecutionEngine.ts +++ b/src/main/engine/ImportExecutionEngine.ts @@ -111,10 +111,13 @@ export class ImportExecutionEngine extends EventEmitter { // - Otherwise, use the original image src const imageUrl = hrefIsImage ? href : imgSrc; - // Derive alt text: use image alt if not empty, otherwise extract filename from the URL + // Derive alt text: prefer alt, then title, then filename let altText = imgAlt.trim(); if (!altText) { - // Extract filename from the image URL + altText = imgTitle.trim(); + } + if (!altText) { + // Extract filename from the image URL as last resort const urlPath = imageUrl.split('?')[0]; // Remove query string const filename = urlPath.split('/').pop() || ''; altText = filename; diff --git a/tests/assets/import-test-cases.wxr b/tests/assets/import-test-cases.wxr index dbcb5d3..b1bee64 100644 --- a/tests/assets/import-test-cases.wxr +++ b/tests/assets/import-test-cases.wxr @@ -312,7 +312,9 @@ with multiple lines]]>

Linked image where link and image src are the same:

For comparison, an image with proper alt inside a link should preserve the alt:

-Company Logo]]> +Company Logo +

Image with title but empty alt should use title as alt text:

+]]> 107 2024-01-07 10:00:00 diff --git a/tests/engine/ImportExecutionEngine.e2e.test.ts b/tests/engine/ImportExecutionEngine.e2e.test.ts index b554126..43901f2 100644 --- a/tests/engine/ImportExecutionEngine.e2e.test.ts +++ b/tests/engine/ImportExecutionEngine.e2e.test.ts @@ -432,6 +432,9 @@ describe('ImportExecutionEngine E2E Tests', () => { // Image with proper alt inside link should preserve the alt text expect(content).toContain('![Company Logo](http://example.com/logo.png)'); + // Image with title but empty alt should use title as alt text (title takes precedence over filename) + expect(content).toContain('![Delicious Piroggen](http://example.com/wp-content/uploads/2020/03/dish.jpg'); + // Should NOT have empty image alt text (the broken pattern we're fixing) expect(content).not.toMatch(/!\[\]\([^)]+\)/); });