@@ -220,7 +220,7 @@ function get_attr_value(node, attr) {
220
220
* height: string | number
221
221
* }} details
222
222
*/
223
- function img_attributes_to_markdown ( content , attributes , details ) {
223
+ function serialize_img_attributes ( content , attributes , details ) {
224
224
const attribute_strings = attributes . map ( ( attribute ) => {
225
225
if ( attribute . name === 'src' ) {
226
226
return `src=${ details . src } ` ;
@@ -279,22 +279,18 @@ function img_to_picture(content, node, image) {
279
279
}
280
280
281
281
let res = '<picture>' ;
282
+
282
283
for ( const [ format , srcset ] of Object . entries ( image . sources ) ) {
283
284
res += `<source srcset={"${ srcset } "}${ sizes_string } type="image/${ format } " />` ;
284
285
}
285
- // Need to handle src differently when using either Vite's renderBuiltUrl or relative base path in Vite.
286
- // See https://github.com/vitejs/vite/blob/b93dfe3e08f56cafe2e549efd80285a12a3dc2f0/packages/vite/src/node/plugins/asset.ts#L132
287
- const src =
288
- image . img . src . startsWith ( '"+' ) && image . img . src . endsWith ( '+"' )
289
- ? `{"${ image . img . src . substring ( 2 , image . img . src . length - 2 ) } "}`
290
- : `"${ image . img . src } "` ;
291
- res += `<img ${ img_attributes_to_markdown ( content , attributes , {
292
- src,
286
+
287
+ res += `<img ${ serialize_img_attributes ( content , attributes , {
288
+ src : image . img . src . startsWith ( '__VITE_ASSET__' ) ? `{"${ image . img . src } "}` : `"${ image . img . src } "` ,
293
289
width : image . img . w ,
294
290
height : image . img . h
295
291
} ) } />`;
296
- res += '</picture>' ;
297
- return res ;
292
+
293
+ return ( res += '</picture>' ) ;
298
294
}
299
295
300
296
/**
@@ -320,13 +316,13 @@ function dynamic_img_to_picture(content, node, src_var_name) {
320
316
} ;
321
317
322
318
return `{#if typeof ${ src_var_name } === 'string'}
323
- <img ${ img_attributes_to_markdown ( content , node . attributes , details ) } />
319
+ <img ${ serialize_img_attributes ( content , node . attributes , details ) } />
324
320
{:else}
325
321
<picture>
326
322
{#each Object.entries(${ src_var_name } .sources) as [format, srcset]}
327
323
<source {srcset}${ sizes_string } type={'image/' + format} />
328
324
{/each}
329
- <img ${ img_attributes_to_markdown ( content , attributes , details ) } />
325
+ <img ${ serialize_img_attributes ( content , attributes , details ) } />
330
326
</picture>
331
327
{/if}` ;
332
328
}
0 commit comments