Every line of 'how to add multiple images in html' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
89 function addContentImages(data, images) { 90 let regex = (/]*src="(.+?\.(?:gif|jpg|png))"[^>]*>/gi); 91 let match; 92 93 getItemsOfType(data, 'post').forEach(post => { 94 let postId = post.post_id[0]; 95 let postContent = post.encoded[0]; 96 let postLink = post.link[0]; 97 98 // reset lastIndex since we're reusing the same regex object 99 regex.lastIndex = 0; 100 while ((match = regex.exec(postContent)) !== null) { 101 // base the matched image URL relative to the post URL 102 let url = new URL(match[1], postLink).href; 103 104 // add image if it hasn't already been added for this post 105 let exists = images.some(image => image.postId === postId && image.url === url); 106 if (!exists) { 107 images.push({ 108 id: -1, 109 postId: postId, 110 url: url 111 }); 112 console.log('Scraped ' + url + '.'); 113 } 114 } 115 }); 116 }
73 function getImgHtml(imgs) { 74 var html = ''; 75 (imgs || '').split(',').forEach(function (item, index) { 76 if (item == '') 77 return; 78 var br = ''; 79 if (index != 0) 80 br = '<br />'; 81 html += '{0}<a></a>'.format(br, item); 82 }); 83 84 return html; 85 }