@scrider/formatter 1.3.1 → 1.3.3

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
@@ -3120,7 +3120,14 @@ function htmlToDelta(html, options = {}) {
3120
3120
  }
3121
3121
  if (tagName === "br") {
3122
3122
  const hasMarker = node.hasAttribute("data-scrider-embed");
3123
- if (hasMarker || hasMeaningfulPrevSibling(node)) {
3123
+ if (hasMarker) {
3124
+ context.pushEmbed({ softBreak: true });
3125
+ return;
3126
+ }
3127
+ if (isBrowserEmptyLineFiller(node)) {
3128
+ return;
3129
+ }
3130
+ if (hasMeaningfulPrevSibling(node)) {
3124
3131
  context.pushEmbed({ softBreak: true });
3125
3132
  } else {
3126
3133
  context.pushNewline();
@@ -3575,6 +3582,39 @@ function hasMeaningfulPrevSibling(brNode) {
3575
3582
  }
3576
3583
  return false;
3577
3584
  }
3585
+ function isBrowserEmptyLineFiller(brNode) {
3586
+ const parent = brNode.parentNode;
3587
+ if (!parent) return false;
3588
+ const children = parent.childNodes;
3589
+ let prevElement = null;
3590
+ let foundCurrent = false;
3591
+ for (let i = 0; i < children.length; i++) {
3592
+ const child = children[i];
3593
+ if (!child) continue;
3594
+ if (child === brNode) {
3595
+ foundCurrent = true;
3596
+ continue;
3597
+ }
3598
+ if (!foundCurrent) {
3599
+ if (child.nodeType === NODE_TYPE.TEXT_NODE) {
3600
+ const text = (child.textContent ?? "").replace(/[\s\u200B]/g, "");
3601
+ if (text.length > 0) prevElement = null;
3602
+ } else if (isElement(child)) {
3603
+ prevElement = child;
3604
+ }
3605
+ } else {
3606
+ if (child.nodeType === NODE_TYPE.TEXT_NODE) {
3607
+ const text = (child.textContent ?? "").replace(/[\s\u200B]/g, "");
3608
+ if (text.length > 0) return false;
3609
+ } else if (isElement(child)) {
3610
+ const tag = child.tagName?.toLowerCase();
3611
+ if (tag !== "br") return false;
3612
+ }
3613
+ }
3614
+ }
3615
+ if (!prevElement) return false;
3616
+ return prevElement.tagName?.toLowerCase() === "br";
3617
+ }
3578
3618
  function findTagHandler(handlers, element, tagName) {
3579
3619
  const className = element.getAttribute("class");
3580
3620
  if (className) {