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