···
function transformImages(content: string): string {
+
// Transform multiple images: ![alt2](url2){attrs}
+
content = content.replace(
+
/!!(\[([^\]]*)\]\(([^)]+)\))+(?:\{([^}]+)\})?/g,
+
// Extract all [alt](url) pairs
+
const pairs = [...match.matchAll(/\[([^\]]*)\]\(([^)]+)\)/g)];
+
const urls = pairs.map(p => p[2]).join(', ');
+
const alts = pairs.map(p => p[1]).join(', ');
+
// Extract attrs if present
+
const attrsMatch = match.match(/\{([^}]+)\}$/);
+
const attrs = attrsMatch ? attrsMatch[1] : '';
+
const params: string[] = [`id="${urls}"`];
+
params.push(`alt="${alts}"`);
+
const classes = attrs.match(/\.([a-zA-Z0-9_-]+)/g)?.map(c => c.slice(1)) || [];
+
params.push(`class="${classes.join(' ')}"`);
+
const keyValueMatches = attrs.matchAll(/([a-zA-Z]+)=["']?([^"'\s}]+)["']?/g);
+
for (const [, key, value] of keyValueMatches) {
+
params.push(`${key}="${value.replace(/["']/g, '')}"`);
+
return `{{ imgs(${params.join(', ')}) }}`;
+
// Transform single images: {attrs}
+
content = content.replace(
+
/!\[([^\]]*)\]\(([^)]+)\)(?:\{([^}]+)\})?/g,
(match, alt, url, attrs) => {
const params: string[] = [`id="${url}"`];
···
params.push(`alt="${alt}"`);
+
const classes = attrs.match(/\.([a-zA-Z0-9_-]+)/g)?.map(c => c.slice(1)) || [];
+
params.push(`class="${classes.join(' ')}"`);
+
const keyValueMatches = attrs.matchAll(/([a-zA-Z]+)=["']?([^"'\s}]+)["']?/g);
+
for (const [, key, value] of keyValueMatches) {
+
params.push(`${key}="${value.replace(/["']/g, '')}"`);
return `{{ img(${params.join(', ')}) }}`;
function processFile(filePath: string): void {