Skip to content
Snippets Groups Projects
Verified Commit 690c13d4 authored by Bartłomiej Górnicki's avatar Bartłomiej Górnicki
Browse files

fix: child node replacement

Closes #21
parent dbaf2269
No related branches found
No related tags found
1 merge request!16fix: child node replacement
Pipeline #98314 failed
This diff is collapsed.
......@@ -28,40 +28,40 @@
"hooks:install": "husky"
},
"dependencies": {
"@xmldom/xmldom": "0.8.1",
"@xmldom/xmldom": "0.8.10",
"ow": "0.28.2",
"remarkable": "2.0.1",
"sanitize-html": "2.12.1",
"sanitize-html": "2.13.0",
"typescript-chained-error": "1.6.0",
"universe-log": "5.2.0"
},
"devDependencies": {
"@commitlint/cli": "18.6.1",
"@commitlint/config-conventional": "18.6.2",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@engrave/eslint-config-engrave": "1.0.0",
"@semantic-release/gitlab": "13.0.3",
"@types/chai": "4.3.11",
"@types/jsdom": "21.1.6",
"@types/lodash": "4.14.202",
"@types/mocha": "10.0.6",
"@types/node": "20.11.20",
"@semantic-release/gitlab": "13.2.0",
"@types/chai": "4.3.16",
"@types/jsdom": "21.1.7",
"@types/lodash": "4.17.6",
"@types/mocha": "10.0.7",
"@types/node": "20.14.10",
"@types/remarkable": "2.0.8",
"@types/sanitize-html": "2.11.0",
"@types/uuid": "9.0.8",
"@types/uuid": "10.0.0",
"chai": "4.4.1",
"eslint": "8.56.0",
"eslint": "9.6.0",
"husky": "9.0.11",
"jsdom": "24.0.0",
"jsdom": "24.1.0",
"lodash": "4.17.21",
"mocha": "10.3.0",
"nyc": "15.1.0",
"prettier": "3.2.5",
"semantic-release": "23.0.2",
"testcafe": "3.5.0",
"mocha": "10.6.0",
"nyc": "17.0.0",
"prettier": "3.3.2",
"semantic-release": "24.0.0",
"testcafe": "3.6.2",
"ts-node": "10.9.2",
"typescript": "5.3.3",
"uuid": "9.0.1",
"webpack": "5.90.3",
"typescript": "5.5.3",
"uuid": "10.0.0",
"webpack": "5.92.1",
"webpack-cli": "5.1.4",
"webpack-visualizer-plugin2": "1.1.0"
},
......
......@@ -135,7 +135,11 @@ export class HtmlDOMParser {
phishyDiv.textContent = `${child.textContent} / ${url}`;
phishyDiv.setAttribute('title', this.localization.phishingWarning);
phishyDiv.setAttribute('class', 'phishy');
(child as any).parentNode.replaceChild(phishyDiv, child);
const parent = child.parentNode;
if (parent) {
parent.appendChild(phishyDiv);
parent.removeChild(child);
}
} else {
child.setAttribute('href', sanitizedLink);
}
......@@ -157,7 +161,12 @@ export class HtmlDOMParser {
return;
}
const html = this.xmlSerializer.serializeToString(child);
(child as any).parentNode.replaceChild(this.domParser.parseFromString(`<div class="videoWrapper">${html}</div>`), child);
const wrapper = this.domParser.parseFromString(`<div class="videoWrapper">${html}</div>`);
const parent = child.parentNode;
if (parent) {
parent.appendChild(wrapper);
parent.removeChild(child);
}
}
// TODO this is youtube specific but should be executed for all iframes and embedders
......@@ -209,7 +218,11 @@ export class HtmlDOMParser {
const content = this.linkify(data);
if (this.mutate && content !== data) {
const newChild = this.domParser.parseFromString(`<span>${content}</span>`);
(child.parentNode as any).replaceChild(newChild, child);
const parent = child.parentNode;
if (parent) {
parent.appendChild(newChild);
parent.removeChild(child);
}
return newChild;
}
} catch (error) {
......@@ -290,8 +303,10 @@ export class HtmlDOMParser {
const pre = doc.createElement('pre');
pre.setAttribute('class', 'image-url-only');
pre.appendChild(doc.createTextNode(image.getAttribute('src') || ''));
if (image.parentNode) {
image.parentNode.replaceChild(pre, image);
const parent = image.parentNode;
if (parent) {
parent.appendChild(pre);
parent.removeChild(image);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment