Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: use linkedom

thecodrrad10b6c98dd4
diff --git a/packages/core/__tests__/notes.test.js b/packages/core/__tests__/notes.test.js
index 14ecdc92c..419747651 100644
--- a/packages/core/__tests__/notes.test.js
+++ b/packages/core/__tests__/notes.test.js
@@ -112,7 +112,7 @@ test("update note", () =>
title: "I am a new title",
content: {
type: TEST_NOTE.content.type,
- data: "<p><br/></p>",
+ data: "<p><br></p>",
},
pinned: true,
favorite: true,
diff --git a/packages/core/__tests__/utils/index.js b/packages/core/__tests__/utils/index.js
index ff8e7b0f5..3681d5b70 100644
--- a/packages/core/__tests__/utils/index.js
+++ b/packages/core/__tests__/utils/index.js
@@ -30,7 +30,7 @@ const notebookTest = (notebook = TEST_NOTEBOOK) =>
var TEST_NOTE = {
content: {
type: "tiny",
- data: `<p>Hello<br/><span style="color:#f00">This is colorful</span></p>`,
+ data: `<p>Hello<br><span style="color:#f00">This is colorful</span></p>`,
},
};
diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json
index d17dceefe..058b53e3b 100644
--- a/packages/core/package-lock.json
+++ b/packages/core/package-lock.json
@@ -19,6 +19,7 @@
"fast-sort": "^2.0.1",
"fflate": "^0.7.1",
"happy-dom": "^2.55.0",
+ "linkedom": "^0.14.7",
"liqe": "^1.13.0",
"node-html-parser": "github:thecodrr/node-html-parser",
"qclone": "^1.0.4",
@@ -7229,6 +7230,46 @@
"libsodium": "^0.7.0"
}
},
+ "node_modules/linkedom": {
+ "version": "0.14.7",
+ "resolved": "https://registry.npmjs.org/linkedom/-/linkedom-0.14.7.tgz",
+ "integrity": "sha512-3S0iNZDXWbKAqrtc0SU4UdhRDRm+8Fq1y15zAhcVnHWaGh+6Qnej9BF2wFJjpgdwrmF2E8nxb5axYSKLpMM3Pw==",
+ "dependencies": {
+ "css-select": "^4.3.0",
+ "cssom": "^0.5.0",
+ "html-escaper": "^3.0.3",
+ "htmlparser2": "^7.2.0",
+ "uhyphen": "^0.1.0"
+ }
+ },
+ "node_modules/linkedom/node_modules/cssom": {
+ "version": "0.5.0",
+ "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.5.0.tgz",
+ "integrity": "sha512-iKuQcq+NdHqlAcwUY0o/HL69XQrUaQdMjmStJ8JFmUaiiQErlhrmuigkg/CU4E2J0IyUKUrMAgl36TvN67MqTw=="
+ },
+ "node_modules/linkedom/node_modules/html-escaper": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
+ "integrity": "sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ=="
+ },
+ "node_modules/linkedom/node_modules/htmlparser2": {
+ "version": "7.2.0",
+ "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-7.2.0.tgz",
+ "integrity": "sha512-H7MImA4MS6cw7nbyURtLPO1Tms7C5H602LRETv95z1MxO/7CP7rDVROehUYeYBUYEON94NXXDEPmZuq+hX4sog==",
+ "funding": [
+ "https://github.com/fb55/htmlparser2?sponsor=1",
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/fb55"
+ }
+ ],
+ "dependencies": {
+ "domelementtype": "^2.0.1",
+ "domhandler": "^4.2.2",
+ "domutils": "^2.8.0",
+ "entities": "^3.0.1"
+ }
+ },
"node_modules/liqe": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/liqe/-/liqe-1.13.0.tgz",
@@ -9648,6 +9689,11 @@
"node": ">=4.2.0"
}
},
+ "node_modules/uhyphen": {
+ "version": "0.1.0",
+ "resolved": "https://registry.npmjs.org/uhyphen/-/uhyphen-0.1.0.tgz",
+ "integrity": "sha512-o0QVGuFg24FK765Qdd5kk0zU/U4dEsCtN/GSiwNI9i8xsSVtjIAOdTaVhLwZ1nrbWxFVMxNDDl+9fednsOMsBw=="
+ },
"node_modules/unicode-canonical-property-names-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
@@ -15926,6 +15972,41 @@
"libsodium": "^0.7.0"
}
},
+ "linkedom": {
+ "version": "0.14.7",
+ "resolved": "https://registry.npmjs.org/linkedom/-/linkedom-0.14.7.tgz",
+ "integrity": "sha512-3S0iNZDXWbKAqrtc0SU4UdhRDRm+8Fq1y15zAhcVnHWaGh+6Qnej9BF2wFJjpgdwrmF2E8nxb5axYSKLpMM3Pw==",
+ "requires": {
+ "css-select": "^4.3.0",
+ "cssom": "^0.5.0",
+ "html-escaper": "^3.0.3",
+ "htmlparser2": "^7.2.0",
+ "uhyphen": "^0.1.0"
+ },
+ "dependencies": {
+ "cssom": {
+ "version": "0.5.0",
+ "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.5.0.tgz",
+ "integrity": "sha512-iKuQcq+NdHqlAcwUY0o/HL69XQrUaQdMjmStJ8JFmUaiiQErlhrmuigkg/CU4E2J0IyUKUrMAgl36TvN67MqTw=="
+ },
+ "html-escaper": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
+ "integrity": "sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ=="
+ },
+ "htmlparser2": {
+ "version": "7.2.0",
+ "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-7.2.0.tgz",
+ "integrity": "sha512-H7MImA4MS6cw7nbyURtLPO1Tms7C5H602LRETv95z1MxO/7CP7rDVROehUYeYBUYEON94NXXDEPmZuq+hX4sog==",
+ "requires": {
+ "domelementtype": "^2.0.1",
+ "domhandler": "^4.2.2",
+ "domutils": "^2.8.0",
+ "entities": "^3.0.1"
+ }
+ }
+ }
+ },
"liqe": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/liqe/-/liqe-1.13.0.tgz",
@@ -17831,6 +17912,11 @@
"dev": true,
"peer": true
},
+ "uhyphen": {
+ "version": "0.1.0",
+ "resolved": "https://registry.npmjs.org/uhyphen/-/uhyphen-0.1.0.tgz",
+ "integrity": "sha512-o0QVGuFg24FK765Qdd5kk0zU/U4dEsCtN/GSiwNI9i8xsSVtjIAOdTaVhLwZ1nrbWxFVMxNDDl+9fednsOMsBw=="
+ },
"unicode-canonical-property-names-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
diff --git a/packages/core/package.json b/packages/core/package.json
index 759e982c6..ab5426eea 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -39,6 +39,7 @@
"fast-sort": "^2.0.1",
"fflate": "^0.7.1",
"happy-dom": "^2.55.0",
+ "linkedom": "^0.14.7",
"liqe": "^1.13.0",
"node-html-parser": "github:thecodrr/node-html-parser",
"qclone": "^1.0.4",
diff --git a/packages/core/utils/html-parser.js b/packages/core/utils/html-parser.js
index 79a7b9483..8e2d35f5a 100644
--- a/packages/core/utils/html-parser.js
+++ b/packages/core/utils/html-parser.js
@@ -1,13 +1,13 @@
import { decodeHTML5 } from "entities";
-import { Window } from "happy-dom";
+import { DOMParser } from "linkedom";
const RealDOMParser =
"window" in global && "DOMParser" in window
? new window.DOMParser()
- : new new Window().DOMParser();
+ : new DOMParser();
export const parseHTML = (input) =>
- RealDOMParser.parseFromString(input, "text/html");
+ RealDOMParser.parseFromString(wrapIntoHTMLDocument(input), "text/html");
export function getDummyDocument() {
const doc = parseHTML("<div></div>");
@@ -17,3 +17,9 @@ export function getDummyDocument() {
export function getInnerText(element) {
return decodeHTML5(element.innerText || element.textContent);
}
+
+function wrapIntoHTMLDocument(input) {
+ if (input.includes("<body>")) return input;
+
+ return `<!doctype html><html lang="en"><head><title>Document Fragment</title></head><body>${input}</body></html>`;
+}