(htmlContent: string)
| 20 | * @returns {string[]} array of asset sources |
| 21 | */ |
| 22 | const extractAssetsFromHTMLContent = (htmlContent: string): string[] => { |
| 23 | // create a DOM parser |
| 24 | const parser = new DOMParser(); |
| 25 | // parse the HTML string into a DOM document |
| 26 | const doc = parser.parseFromString(htmlContent, "text/html"); |
| 27 | // collect all unique asset sources |
| 28 | const assetSources = new Set<string>(); |
| 29 | // extract sources from image components |
| 30 | const imageComponents = doc.querySelectorAll("image-component"); |
| 31 | imageComponents.forEach((component) => { |
| 32 | const src = component.getAttribute("src"); |
| 33 | if (src) assetSources.add(src); |
| 34 | }); |
| 35 | const additionalAssetIds = extractAdditionalAssetsFromHTMLContent(htmlContent); |
| 36 | return [...Array.from(assetSources), ...additionalAssetIds]; |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * @description function to replace assets in HTML content with new IDs |
no test coverage detected