@tiptap/core 2.1.14 → 2.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +16 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +16 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/utilities/elementFromString.ts +21 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/core",
|
|
3
3
|
"description": "headless rich text editor",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.16",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tiptap/pm": "^2.1.
|
|
35
|
+
"@tiptap/pm": "^2.1.16"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.0.0"
|
|
@@ -1,6 +1,26 @@
|
|
|
1
|
+
const removeWhitespaces = (node: HTMLElement) => {
|
|
2
|
+
const children = node.childNodes
|
|
3
|
+
|
|
4
|
+
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
5
|
+
const child = children[i]
|
|
6
|
+
|
|
7
|
+
if (child.nodeType === 3 && child.nodeValue && !/\S/.test(child.nodeValue)) {
|
|
8
|
+
node.removeChild(child)
|
|
9
|
+
} else if (child.nodeType === 1) {
|
|
10
|
+
removeWhitespaces(child as HTMLElement)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return node
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
export function elementFromString(value: string): HTMLElement {
|
|
2
18
|
// add a wrapper to preserve leading and trailing whitespace
|
|
3
19
|
const wrappedValue = `<body>${value}</body>`
|
|
4
20
|
|
|
5
|
-
|
|
21
|
+
const html = new window.DOMParser().parseFromString(wrappedValue, 'text/html').body
|
|
22
|
+
|
|
23
|
+
removeWhitespaces(html)
|
|
24
|
+
|
|
25
|
+
return removeWhitespaces(html)
|
|
6
26
|
}
|