@scrider/formatter 1.8.0 → 1.8.2

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
@@ -61,6 +61,7 @@ __export(index_exports, {
61
61
  codeBlockFormat: () => codeBlockFormat,
62
62
  codeFormat: () => codeFormat,
63
63
  codeWidgetFormat: () => codeWidgetFormat,
64
+ collectAdjacentTableLines: () => collectAdjacentTableLines,
64
65
  colorFormat: () => colorFormat,
65
66
  columnsBlockHandler: () => columnsBlockHandler,
66
67
  createDefaultBlockHandlers: () => createDefaultBlockHandlers,
@@ -88,6 +89,7 @@ __export(index_exports, {
88
89
  imageFormat: () => imageFormat,
89
90
  indentFormat: () => indentFormat,
90
91
  isAdapterAvailable: () => isAdapterAvailable,
92
+ isAdjacentSimpleTableGridBoundary: () => isAdjacentSimpleTableGridBoundary,
91
93
  isElement: () => isElement,
92
94
  isRemarkAvailable: () => isRemarkAvailable,
93
95
  isTableNewlineOp: () => isTableNewlineOp,
@@ -120,6 +122,8 @@ __export(index_exports, {
120
122
  subscriptFormat: () => subscriptFormat,
121
123
  superscriptFormat: () => superscriptFormat,
122
124
  tableBlockHandler: () => tableBlockHandler,
125
+ tableCellCoordsFromAttributes: () => tableCellCoordsFromAttributes,
126
+ tableCellCoordsFromOp: () => tableCellCoordsFromOp,
123
127
  tableColAlignFormat: () => tableColAlignFormat,
124
128
  tableColFormat: () => tableColFormat,
125
129
  tableHeaderFormat: () => tableHeaderFormat,
@@ -488,6 +492,13 @@ function isTextNode(node) {
488
492
  }
489
493
 
490
494
  // src/schema/blocks/table.ts
495
+ var VALID_CELL_HORIZONTAL_ALIGNS = [
496
+ "left",
497
+ "center",
498
+ "right",
499
+ "justify"
500
+ ];
501
+ var VALID_CELL_VERTICAL_ALIGNS = ["top", "middle", "bottom"];
491
502
  var CELL_KEY_RE = /^(\d+):(\d+)$/;
492
503
  function parseCellKey(key) {
493
504
  const match = CELL_KEY_RE.exec(key);
@@ -508,7 +519,22 @@ function getGridDimensions(cells) {
508
519
  return [maxRow + 1, maxCol + 1];
509
520
  }
510
521
  function isValidCellData(cell) {
511
- return typeof cell === "object" && cell !== null && Array.isArray(cell.ops) && cell.ops.length > 0 && (cell.colspan === void 0 || Number.isInteger(cell.colspan) && cell.colspan >= 1) && (cell.rowspan === void 0 || Number.isInteger(cell.rowspan) && cell.rowspan >= 1);
522
+ if (typeof cell !== "object" || cell === null || !Array.isArray(cell.ops) || cell.ops.length === 0) {
523
+ return false;
524
+ }
525
+ if (cell.colspan !== void 0 && (!Number.isInteger(cell.colspan) || cell.colspan < 1)) {
526
+ return false;
527
+ }
528
+ if (cell.rowspan !== void 0 && (!Number.isInteger(cell.rowspan) || cell.rowspan < 1)) {
529
+ return false;
530
+ }
531
+ if (cell.align !== void 0 && !VALID_CELL_HORIZONTAL_ALIGNS.includes(cell.align)) {
532
+ return false;
533
+ }
534
+ if (cell.vAlign !== void 0 && !VALID_CELL_VERTICAL_ALIGNS.includes(cell.vAlign)) {
535
+ return false;
536
+ }
537
+ return true;
512
538
  }
513
539
  function validateMergedCells(cells, rows, cols) {
514
540
  const covered = /* @__PURE__ */ new Set();
@@ -538,6 +564,38 @@ function validateMergedCells(cells, rows, cols) {
538
564
  }
539
565
  return true;
540
566
  }
567
+ function parseHorizontalAlign(value) {
568
+ const normalized = value?.trim().toLowerCase();
569
+ if (normalized === "left" || normalized === "center" || normalized === "right") {
570
+ return normalized;
571
+ }
572
+ if (normalized === "justify") return "justify";
573
+ return null;
574
+ }
575
+ function resolveCellHorizontalAlign(cell, col, colAligns) {
576
+ if (cell.align !== void 0) return cell.align;
577
+ const colAlign = colAligns?.[col];
578
+ if (colAlign) return colAlign;
579
+ return "left";
580
+ }
581
+ function promoteAlignFromCellOps(cell) {
582
+ if (cell.align !== void 0) return cell;
583
+ for (let i = cell.ops.length - 1; i >= 0; i--) {
584
+ const op = cell.ops[i];
585
+ if (!op || !(0, import_delta2.isInsert)(op) || !(0, import_delta2.isTextInsert)(op) || !op.insert.includes("\n")) continue;
586
+ const align = op.attributes?.align;
587
+ const parsed = typeof align === "string" ? parseHorizontalAlign(align) : null;
588
+ if (!parsed) continue;
589
+ const ops = cell.ops.map((item, idx) => {
590
+ if (idx !== i || !(0, import_delta2.isInsert)(item) || item.attributes == null) return item;
591
+ const rest = { ...item.attributes };
592
+ delete rest.align;
593
+ return Object.keys(rest).length > 0 ? { insert: item.insert, attributes: rest } : { insert: item.insert };
594
+ });
595
+ return { ...cell, ops, align: parsed };
596
+ }
597
+ return cell;
598
+ }
541
599
  function renderExtendedRow(data, row, cols, defaultCellTag, context, pretty) {
542
600
  const nl = pretty ? "\n" : "";
543
601
  const ind = (level) => pretty ? " ".repeat(level) : "";
@@ -555,11 +613,16 @@ function renderExtendedRow(data, row, cols, defaultCellTag, context, pretty) {
555
613
  if (cell.rowspan && cell.rowspan > 1) {
556
614
  attrs.push(`rowspan="${cell.rowspan}"`);
557
615
  }
558
- if (data.colAligns) {
559
- const align = data.colAligns[c];
560
- if (align && align !== "left") {
561
- attrs.push(`style="text-align: ${align}"`);
562
- }
616
+ const colDefault = data.colAligns?.[c] ?? "left";
617
+ const effectiveAlign = resolveCellHorizontalAlign(cell, c, data.colAligns);
618
+ let alignStyle = null;
619
+ if (effectiveAlign !== "left") {
620
+ alignStyle = `text-align: ${effectiveAlign}`;
621
+ } else if (cell.align === "left" && colDefault !== "left") {
622
+ alignStyle = "text-align: left";
623
+ }
624
+ if (alignStyle) {
625
+ attrs.push(`style="${alignStyle}"`);
563
626
  }
564
627
  const attrStr = attrs.length > 0 ? " " + attrs.join(" ") : "";
565
628
  let content = "";
@@ -575,6 +638,9 @@ function isGfmCompatible(data) {
575
638
  if (data.colWidths && data.colWidths.some((w) => w > 0)) {
576
639
  return false;
577
640
  }
641
+ for (const cell of Object.values(data.cells)) {
642
+ if (cell !== null && cell.align !== void 0) return false;
643
+ }
578
644
  for (const cell of Object.values(data.cells)) {
579
645
  if (cell === null) return false;
580
646
  if (cell.colspan && cell.colspan > 1) return false;
@@ -685,14 +751,28 @@ function extractColWidths(table) {
685
751
  return void 0;
686
752
  }
687
753
  function extractCellAlign(cell) {
688
- const textAlign = cell.style?.textAlign || cell.style?.getPropertyValue?.("text-align");
689
- if (textAlign === "left" || textAlign === "center" || textAlign === "right") {
690
- return textAlign;
754
+ const direct = extractInlineHorizontalAlign(cell);
755
+ if (direct) return direct;
756
+ const children = cell.childNodes;
757
+ for (let i = 0; i < children.length; i++) {
758
+ const child = children[i];
759
+ if (!child || !isElement(child)) continue;
760
+ const tag = child.tagName.toLowerCase();
761
+ if (tag === "p" || tag === "div") {
762
+ const align = extractInlineHorizontalAlign(child);
763
+ if (align) return align;
764
+ }
691
765
  }
692
- const style = cell.getAttribute("style") || "";
693
- const match = style.match(/text-align:\s*(left|center|right)/);
766
+ return null;
767
+ }
768
+ function extractInlineHorizontalAlign(element) {
769
+ const textAlign = element.style?.textAlign || element.style?.getPropertyValue?.("text-align");
770
+ const fromStyle = parseHorizontalAlign(textAlign);
771
+ if (fromStyle) return fromStyle;
772
+ const style = element.getAttribute("style") || "";
773
+ const match = style.match(/text-align:\s*(left|center|right|justify)/i);
694
774
  if (match?.[1]) {
695
- return match[1];
775
+ return parseHorizontalAlign(match[1]);
696
776
  }
697
777
  return null;
698
778
  }
@@ -701,6 +781,7 @@ function parseTableElement(table, context) {
701
781
  if (rows.length === 0) return null;
702
782
  const cells = {};
703
783
  const colAligns = [];
784
+ const rawAligns = {};
704
785
  let maxCol = 0;
705
786
  let firstRowProcessed = false;
706
787
  const occupied = /* @__PURE__ */ new Set();
@@ -729,10 +810,20 @@ function parseTableElement(table, context) {
729
810
  } else {
730
811
  ops = [{ insert: "\n" }];
731
812
  }
732
- const cellData = { ops };
813
+ let cellData = { ops };
733
814
  if (colspan > 1) cellData.colspan = colspan;
734
815
  if (rowspan > 1) cellData.rowspan = rowspan;
735
- cells[`${rowIdx}:${colIdx}`] = cellData;
816
+ cellData = promoteAlignFromCellOps(cellData);
817
+ const htmlAlign = extractCellAlign(cell);
818
+ const effectiveAlign = htmlAlign ?? cellData.align ?? "left";
819
+ if (cellData.align !== void 0) {
820
+ const withoutAlign = { ...cellData };
821
+ delete withoutAlign.align;
822
+ cellData = withoutAlign;
823
+ }
824
+ const cellKey = `${rowIdx}:${colIdx}`;
825
+ cells[cellKey] = cellData;
826
+ rawAligns[cellKey] = effectiveAlign;
736
827
  for (let dr = 0; dr < rowspan; dr++) {
737
828
  for (let dc = 0; dc < colspan; dc++) {
738
829
  if (dr === 0 && dc === 0) continue;
@@ -746,8 +837,9 @@ function parseTableElement(table, context) {
746
837
  }
747
838
  if (!firstRowProcessed) {
748
839
  const align = extractCellAlign(cell);
840
+ const colAlign = align === "center" || align === "right" ? align : null;
749
841
  for (let dc = 0; dc < colspan; dc++) {
750
- colAligns.push(align);
842
+ colAligns.push(colAlign);
751
843
  }
752
844
  }
753
845
  const cellEndCol = colIdx + colspan - 1;
@@ -788,6 +880,18 @@ function parseTableElement(table, context) {
788
880
  if (colAligns.length > totalCols) colAligns.length = totalCols;
789
881
  result.colAligns = colAligns;
790
882
  }
883
+ for (let r = 0; r < totalRows; r++) {
884
+ for (let c = 0; c < totalCols; c++) {
885
+ const key = `${r}:${c}`;
886
+ const cell = result.cells[key];
887
+ if (cell == null) continue;
888
+ const colDefault = result.colAligns?.[c] ?? "left";
889
+ const effective = rawAligns[key] ?? "left";
890
+ if (effective !== colDefault) {
891
+ result.cells[key] = { ...cell, align: effective };
892
+ }
893
+ }
894
+ }
791
895
  return result;
792
896
  }
793
897
  var tableBlockHandler = {
@@ -899,8 +1003,11 @@ var tableBlockHandler = {
899
1003
  for (const [key, cell] of Object.entries(data.cells)) {
900
1004
  if (cell !== null) {
901
1005
  const normalized = normalizeDelta(new import_delta2.Delta(cell.ops), registry);
902
- if (normalized.ops !== cell.ops) {
903
- newCells[key] = { ...cell, ops: normalized.ops };
1006
+ const promoted = promoteAlignFromCellOps(
1007
+ normalized.ops !== cell.ops ? { ...cell, ops: normalized.ops } : cell
1008
+ );
1009
+ if (promoted.ops !== cell.ops || promoted.align !== cell.align) {
1010
+ newCells[key] = promoted;
904
1011
  changed = true;
905
1012
  } else {
906
1013
  newCells[key] = cell;
@@ -2778,7 +2885,7 @@ function isAdapterAvailable() {
2778
2885
  }
2779
2886
 
2780
2887
  // src/conversion/html/delta-to-html.ts
2781
- var import_delta7 = require("@scrider/delta");
2888
+ var import_delta8 = require("@scrider/delta");
2782
2889
 
2783
2890
  // src/conversion/utils/slugify.ts
2784
2891
  function slugify(text) {
@@ -3001,6 +3108,97 @@ function buildTableCellStyleAttr(params) {
3001
3108
  return ` style="${parts.join("; ")}"`;
3002
3109
  }
3003
3110
 
3111
+ // src/conversion/markdown/table-region.ts
3112
+ var import_delta7 = require("@scrider/delta");
3113
+ function isTableNewlineOp(op) {
3114
+ if (!op || !(0, import_delta7.isInsert)(op) || !(0, import_delta7.isTextInsert)(op)) return false;
3115
+ if (!op.insert.includes("\n")) return false;
3116
+ return !!op.attributes && "table-row" in op.attributes;
3117
+ }
3118
+ function tableCellCoordsFromAttributes(attrs) {
3119
+ if (!attrs || typeof attrs["table-row"] !== "number" || typeof attrs["table-col"] !== "number") {
3120
+ return null;
3121
+ }
3122
+ return { row: attrs["table-row"], col: attrs["table-col"] };
3123
+ }
3124
+ function tableCellCoordsFromOp(op) {
3125
+ if (!isTableNewlineOp(op) || !(0, import_delta7.isTextInsert)(op)) return null;
3126
+ return tableCellCoordsFromAttributes(op.attributes);
3127
+ }
3128
+ function isAdjacentSimpleTableGridBoundary(prev, next) {
3129
+ if (next.row < prev.row) return true;
3130
+ if (next.row === 0 && prev.row === 0 && next.col === 0 && prev.col > 0) return true;
3131
+ return false;
3132
+ }
3133
+ function collectAdjacentTableLines(lines, startIndex) {
3134
+ const result = [];
3135
+ let prevCoords = null;
3136
+ for (let i = startIndex; i < lines.length; i++) {
3137
+ const line = lines[i];
3138
+ if (line === void 0) break;
3139
+ const coords = tableCellCoordsFromAttributes(line.attributes);
3140
+ if (!coords) break;
3141
+ if (prevCoords && isAdjacentSimpleTableGridBoundary(prevCoords, coords)) break;
3142
+ result.push(line);
3143
+ prevCoords = coords;
3144
+ }
3145
+ return result;
3146
+ }
3147
+ function extractTableRegion(ops, hintOpIdx) {
3148
+ if (hintOpIdx < 0 || hintOpIdx >= ops.length) return null;
3149
+ let probeIdx = -1;
3150
+ for (let i = hintOpIdx; i < ops.length; i++) {
3151
+ const op = ops[i];
3152
+ if (!op || !(0, import_delta7.isInsert)(op)) continue;
3153
+ if ((0, import_delta7.isTextInsert)(op) && op.insert.includes("\n")) {
3154
+ probeIdx = i;
3155
+ break;
3156
+ }
3157
+ }
3158
+ if (probeIdx < 0) return null;
3159
+ if (!isTableNewlineOp(ops[probeIdx])) return null;
3160
+ const probeCoords = tableCellCoordsFromOp(ops[probeIdx]);
3161
+ if (!probeCoords) return null;
3162
+ let endOpIdx = probeIdx;
3163
+ let prevCoords = probeCoords;
3164
+ for (let i = probeIdx + 1; i < ops.length; i++) {
3165
+ const op = ops[i];
3166
+ if (!op || !(0, import_delta7.isInsert)(op)) break;
3167
+ if (!(0, import_delta7.isTextInsert)(op) || !op.insert.includes("\n")) continue;
3168
+ if (isTableNewlineOp(op)) {
3169
+ const coords = tableCellCoordsFromOp(op);
3170
+ if (isAdjacentSimpleTableGridBoundary(prevCoords, coords)) break;
3171
+ prevCoords = coords;
3172
+ endOpIdx = i;
3173
+ } else {
3174
+ break;
3175
+ }
3176
+ }
3177
+ let startOpIdx = 0;
3178
+ let nextCoords = probeCoords;
3179
+ for (let i = probeIdx - 1; i >= 0; i--) {
3180
+ const op = ops[i];
3181
+ if (!op || !(0, import_delta7.isInsert)(op)) {
3182
+ startOpIdx = i + 1;
3183
+ break;
3184
+ }
3185
+ if (!(0, import_delta7.isTextInsert)(op) || !op.insert.includes("\n")) continue;
3186
+ if (isTableNewlineOp(op)) {
3187
+ const coords = tableCellCoordsFromOp(op);
3188
+ if (isAdjacentSimpleTableGridBoundary(coords, nextCoords)) {
3189
+ startOpIdx = i + 1;
3190
+ break;
3191
+ }
3192
+ nextCoords = coords;
3193
+ } else {
3194
+ startOpIdx = i + 1;
3195
+ break;
3196
+ }
3197
+ }
3198
+ const regionOps = ops.slice(startOpIdx, endOpIdx + 1);
3199
+ return { startOpIdx, endOpIdx, ops: regionOps };
3200
+ }
3201
+
3004
3202
  // src/conversion/html/delta-to-html.ts
3005
3203
  function deltaToHtml(delta, options = {}) {
3006
3204
  const lines = splitIntoLines(delta);
@@ -3021,7 +3219,7 @@ function deltaToHtml(delta, options = {}) {
3021
3219
  html += closeAllLists(listStack, pretty);
3022
3220
  listStack = [];
3023
3221
  counters = [];
3024
- const tableLines = collectTableLines(lines, i);
3222
+ const tableLines = collectAdjacentTableLines(lines, i);
3025
3223
  html += renderTable(tableLines, embedRenderers, pretty, blockHandlers, options);
3026
3224
  i += tableLines.length - 1;
3027
3225
  continue;
@@ -3130,8 +3328,8 @@ function splitIntoLines(delta) {
3130
3328
  const lines = [];
3131
3329
  let currentOps = [];
3132
3330
  for (const op of delta.ops) {
3133
- if (!(0, import_delta7.isInsert)(op)) continue;
3134
- if ((0, import_delta7.isEmbedInsert)(op)) {
3331
+ if (!(0, import_delta8.isInsert)(op)) continue;
3332
+ if ((0, import_delta8.isEmbedInsert)(op)) {
3135
3333
  currentOps.push(op);
3136
3334
  continue;
3137
3335
  }
@@ -3168,7 +3366,7 @@ var BLOCK_LEVEL_EMBEDS = /* @__PURE__ */ new Set(["divider", "block"]);
3168
3366
  function isBlockLevelEmbedLine(line) {
3169
3367
  if (line.ops.length !== 1) return false;
3170
3368
  const op = line.ops[0];
3171
- if (!op || !(0, import_delta7.isEmbedInsert)(op)) return false;
3369
+ if (!op || !(0, import_delta8.isEmbedInsert)(op)) return false;
3172
3370
  const embed = op.insert;
3173
3371
  const embedType = Object.keys(embed)[0];
3174
3372
  if (!!embedType && BLOCK_LEVEL_EMBEDS.has(embedType)) return true;
@@ -3179,15 +3377,6 @@ function isBlockLevelEmbedLine(line) {
3179
3377
  function isTableLine(line) {
3180
3378
  return line.attributes != null && typeof line.attributes["table-row"] === "number" && typeof line.attributes["table-col"] === "number";
3181
3379
  }
3182
- function collectTableLines(lines, startIndex) {
3183
- const result = [];
3184
- for (let i = startIndex; i < lines.length; i++) {
3185
- const line = lines[i];
3186
- if (!line || !isTableLine(line)) break;
3187
- result.push(line);
3188
- }
3189
- return result;
3190
- }
3191
3380
  function renderTable(tableLines, embedRenderers, pretty, blockHandlers, options) {
3192
3381
  const rows = /* @__PURE__ */ new Map();
3193
3382
  for (const line of tableLines) {
@@ -3458,7 +3647,7 @@ function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
3458
3647
  function extractPlainText(ops) {
3459
3648
  let text = "";
3460
3649
  for (const op of ops) {
3461
- if ((0, import_delta7.isInsert)(op) && typeof op.insert === "string") {
3650
+ if ((0, import_delta8.isInsert)(op) && typeof op.insert === "string") {
3462
3651
  text += op.insert;
3463
3652
  }
3464
3653
  }
@@ -3467,8 +3656,8 @@ function extractPlainText(ops) {
3467
3656
  function renderLineContent(ops, embedRenderers, blockHandlers, options) {
3468
3657
  let html = "";
3469
3658
  for (const op of ops) {
3470
- if (!(0, import_delta7.isInsert)(op)) continue;
3471
- if ((0, import_delta7.isEmbedInsert)(op)) {
3659
+ if (!(0, import_delta8.isInsert)(op)) continue;
3660
+ if ((0, import_delta8.isEmbedInsert)(op)) {
3472
3661
  html += renderEmbed(
3473
3662
  op.insert,
3474
3663
  op.attributes,
@@ -3524,7 +3713,7 @@ function renderEmbed(value, attributes, renderers, blockHandlers, options) {
3524
3713
  const context = {
3525
3714
  registry: null,
3526
3715
  options: { pretty: options?.pretty ?? false },
3527
- renderDelta: (ops) => deltaToHtml(new import_delta7.Delta(ops), options ?? {}),
3716
+ renderDelta: (ops) => deltaToHtml(new import_delta8.Delta(ops), options ?? {}),
3528
3717
  ...attributes ? { opAttributes: attributes } : {}
3529
3718
  };
3530
3719
  return handler.toHtml(blockData, context);
@@ -3549,13 +3738,13 @@ function renderEmbed(value, attributes, renderers, blockHandlers, options) {
3549
3738
  }
3550
3739
 
3551
3740
  // src/conversion/html/html-to-delta.ts
3552
- var import_delta8 = require("@scrider/delta");
3741
+ var import_delta9 = require("@scrider/delta");
3553
3742
  function htmlToDelta(html, options = {}) {
3554
3743
  const adapter = options.adapter ?? getAdapter();
3555
3744
  const normalizeWhitespace = options.normalizeWhitespace ?? true;
3556
3745
  const tagHandlers = { ...DEFAULT_TAG_HANDLERS, ...options.tagHandlers };
3557
3746
  const fragment = adapter.parseHTML(html);
3558
- const delta = new import_delta8.Delta();
3747
+ const delta = new import_delta9.Delta();
3559
3748
  let currentAttributes = {};
3560
3749
  let currentBlockAttributes = {};
3561
3750
  let pendingText = "";
@@ -4265,7 +4454,7 @@ var DEFAULT_TAG_HANDLERS = {
4265
4454
  };
4266
4455
 
4267
4456
  // src/conversion/markdown/delta-to-markdown.ts
4268
- var import_delta9 = require("@scrider/delta");
4457
+ var import_delta10 = require("@scrider/delta");
4269
4458
 
4270
4459
  // src/conversion/markdown/config.ts
4271
4460
  var MARKDOWN_ESCAPE_CHARS = /[\\`*_[\]<>#]/g;
@@ -4353,7 +4542,7 @@ function deltaToMarkdown(delta, options = {}) {
4353
4542
  const attrs = line.attributes;
4354
4543
  const isBlockquote = !!attrs.blockquote;
4355
4544
  if (typeof attrs["table-row"] === "number" && typeof attrs["table-col"] === "number") {
4356
- const tableLines = collectTableLines2(lines, i);
4545
+ const tableLines = collectAdjacentTableLines(lines, i);
4357
4546
  result.push(
4358
4547
  renderMarkdownTable(tableLines, embedRenderers, useLatexDelimiters, registry, softBreakStyle)
4359
4548
  );
@@ -4458,9 +4647,9 @@ function splitIntoLines2(ops) {
4458
4647
  const lines = [];
4459
4648
  let currentOps = [];
4460
4649
  for (const op of ops) {
4461
- if (!(0, import_delta9.isInsert)(op)) continue;
4650
+ if (!(0, import_delta10.isInsert)(op)) continue;
4462
4651
  const opAttrs = op.attributes ?? {};
4463
- if ((0, import_delta9.isTextInsert)(op)) {
4652
+ if ((0, import_delta10.isTextInsert)(op)) {
4464
4653
  const text = op.insert;
4465
4654
  const parts = text.split("\n");
4466
4655
  for (let i = 0; i < parts.length; i++) {
@@ -4525,17 +4714,6 @@ function collectCodeBlock(lines, startIndex) {
4525
4714
  }
4526
4715
  return codeLines;
4527
4716
  }
4528
- function collectTableLines2(lines, startIndex) {
4529
- const result = [];
4530
- for (let i = startIndex; i < lines.length; i++) {
4531
- const line = lines[i];
4532
- if (!line || typeof line.attributes["table-row"] !== "number" || typeof line.attributes["table-col"] !== "number") {
4533
- break;
4534
- }
4535
- result.push(line);
4536
- }
4537
- return result;
4538
- }
4539
4717
  function renderMarkdownTable(tableLines, embedRenderers, useLatexDelimiters = false, registry, softBreakStyle = "spaces") {
4540
4718
  const rows = /* @__PURE__ */ new Map();
4541
4719
  for (const line of tableLines) {
@@ -4671,14 +4849,14 @@ function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters
4671
4849
  let result = "";
4672
4850
  for (const op of ops) {
4673
4851
  const attrs = op.attributes;
4674
- if ((0, import_delta9.isTextInsert)(op)) {
4852
+ if ((0, import_delta10.isTextInsert)(op)) {
4675
4853
  const text = op.insert;
4676
4854
  if (inCodeBlock) {
4677
4855
  result += text;
4678
4856
  } else {
4679
4857
  result += renderInlineText2(text, attrs);
4680
4858
  }
4681
- } else if ((0, import_delta9.isEmbedInsert)(op)) {
4859
+ } else if ((0, import_delta10.isEmbedInsert)(op)) {
4682
4860
  const embed = op.insert;
4683
4861
  result += renderEmbed2(
4684
4862
  embed,
@@ -4743,7 +4921,7 @@ function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = f
4743
4921
  if (handler.toMarkdown) {
4744
4922
  const mdContext = {
4745
4923
  registry: void 0,
4746
- renderDelta: (ops) => deltaToMarkdown(new import_delta9.Delta(ops), { blockHandlers }),
4924
+ renderDelta: (ops) => deltaToMarkdown(new import_delta10.Delta(ops), { blockHandlers }),
4747
4925
  ...opAttrs
4748
4926
  };
4749
4927
  const md = handler.toMarkdown(blockData, mdContext);
@@ -4752,7 +4930,7 @@ function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = f
4752
4930
  const htmlContext = {
4753
4931
  registry: void 0,
4754
4932
  ...prettyHtml ? { options: { pretty: true } } : {},
4755
- renderDelta: (ops) => deltaToHtml(new import_delta9.Delta(ops), { blockHandlers, pretty: prettyHtml }),
4933
+ renderDelta: (ops) => deltaToHtml(new import_delta10.Delta(ops), { blockHandlers, pretty: prettyHtml }),
4756
4934
  ...opAttrs
4757
4935
  };
4758
4936
  return "\n" + handler.toHtml(blockData, htmlContext) + "\n";
@@ -4900,12 +5078,12 @@ function renderBlockFormat(content, attributes, orderedIndex, _strict) {
4900
5078
  }
4901
5079
 
4902
5080
  // src/conversion/markdown/markdown-to-delta.ts
4903
- var import_delta11 = require("@scrider/delta");
5081
+ var import_delta12 = require("@scrider/delta");
4904
5082
 
4905
5083
  // src/conversion/markdown/table-header-normalize.ts
4906
- var import_delta10 = require("@scrider/delta");
5084
+ var import_delta11 = require("@scrider/delta");
4907
5085
  function isTableCellTerminator(op) {
4908
- return (0, import_delta10.isInsert)(op) && typeof op.insert === "string" && op.insert === "\n" && op.attributes !== void 0 && typeof op.attributes["table-row"] === "number";
5086
+ return (0, import_delta11.isInsert)(op) && typeof op.insert === "string" && op.insert === "\n" && op.attributes !== void 0 && typeof op.attributes["table-row"] === "number";
4909
5087
  }
4910
5088
  function normalizeSyntheticEmptyHeaderRow(ops) {
4911
5089
  const ends = [];
@@ -4914,7 +5092,7 @@ function normalizeSyntheticEmptyHeaderRow(ops) {
4914
5092
  let currentTextOps = [];
4915
5093
  for (let i = 0; i < ops.length; i++) {
4916
5094
  const op = ops[i];
4917
- if (!(0, import_delta10.isInsert)(op)) continue;
5095
+ if (!(0, import_delta11.isInsert)(op)) continue;
4918
5096
  if (typeof op.insert === "string" && op.insert !== "\n") {
4919
5097
  buf += op.insert;
4920
5098
  currentTextOps.push(i);
@@ -4965,7 +5143,7 @@ function normalizeHeaderDashPlaceholders(ops) {
4965
5143
  let currentTextOps = [];
4966
5144
  for (let i = 0; i < ops.length; i++) {
4967
5145
  const op = ops[i];
4968
- if (!(0, import_delta10.isInsert)(op)) continue;
5146
+ if (!(0, import_delta11.isInsert)(op)) continue;
4969
5147
  if (typeof op.insert === "string" && op.insert !== "\n") {
4970
5148
  buf += op.insert;
4971
5149
  currentTextOps.push(i);
@@ -4994,7 +5172,7 @@ function normalizeHeaderDashPlaceholders(ops) {
4994
5172
  out.push(op);
4995
5173
  continue;
4996
5174
  }
4997
- if (!(0, import_delta10.isInsert)(op)) {
5175
+ if (!(0, import_delta11.isInsert)(op)) {
4998
5176
  out.push(op);
4999
5177
  continue;
5000
5178
  }
@@ -5015,7 +5193,7 @@ function normalizeImportedTableOps(ops) {
5015
5193
  const ends = [];
5016
5194
  let buf = "";
5017
5195
  for (const op of ops) {
5018
- if (!(0, import_delta10.isInsert)(op)) continue;
5196
+ if (!(0, import_delta11.isInsert)(op)) continue;
5019
5197
  if (typeof op.insert === "string" && op.insert !== "\n") {
5020
5198
  buf += op.insert;
5021
5199
  continue;
@@ -5168,7 +5346,7 @@ function markdownToDeltaSync(markdown, options = {}) {
5168
5346
  );
5169
5347
  }
5170
5348
  function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock, blockHandlers) {
5171
- const delta = new import_delta11.Delta();
5349
+ const delta = new import_delta12.Delta();
5172
5350
  let currentInlineAttrs = {};
5173
5351
  let pendingText = "";
5174
5352
  const spanAttrStack = [];
@@ -5551,7 +5729,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
5551
5729
  }
5552
5730
  const tableOps = delta.ops.splice(tableStart);
5553
5731
  for (const op of normalizeImportedTableOps(tableOps)) {
5554
- if (!(0, import_delta11.isInsert)(op)) continue;
5732
+ if (!(0, import_delta12.isInsert)(op)) continue;
5555
5733
  if (op.attributes && Object.keys(op.attributes).length > 0) {
5556
5734
  delta.insert(op.insert, op.attributes);
5557
5735
  } else {
@@ -5737,54 +5915,6 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
5737
5915
  }
5738
5916
  return delta;
5739
5917
  }
5740
-
5741
- // src/conversion/markdown/table-region.ts
5742
- var import_delta12 = require("@scrider/delta");
5743
- function isTableNewlineOp(op) {
5744
- if (!op || !(0, import_delta12.isInsert)(op) || !(0, import_delta12.isTextInsert)(op)) return false;
5745
- if (!op.insert.includes("\n")) return false;
5746
- return !!op.attributes && "table-row" in op.attributes;
5747
- }
5748
- function extractTableRegion(ops, hintOpIdx) {
5749
- if (hintOpIdx < 0 || hintOpIdx >= ops.length) return null;
5750
- let probeIdx = -1;
5751
- for (let i = hintOpIdx; i < ops.length; i++) {
5752
- const op = ops[i];
5753
- if (!op || !(0, import_delta12.isInsert)(op)) continue;
5754
- if ((0, import_delta12.isTextInsert)(op) && op.insert.includes("\n")) {
5755
- probeIdx = i;
5756
- break;
5757
- }
5758
- }
5759
- if (probeIdx < 0) return null;
5760
- if (!isTableNewlineOp(ops[probeIdx])) return null;
5761
- let endOpIdx = probeIdx;
5762
- for (let i = probeIdx + 1; i < ops.length; i++) {
5763
- const op = ops[i];
5764
- if (!op || !(0, import_delta12.isInsert)(op)) break;
5765
- if ((0, import_delta12.isTextInsert)(op) && op.insert.includes("\n")) {
5766
- if (isTableNewlineOp(op)) {
5767
- endOpIdx = i;
5768
- } else {
5769
- break;
5770
- }
5771
- }
5772
- }
5773
- let startOpIdx = 0;
5774
- for (let i = probeIdx - 1; i >= 0; i--) {
5775
- const op = ops[i];
5776
- if (!op || !(0, import_delta12.isInsert)(op)) {
5777
- startOpIdx = i + 1;
5778
- break;
5779
- }
5780
- if ((0, import_delta12.isTextInsert)(op) && op.insert.includes("\n") && !isTableNewlineOp(op)) {
5781
- startOpIdx = i + 1;
5782
- break;
5783
- }
5784
- }
5785
- const regionOps = ops.slice(startOpIdx, endOpIdx + 1);
5786
- return { startOpIdx, endOpIdx, ops: regionOps };
5787
- }
5788
5918
  // Annotate the CommonJS export names for ESM import in node:
5789
5919
  0 && (module.exports = {
5790
5920
  ALERT_TYPES,
@@ -5817,6 +5947,7 @@ function extractTableRegion(ops, hintOpIdx) {
5817
5947
  codeBlockFormat,
5818
5948
  codeFormat,
5819
5949
  codeWidgetFormat,
5950
+ collectAdjacentTableLines,
5820
5951
  colorFormat,
5821
5952
  columnsBlockHandler,
5822
5953
  createDefaultBlockHandlers,
@@ -5844,6 +5975,7 @@ function extractTableRegion(ops, hintOpIdx) {
5844
5975
  imageFormat,
5845
5976
  indentFormat,
5846
5977
  isAdapterAvailable,
5978
+ isAdjacentSimpleTableGridBoundary,
5847
5979
  isElement,
5848
5980
  isRemarkAvailable,
5849
5981
  isTableNewlineOp,
@@ -5876,6 +6008,8 @@ function extractTableRegion(ops, hintOpIdx) {
5876
6008
  subscriptFormat,
5877
6009
  superscriptFormat,
5878
6010
  tableBlockHandler,
6011
+ tableCellCoordsFromAttributes,
6012
+ tableCellCoordsFromOp,
5879
6013
  tableColAlignFormat,
5880
6014
  tableColFormat,
5881
6015
  tableHeaderFormat,