( url, html )
| 323 | } |
| 324 | |
| 325 | async function parseHTML( url, html ) { |
| 326 | |
| 327 | html = fixSourceLinks( url, html ); |
| 328 | |
| 329 | html = html.replace( /<div class="description">[^]*?<\/div>/, '' ); |
| 330 | |
| 331 | const styleRE = /<style>([^]*?)<\/style>/i; |
| 332 | const titleRE = /<title>([^]*?)<\/title>/i; |
| 333 | const bodyRE = /<body>([^]*?)<\/body>/i; |
| 334 | const inlineScriptRE = /<script>([^]*?)<\/script>/i; |
| 335 | const inlineModuleScriptRE = /<script type="module">([^]*?)<\/script>/i; |
| 336 | const externalScriptRE = /(<!--(?:(?!-->)[\s\S])*?-->\n){0,1}<script\s+([^>]*?)(type="module"\s+)?src\s*=\s*"(.*?)"(.*?)>\s*<\/script>/ig; |
| 337 | const dataScriptRE = /(<!--(?:(?!-->)[\s\S])*?-->\n){0,1}<script([^>]*?type="(?!module).*?".*?)>([^]*?)<\/script>/ig; |
| 338 | const cssLinkRE = /<link ([^>]+?)>/g; |
| 339 | const isCSSLinkRE = /type="text\/css"|rel="stylesheet"/; |
| 340 | const hrefRE = /href="([^"]+)"/; |
| 341 | |
| 342 | const obj = { html: html }; |
| 343 | addSource( 'css', 'css', formatCSS( fixCSSLinks( url, getHTMLPart( styleRE, obj, '<style>\n${css}</style>' ) ) ) ); |
| 344 | addSource( 'html', 'html', getHTMLPart( bodyRE, obj, '<body>${html}</body>' ) ); |
| 345 | const rootScript = getHTMLPart( inlineScriptRE, obj, '<script>${js}</script>' ) || |
| 346 | getHTMLPart( inlineModuleScriptRE, obj, '<script type="module">${js}</script>' ); |
| 347 | html = obj.html; |
| 348 | |
| 349 | const fqURL = getFQUrl( url ); |
| 350 | /** @type Object<string, SourceInfo> */ |
| 351 | const scriptInfos = {}; |
| 352 | g.rootScriptInfo = { |
| 353 | fqURL, |
| 354 | deps: [], |
| 355 | source: rootScript, |
| 356 | }; |
| 357 | scriptInfos[ fqURL ] = g.rootScriptInfo; |
| 358 | |
| 359 | const { text } = await getWorkerScripts( rootScript, fqURL, scriptInfos ); |
| 360 | g.rootScriptInfo.source = text; |
| 361 | g.scriptInfos = scriptInfos; |
| 362 | for ( const [ fqURL, scriptInfo ] of Object.entries( scriptInfos ) ) { |
| 363 | |
| 364 | addSource( 'js', basename( fqURL ), scriptInfo.source, scriptInfo ); |
| 365 | |
| 366 | } |
| 367 | |
| 368 | const tm = titleRE.exec( html ); |
| 369 | if ( tm ) { |
| 370 | |
| 371 | g.title = tm[ 1 ]; |
| 372 | |
| 373 | } |
| 374 | |
| 375 | const kScript = 'script'; |
| 376 | const scripts = []; |
| 377 | html = html.replace( externalScriptRE, function ( p0, p1, p2, type, p3, p4 ) { |
| 378 | |
| 379 | p1 = p1 || ''; |
| 380 | scripts.push( `${p1}<${kScript} ${p2}${safeStr( type )}src="${p3}"${p4}></${kScript}>` ); |
| 381 | return ''; |
| 382 |
no test coverage detected