fix href value
This commit is contained in:
@@ -149,6 +149,13 @@ function isSVGElement(el: Element): boolean {
|
|||||||
return el.tagName === 'svg' || el instanceof SVGElement;
|
return el.tagName === 'svg' || el instanceof SVGElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHref() {
|
||||||
|
// return a href without hash
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = '';
|
||||||
|
return a.href;
|
||||||
|
}
|
||||||
|
|
||||||
export function transformAttribute(
|
export function transformAttribute(
|
||||||
doc: Document,
|
doc: Document,
|
||||||
name: string,
|
name: string,
|
||||||
@@ -160,7 +167,7 @@ export function transformAttribute(
|
|||||||
} else if (name === 'srcset' && value) {
|
} else if (name === 'srcset' && value) {
|
||||||
return getAbsoluteSrcsetString(doc, value);
|
return getAbsoluteSrcsetString(doc, value);
|
||||||
} else if (name === 'style' && value) {
|
} else if (name === 'style' && value) {
|
||||||
return absoluteToStylesheet(value, location.href);
|
return absoluteToStylesheet(value, getHref());
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -262,7 +269,7 @@ function serializeNode(
|
|||||||
(n as HTMLStyleElement).sheet as CSSStyleSheet,
|
(n as HTMLStyleElement).sheet as CSSStyleSheet,
|
||||||
);
|
);
|
||||||
if (cssText) {
|
if (cssText) {
|
||||||
attributes._cssText = absoluteToStylesheet(cssText, location.href);
|
attributes._cssText = absoluteToStylesheet(cssText, getHref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// form fields
|
// form fields
|
||||||
@@ -335,7 +342,7 @@ function serializeNode(
|
|||||||
let textContent = (n as Text).textContent;
|
let textContent = (n as Text).textContent;
|
||||||
const isStyle = parentTagName === 'STYLE' ? true : undefined;
|
const isStyle = parentTagName === 'STYLE' ? true : undefined;
|
||||||
if (isStyle && textContent) {
|
if (isStyle && textContent) {
|
||||||
textContent = absoluteToStylesheet(textContent, location.href);
|
textContent = absoluteToStylesheet(textContent, getHref());
|
||||||
}
|
}
|
||||||
if (parentTagName === 'SCRIPT') {
|
if (parentTagName === 'SCRIPT') {
|
||||||
textContent = 'SCRIPT_PLACEHOLDER';
|
textContent = 'SCRIPT_PLACEHOLDER';
|
||||||
|
|||||||
Reference in New Issue
Block a user