@scrider/formatter 1.10.9 → 1.10.11

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
@@ -548,6 +548,9 @@ var LIST_WRAPPER_TAGS = {
548
548
  checked: "ul",
549
549
  unchecked: "ul"
550
550
  };
551
+ function listWrapperFamily(listType) {
552
+ return LIST_WRAPPER_TAGS[listType] || "ul";
553
+ }
551
554
  var EMBED_RENDERERS = {
552
555
  image: (value, attrs) => {
553
556
  const src = typeof value === "string" ? value : "";
@@ -3973,7 +3976,7 @@ function handleListOpen(stack, listType, indent, pretty, resolvedDocumentPresent
3973
3976
  }
3974
3977
  }
3975
3978
  const top = stack[stack.length - 1];
3976
- if (top && top.indent === indent && top.type !== listType) {
3979
+ if (top && top.indent === indent && listWrapperFamily(top.type) !== listWrapperFamily(listType)) {
3977
3980
  const closed = stack.pop();
3978
3981
  if (closed) {
3979
3982
  const closeTag = LIST_WRAPPER_TAGS[closed.type] || "ul";
@@ -4419,6 +4422,7 @@ function htmlToDelta(html, options = {}) {
4419
4422
  if (align) {
4420
4423
  currentBlockAttributes.align = align;
4421
4424
  }
4425
+ applyBlockIndentFromMargin(element);
4422
4426
  if (format.format === "header") {
4423
4427
  const id = element.getAttribute("id");
4424
4428
  if (id) {
@@ -4837,6 +4841,7 @@ function htmlToDelta(html, options = {}) {
4837
4841
  if (align) {
4838
4842
  currentBlockAttributes.align = align;
4839
4843
  }
4844
+ applyBlockIndentFromMargin(element);
4840
4845
  const children2 = element.childNodes;
4841
4846
  const firstChild = children2[0];
4842
4847
  const isBrOnlyParagraph = children2.length === 1 && firstChild !== void 0 && isElement(firstChild) && firstChild.tagName.toLowerCase() === "br" && !firstChild.hasAttribute("data-scrider-embed");
@@ -4853,6 +4858,26 @@ function htmlToDelta(html, options = {}) {
4853
4858
  }
4854
4859
  return null;
4855
4860
  }
4861
+ function parseIndentEm(raw) {
4862
+ if (!raw) return null;
4863
+ const match = raw.trim().match(/^(-?[\d.]+)em$/i);
4864
+ if (!match) return null;
4865
+ const em = Number.parseFloat(match[1]);
4866
+ if (!Number.isFinite(em) || em <= 0) return null;
4867
+ const level = Math.round(em / 2);
4868
+ if (level < 1 || level > 8) return null;
4869
+ return level;
4870
+ }
4871
+ function getIndentFromMarginLeft(element) {
4872
+ const fromAttr = (element.getAttribute?.("style") ?? "").match(/(?:^|;)\s*margin-left:\s*([^;]+)/i)?.[1];
4873
+ const fromStyle = element.style?.getPropertyValue?.("margin-left");
4874
+ return parseIndentEm(fromAttr) ?? parseIndentEm(fromStyle);
4875
+ }
4876
+ function applyBlockIndentFromMargin(element) {
4877
+ if (currentBlockAttributes.list != null) return;
4878
+ const indent = getIndentFromMarginLeft(element);
4879
+ if (indent != null) currentBlockAttributes.indent = indent;
4880
+ }
4856
4881
  const children = fragment.childNodes;
4857
4882
  for (let i = 0; i < children.length; i++) {
4858
4883
  const child = children[i];