@@ -47,13 +47,15 @@ function fileExists(relativePath: string, markdownFilePath: string): boolean {
4747 */
4848function convertImgToPicture (
4949 src : string ,
50- alt : string ,
50+ alt : string | null ,
5151 markdownPath : string ,
5252 additionalAttrs : string = "" ,
5353) : string {
54+ const safeAlt = alt || "" ;
55+
5456 // 외부 URL이거나 svg, gif는 picture 태그로 변환하지 않음
5557 if ( src . startsWith ( "http" ) || src . endsWith ( ".svg" ) || src . endsWith ( ".gif" ) ) {
56- return `<img src="${ src } " alt="${ alt } "${ additionalAttrs ? " " + additionalAttrs : "" } loading="lazy" />` ;
58+ return `<img src="${ src } " alt="${ safeAlt } "${ additionalAttrs ? " " + additionalAttrs : "" } loading="lazy" />` ;
5759 }
5860
5961 // 이미지 포맷별 경로 생성
@@ -79,13 +81,13 @@ function convertImgToPicture(
7981
8082 // 변환된 이미지가 없으면 원본만 사용
8183 if ( sources . length === 0 ) {
82- return `<img src="${ src } " alt="${ alt } "${ additionalAttrs ? " " + additionalAttrs : "" } loading="lazy" />` ;
84+ return `<img src="${ src } " alt="${ safeAlt } "${ additionalAttrs ? " " + additionalAttrs : "" } loading="lazy" />` ;
8385 }
8486
8587 // picture 태그 생성 (원본을 최종 fallback으로 사용)
8688 return `<picture>
8789 ${ sources . join ( "\n " ) }
88- <img src="${ src } " alt="${ alt } "${ additionalAttrs ? " " + additionalAttrs : "" } loading="lazy" />
90+ <img src="${ src } " alt="${ safeAlt } "${ additionalAttrs ? " " + additionalAttrs : "" } loading="lazy" />
8991</picture>` ;
9092}
9193
@@ -114,7 +116,7 @@ function processHtmlImages(html: string, markdownPath: string): string {
114116 . replace ( / l o a d i n g = [ " ' ] [ ^ " ' ] * [ " ' ] / gi, "" ) // loading은 우리가 추가할 것이므로 제거
115117 . trim ( ) ;
116118
117- return convertImgToPicture ( src , alt , markdownPath , remainingAttrs ) ;
119+ return convertImgToPicture ( src , alt || "" , markdownPath , remainingAttrs || "" ) ;
118120 } ) ;
119121}
120122
0 commit comments