fixed alt text handling

This commit is contained in:
2026-02-15 18:40:08 +01:00
parent c66f4b2165
commit 3e3504f7d3
2 changed files with 8 additions and 12 deletions

View File

@@ -247,7 +247,7 @@ export class ImportAnalysisEngine {
// - Otherwise, use the original image src // - Otherwise, use the original image src
const imageUrl = hrefIsImage ? href : imgSrc; const imageUrl = hrefIsImage ? href : imgSrc;
// Derive alt text: prefer alt, then title, then filename // Derive alt text: prefer alt, then title, then cleaned filename
let altText = imgAlt.trim(); let altText = imgAlt.trim();
if (!altText) { if (!altText) {
altText = imgTitle.trim(); altText = imgTitle.trim();
@@ -256,13 +256,11 @@ export class ImportAnalysisEngine {
// Extract filename from the image URL as last resort // Extract filename from the image URL as last resort
const urlPath = imageUrl.split('?')[0]; // Remove query string const urlPath = imageUrl.split('?')[0]; // Remove query string
const filename = urlPath.split('/').pop() || ''; const filename = urlPath.split('/').pop() || '';
altText = filename; // Clean the filename: remove extension and replace underscores with spaces
altText = filename.replace(/\.[^.]+$/, '').replace(/_/g, ' ');
} }
// Build the markdown image link // Build the markdown image link (without title attribute)
if (imgTitle) {
return `![${altText}](${imageUrl} "${imgTitle}")`;
}
return `![${altText}](${imageUrl})`; return `![${altText}](${imageUrl})`;
}, },
}); });

View File

@@ -161,7 +161,7 @@ export class ImportExecutionEngine extends EventEmitter {
// - Otherwise, use the original image src // - Otherwise, use the original image src
const imageUrl = hrefIsImage ? href : imgSrc; const imageUrl = hrefIsImage ? href : imgSrc;
// Derive alt text: prefer alt, then title, then filename // Derive alt text: prefer alt, then title, then cleaned filename
let altText = imgAlt.trim(); let altText = imgAlt.trim();
if (!altText) { if (!altText) {
altText = imgTitle.trim(); altText = imgTitle.trim();
@@ -170,13 +170,11 @@ export class ImportExecutionEngine extends EventEmitter {
// Extract filename from the image URL as last resort // Extract filename from the image URL as last resort
const urlPath = imageUrl.split('?')[0]; // Remove query string const urlPath = imageUrl.split('?')[0]; // Remove query string
const filename = urlPath.split('/').pop() || ''; const filename = urlPath.split('/').pop() || '';
altText = filename; // Clean the filename: remove extension and replace underscores with spaces
altText = filename.replace(/\.[^.]+$/, '').replace(/_/g, ' ');
} }
// Build the markdown image link // Build the markdown image link (without title attribute)
if (imgTitle) {
return `![${altText}](${imageUrl} "${imgTitle}")`;
}
return `![${altText}](${imageUrl})`; return `![${altText}](${imageUrl})`;
}, },
}); });