@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.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
- return new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
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) {