(html, pageUrl, localAdvicePaths)
| 30 | }; |
| 31 | |
| 32 | const normalizeHtml = (html, pageUrl, localAdvicePaths) => |
| 33 | html |
| 34 | .replace(/\sstyle="[^"]*"/g, '') |
| 35 | .replace(/\shref="([^"]+)"/g, (_, href) => { |
| 36 | const absoluteHref = new URL(decodeEntities(href), pageUrl).toString(); |
| 37 | const localHref = localAdvicePaths.get(absoluteHref); |
| 38 | |
| 39 | if (localHref) { |
| 40 | return ` href="${localHref}"`; |
| 41 | } |
| 42 | |
| 43 | const isHttp = /^https?:\/\//.test(absoluteHref); |
| 44 | const safeAttrs = isHttp ? ' target="_blank" rel="nofollow noreferrer"' : ''; |
| 45 | |
| 46 | return ` href="${absoluteHref}"${safeAttrs}`; |
| 47 | }) |
| 48 | .replace(/\ssrc="([^"]+)"/g, (_, src) => ` src="${new URL(decodeEntities(src), pageUrl).toString()}"`) |
| 49 | .replace(/\n{3,}/g, '\n\n') |
| 50 | .trim(); |
| 51 | |
| 52 | const fetchText = async (url) => { |
| 53 | const response = await fetch(url); |
no test coverage detected