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:
-
]]>
+
+Image with title but empty alt should use title as alt text:
+