@@ -268,7 +268,8 @@ fn _transform_html_inner(opts: TranformHTMLOptions) -> Result<String, ()> {
268
268
}
269
269
}
270
270
271
- for img in document. select ( "img[srcset]" ) ? {
271
+ let srcset_images: Vec < _ > = document. select ( "img[srcset]" ) ?. collect ( ) ;
272
+ for img in srcset_images {
272
273
let mut sizes: Vec < ImageSource > = img. attributes . borrow ( ) . get ( "srcset" ) . ok_or ( ( ) ) ?. split ( "," ) . filter_map ( |x| {
273
274
let tok: Vec < & str > = x. trim ( ) . split ( " " ) . collect ( ) ;
274
275
let tok_1 = if tok. len ( ) > 1 && !tok[ 1 ] . is_empty ( ) {
@@ -306,14 +307,16 @@ fn _transform_html_inner(opts: TranformHTMLOptions) -> Result<String, ()> {
306
307
307
308
let url = Url :: parse ( & opts. url ) . map_err ( |_| ( ) ) ?;
308
309
309
- for img in document. select ( "img[src]" ) ? {
310
+ let src_images: Vec < _ > = document. select ( "img[src]" ) ?. collect ( ) ;
311
+ for img in src_images {
310
312
let old = img. attributes . borrow ( ) . get ( "src" ) . map ( |x| x. to_string ( ) ) . ok_or ( ( ) ) ?;
311
313
if let Ok ( new) = url. join ( & old) {
312
314
img. attributes . borrow_mut ( ) . insert ( "src" , new. to_string ( ) ) ;
313
315
}
314
316
}
315
317
316
- for anchor in document. select ( "a[href]" ) ? {
318
+ let href_anchors: Vec < _ > = document. select ( "a[href]" ) ?. collect ( ) ;
319
+ for anchor in href_anchors {
317
320
let old = anchor. attributes . borrow ( ) . get ( "href" ) . map ( |x| x. to_string ( ) ) . ok_or ( ( ) ) ?;
318
321
if let Ok ( new) = url. join ( & old) {
319
322
anchor. attributes . borrow_mut ( ) . insert ( "href" , new. to_string ( ) ) ;
0 commit comments