···
function transformImages(content: string): string {
51
-
return content.replace(
52
-
/!\[([^\]]*)\]\(([^)]+)\)\{([^}]+)\}/g,
51
+
// Transform multiple images: ![alt2](url2){attrs}
52
+
content = content.replace(
53
+
/!!(\[([^\]]*)\]\(([^)]+)\))+(?:\{([^}]+)\})?/g,
55
+
// Extract all [alt](url) pairs
56
+
const pairs = [...match.matchAll(/\[([^\]]*)\]\(([^)]+)\)/g)];
57
+
const urls = pairs.map(p => p[2]).join(', ');
58
+
const alts = pairs.map(p => p[1]).join(', ');
60
+
// Extract attrs if present
61
+
const attrsMatch = match.match(/\{([^}]+)\}$/);
62
+
const attrs = attrsMatch ? attrsMatch[1] : '';
64
+
const params: string[] = [`id="${urls}"`];
67
+
params.push(`alt="${alts}"`);
71
+
const classes = attrs.match(/\.([a-zA-Z0-9_-]+)/g)?.map(c => c.slice(1)) || [];
72
+
if (classes.length) {
73
+
params.push(`class="${classes.join(' ')}"`);
76
+
const keyValueMatches = attrs.matchAll(/([a-zA-Z]+)=["']?([^"'\s}]+)["']?/g);
77
+
for (const [, key, value] of keyValueMatches) {
78
+
if (key !== 'class') {
79
+
params.push(`${key}="${value.replace(/["']/g, '')}"`);
84
+
return `{{ imgs(${params.join(', ')}) }}`;
88
+
// Transform single images: {attrs}
89
+
content = content.replace(
90
+
/!\[([^\]]*)\]\(([^)]+)\)(?:\{([^}]+)\})?/g,
(match, alt, url, attrs) => {
const params: string[] = [`id="${url}"`];
···
params.push(`alt="${alt}"`);
60
-
const classes = attrs.match(/\.([a-zA-Z0-9_-]+)/g)?.map(c => c.slice(1)) || [];
61
-
if (classes.length) {
62
-
params.push(`class="${classes.join(' ')}"`);
65
-
const keyValueMatches = attrs.matchAll(/([a-zA-Z]+)=["']?([^"'\s}]+)["']?/g);
66
-
for (const [, key, value] of keyValueMatches) {
67
-
if (key !== 'class') {
68
-
params.push(`${key}="${value.replace(/["']/g, '')}"`);
99
+
const classes = attrs.match(/\.([a-zA-Z0-9_-]+)/g)?.map(c => c.slice(1)) || [];
100
+
if (classes.length) {
101
+
params.push(`class="${classes.join(' ')}"`);
104
+
const keyValueMatches = attrs.matchAll(/([a-zA-Z]+)=["']?([^"'\s}]+)["']?/g);
105
+
for (const [, key, value] of keyValueMatches) {
106
+
if (key !== 'class') {
107
+
params.push(`${key}="${value.replace(/["']/g, '')}"`);
return `{{ img(${params.join(', ')}) }}`;
function processFile(filePath: string): void {