@@ -9,6 +9,7 @@ import { addWarning } from "../common/commonConversionWarnings";
99import { PluginSettings , HTMLPreview , AltNode , HTMLSettings } from "types" ;
1010import { renderAndAttachSVG } from "../altNodes/altNodeUtils" ;
1111import { getVisibleNodes } from "../common/nodeVisibility" ;
12+ import { getPlaceholderImage } from "../common/images" ;
1213
1314const selfClosingTags = [ "img" ] ;
1415
@@ -211,7 +212,10 @@ const htmlFrame = async (
211212 }
212213} ;
213214
214- const htmlAsset = ( node : SceneNode , settings : HTMLSettings ) : string => {
215+ const htmlAsset = async (
216+ node : SceneNode ,
217+ settings : HTMLSettings ,
218+ ) : Promise < string > => {
215219 if ( ! ( "opacity" in node ) || ! ( "layoutAlign" in node ) || ! ( "fills" in node ) ) {
216220 return "" ;
217221 }
@@ -220,21 +224,13 @@ const htmlAsset = (node: SceneNode, settings: HTMLSettings): string => {
220224 . commonPositionStyles ( )
221225 . commonShapeStyles ( ) ;
222226
223- let tag = "div" ;
224- let src = "" ;
225227 if ( retrieveTopFill ( node . fills ) ?. type === "IMAGE" ) {
226228 addWarning ( "Image fills are replaced with placeholders" ) ;
227- tag = "img" ;
228- src = ` src="https://placehold.co/$${ node . width . toFixed (
229- 0 ,
230- ) } x${ node . height . toFixed ( 0 ) } "`;
229+ const imgUrl = getPlaceholderImage ( node . width , node . height ) ;
230+ return `\n<img${ builder . build ( ) } src="${ imgUrl } " />` ;
231231 }
232232
233- if ( tag === "div" ) {
234- return `\n<div${ builder . build ( ) } ${ src } ></div>` ;
235- }
236-
237- return `\n<${ tag } ${ builder . build ( ) } ${ src } />` ;
233+ return `\n<div${ builder . build ( ) } ></div>` ;
238234} ;
239235
240236// properties named propSomething always take care of ","
@@ -266,20 +262,13 @@ const htmlContainer = (
266262 let src = "" ;
267263 if ( retrieveTopFill ( node . fills ) ?. type === "IMAGE" ) {
268264 addWarning ( "Image fills are replaced with placeholders" ) ;
265+ const imageURL = getPlaceholderImage ( node . width , node . height ) ;
269266 if ( ! ( "children" in node ) || node . children . length === 0 ) {
270267 tag = "img" ;
271- src = ` src="https://placehold.co/${ node . width . toFixed (
272- 0 ,
273- ) } x${ node . height . toFixed ( 0 ) } "`;
268+ src = ` src="${ imageURL } "` ;
274269 } else {
275270 builder . addStyles (
276- formatWithJSX (
277- "background-image" ,
278- settings . jsx ,
279- `url(https://placehold.co/${ node . width . toFixed (
280- 0 ,
281- ) } x${ node . height . toFixed ( 0 ) } )`,
282- ) ,
271+ formatWithJSX ( "background-image" , settings . jsx , `url(${ imageURL } )` ) ,
283272 ) ;
284273 }
285274 }
0 commit comments