mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -04:00
rewriters/html: only rewrite urls on real elements (needs to be merged with elements.ts later)
This commit is contained in:
parent
98f67d737c
commit
f4a4a0e7e4
1 changed files with 17 additions and 2 deletions
|
@ -38,7 +38,22 @@ function traverseParsedHtml(node, origin?: URL) {
|
||||||
|
|
||||||
/* url attributes */
|
/* url attributes */
|
||||||
for (const urlAttr of ["src", "href", "action", "formaction"]) {
|
for (const urlAttr of ["src", "href", "action", "formaction"]) {
|
||||||
if (hasAttrib(node, urlAttr) && !isScramjetFile(node.attribs[urlAttr])) {
|
if (
|
||||||
|
hasAttrib(node, urlAttr) &&
|
||||||
|
!isScramjetFile(node.attribs[urlAttr]) &&
|
||||||
|
[
|
||||||
|
"iframe",
|
||||||
|
"embed",
|
||||||
|
"script",
|
||||||
|
"a",
|
||||||
|
"img",
|
||||||
|
"link",
|
||||||
|
"object",
|
||||||
|
"form",
|
||||||
|
"media",
|
||||||
|
"source",
|
||||||
|
].includes(node.name)
|
||||||
|
) {
|
||||||
const value = node.attribs[urlAttr];
|
const value = node.attribs[urlAttr];
|
||||||
node.attribs[`data-${urlAttr}`] = value;
|
node.attribs[`data-${urlAttr}`] = value;
|
||||||
node.attribs[urlAttr] = encodeUrl(value, origin);
|
node.attribs[urlAttr] = encodeUrl(value, origin);
|
||||||
|
@ -76,7 +91,7 @@ function traverseParsedHtml(node, origin?: URL) {
|
||||||
node.children[0].data = rewriteCss(node.children[0].data, origin);
|
node.children[0].data = rewriteCss(node.children[0].data, origin);
|
||||||
if (
|
if (
|
||||||
node.name === "script" &&
|
node.name === "script" &&
|
||||||
/(application|text)\/javascript|importmap|undefined/.test(
|
/(application|text)\/javascript|module|importmap|undefined/.test(
|
||||||
node.attribs.type
|
node.attribs.type
|
||||||
) &&
|
) &&
|
||||||
node.children[0] !== undefined
|
node.children[0] !== undefined
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue