@tiptap/core 2.1.15 → 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.umd.js CHANGED
@@ -1582,10 +1582,25 @@
1582
1582
  return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options);
1583
1583
  };
1584
1584
 
1585
+ const removeWhitespaces = (node) => {
1586
+ const children = node.childNodes;
1587
+ for (let i = children.length - 1; i >= 0; i -= 1) {
1588
+ const child = children[i];
1589
+ if (child.nodeType === 3 && child.nodeValue && !/\S/.test(child.nodeValue)) {
1590
+ node.removeChild(child);
1591
+ }
1592
+ else if (child.nodeType === 1) {
1593
+ removeWhitespaces(child);
1594
+ }
1595
+ }
1596
+ return node;
1597
+ };
1585
1598
  function elementFromString(value) {
1586
1599
  // add a wrapper to preserve leading and trailing whitespace
1587
1600
  const wrappedValue = `<body>${value}</body>`;
1588
- return new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
1601
+ const html = new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
1602
+ removeWhitespaces(html);
1603
+ return removeWhitespaces(html);
1589
1604
  }
1590
1605
 
1591
1606
  function createNodeFromContent(content, schema, options) {
@@ -1607,7 +1622,6 @@
1607
1622
  }
1608
1623
  }
1609
1624
  if (typeof content === 'string') {
1610
- content = content.split('\n').map(part => part.trim()).join(''); // we need to remove new lines since the parser will add breaks
1611
1625
  const parser = model.DOMParser.fromSchema(schema);
1612
1626
  return options.slice
1613
1627
  ? parser.parseSlice(elementFromString(content), options.parseOptions).content