Skip to content

Commit 1daa1b2

Browse files
committed
fix: img optimizer plugin 에 nullable 한 attr 속성 안전하게 처리
1 parent 3fcde69 commit 1daa1b2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

.vitepress/plugins/markdown-picture.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ function convertImgToPicture(
5252
additionalAttrs: string = "",
5353
): string {
5454
const safeAlt = alt || "";
55+
const safeAttrs = additionalAttrs && additionalAttrs.trim() ? " " + additionalAttrs.trim() : "";
5556

5657
// 외부 URL이거나 svg, gif는 picture 태그로 변환하지 않음
5758
if (src.startsWith("http") || src.endsWith(".svg") || src.endsWith(".gif")) {
58-
return `<img src="${src}" alt="${safeAlt}"${additionalAttrs ? " " + additionalAttrs : ""} loading="lazy" />`;
59+
return `<img src="${src}" alt="${safeAlt}"${safeAttrs} loading="lazy" />`;
5960
}
6061

6162
// 이미지 포맷별 경로 생성
@@ -81,13 +82,13 @@ function convertImgToPicture(
8182

8283
// 변환된 이미지가 없으면 원본만 사용
8384
if (sources.length === 0) {
84-
return `<img src="${src}" alt="${safeAlt}"${additionalAttrs ? " " + additionalAttrs : ""} loading="lazy" />`;
85+
return `<img src="${src}" alt="${safeAlt}"${safeAttrs} loading="lazy" />`;
8586
}
8687

8788
// picture 태그 생성 (원본을 최종 fallback으로 사용)
8889
return `<picture>
8990
${sources.join("\n ")}
90-
<img src="${src}" alt="${safeAlt}"${additionalAttrs ? " " + additionalAttrs : ""} loading="lazy" />
91+
<img src="${src}" alt="${safeAlt}"${safeAttrs} loading="lazy" />
9192
</picture>`;
9293
}
9394

0 commit comments

Comments
 (0)