@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/dist/index.js
CHANGED
|
@@ -1584,10 +1584,25 @@ const insertContent = (value, options) => ({ tr, commands }) => {
|
|
|
1584
1584
|
return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options);
|
|
1585
1585
|
};
|
|
1586
1586
|
|
|
1587
|
+
const removeWhitespaces = (node) => {
|
|
1588
|
+
const children = node.childNodes;
|
|
1589
|
+
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
1590
|
+
const child = children[i];
|
|
1591
|
+
if (child.nodeType === 3 && child.nodeValue && !/\S/.test(child.nodeValue)) {
|
|
1592
|
+
node.removeChild(child);
|
|
1593
|
+
}
|
|
1594
|
+
else if (child.nodeType === 1) {
|
|
1595
|
+
removeWhitespaces(child);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return node;
|
|
1599
|
+
};
|
|
1587
1600
|
function elementFromString(value) {
|
|
1588
1601
|
// add a wrapper to preserve leading and trailing whitespace
|
|
1589
1602
|
const wrappedValue = `<body>${value}</body>`;
|
|
1590
|
-
|
|
1603
|
+
const html = new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
|
|
1604
|
+
removeWhitespaces(html);
|
|
1605
|
+
return removeWhitespaces(html);
|
|
1591
1606
|
}
|
|
1592
1607
|
|
|
1593
1608
|
function createNodeFromContent(content, schema, options) {
|