mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
fix: sanitze all elements
This commit is contained in:
@@ -11,8 +11,10 @@ function register(editor) {
|
||||
editor.getHTML = async function () {
|
||||
const html = editor.getBody().innerHTML;
|
||||
const document = new DOMParser().parseFromString(html, "text/html");
|
||||
|
||||
const elements = document.querySelectorAll(QUERY);
|
||||
for (let element of elements) {
|
||||
sanitizeElement(element);
|
||||
switch (element.nodeName) {
|
||||
case "IMG": {
|
||||
const image = element;
|
||||
@@ -26,15 +28,6 @@ function register(editor) {
|
||||
const datauri = await blobUriToDataUri(image.src);
|
||||
image.src = datauri;
|
||||
}
|
||||
default: {
|
||||
for (let attr of element.attributes) {
|
||||
if (ATTRIBUTES.strip.indexOf(attr.name) > -1)
|
||||
element.removeAttribute(attr.name);
|
||||
else if (ATTRIBUTES.elementDelete.indexOf(attr.name) > -1) {
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return document.body.innerHTML;
|
||||
@@ -87,3 +80,13 @@ function countWords(str) {
|
||||
if (shouldCount) ++count;
|
||||
return count;
|
||||
}
|
||||
|
||||
function sanitizeElement(element) {
|
||||
for (let attr of element.attributes) {
|
||||
if (ATTRIBUTES.strip.indexOf(attr.name) > -1)
|
||||
element.removeAttribute(attr.name);
|
||||
else if (ATTRIBUTES.elementDelete.indexOf(attr.name) > -1) {
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user