@scrider/formatter 1.8.0 → 1.8.1

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.d.cts CHANGED
@@ -1992,11 +1992,34 @@ interface TableRegion {
1992
1992
  /** Slice of the original ops array covering the region. */
1993
1993
  ops: InsertOp[];
1994
1994
  }
1995
+ /** Coordinates carried on a simple-table cell terminator `\n`. */
1996
+ interface TableCellCoords {
1997
+ row: number;
1998
+ col: number;
1999
+ }
1995
2000
  /**
1996
2001
  * Predicate: this op is a `\n`-op that terminates a simple-table cell
1997
2002
  * (i.e. it carries a `table-row` attribute).
1998
2003
  */
1999
2004
  declare function isTableNewlineOp(op: Op | undefined): boolean;
2005
+ declare function tableCellCoordsFromAttributes(attrs: AttributeMap | undefined): TableCellCoords | null;
2006
+ declare function tableCellCoordsFromOp(op: Op): TableCellCoords | null;
2007
+ /**
2008
+ * True when `next` begins a new simple-table grid immediately after `prev`
2009
+ * with no plain paragraph `\n` between them.
2010
+ *
2011
+ * Patterns:
2012
+ * • row decreases (e.g. 1 → 0) — new grid after a multi-row table
2013
+ * • both on row 0 but col resets to 0 — two single-row tables stacked
2014
+ */
2015
+ declare function isAdjacentSimpleTableGridBoundary(prev: TableCellCoords, next: TableCellCoords): boolean;
2016
+ /**
2017
+ * Collect consecutive table lines for one simple-table grid.
2018
+ * Stops at the first non-table line or at an adjacent-grid boundary.
2019
+ */
2020
+ declare function collectAdjacentTableLines<T extends {
2021
+ attributes?: AttributeMap | undefined;
2022
+ }>(lines: readonly T[], startIndex: number): T[];
2000
2023
  /**
2001
2024
  * Find the boundaries of the simple-table region containing the given hint
2002
2025
  * op index. The hint may be:
@@ -2007,8 +2030,9 @@ declare function isTableNewlineOp(op: Op | undefined): boolean;
2007
2030
  * The function walks **forward** from the hint to find the nearest `\n`-op:
2008
2031
  * if it does not carry a `table-row` attribute, the hint is not inside a
2009
2032
  * table and `null` is returned. Otherwise the algorithm extends the region
2010
- * forward through contiguous table newlines and backward to the op just
2011
- * after the previous non-table `\n`-op (or the start of the array).
2033
+ * forward through contiguous table newlines (stopping at adjacent-grid
2034
+ * boundaries) and backward to the op just after the previous non-table
2035
+ * `\n`-op or adjacent-grid boundary (or the start of the array).
2012
2036
  *
2013
2037
  * @param ops - The full ops array (e.g. `delta.ops`).
2014
2038
  * @param hintOpIdx - Any op index known or guessed to be within a table.
@@ -2028,4 +2052,4 @@ declare function isTableNewlineOp(op: Op | undefined): boolean;
2028
2052
  */
2029
2053
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
2030
2054
 
2031
- export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
2055
+ export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
package/dist/index.d.ts CHANGED
@@ -1992,11 +1992,34 @@ interface TableRegion {
1992
1992
  /** Slice of the original ops array covering the region. */
1993
1993
  ops: InsertOp[];
1994
1994
  }
1995
+ /** Coordinates carried on a simple-table cell terminator `\n`. */
1996
+ interface TableCellCoords {
1997
+ row: number;
1998
+ col: number;
1999
+ }
1995
2000
  /**
1996
2001
  * Predicate: this op is a `\n`-op that terminates a simple-table cell
1997
2002
  * (i.e. it carries a `table-row` attribute).
1998
2003
  */
1999
2004
  declare function isTableNewlineOp(op: Op | undefined): boolean;
2005
+ declare function tableCellCoordsFromAttributes(attrs: AttributeMap | undefined): TableCellCoords | null;
2006
+ declare function tableCellCoordsFromOp(op: Op): TableCellCoords | null;
2007
+ /**
2008
+ * True when `next` begins a new simple-table grid immediately after `prev`
2009
+ * with no plain paragraph `\n` between them.
2010
+ *
2011
+ * Patterns:
2012
+ * • row decreases (e.g. 1 → 0) — new grid after a multi-row table
2013
+ * • both on row 0 but col resets to 0 — two single-row tables stacked
2014
+ */
2015
+ declare function isAdjacentSimpleTableGridBoundary(prev: TableCellCoords, next: TableCellCoords): boolean;
2016
+ /**
2017
+ * Collect consecutive table lines for one simple-table grid.
2018
+ * Stops at the first non-table line or at an adjacent-grid boundary.
2019
+ */
2020
+ declare function collectAdjacentTableLines<T extends {
2021
+ attributes?: AttributeMap | undefined;
2022
+ }>(lines: readonly T[], startIndex: number): T[];
2000
2023
  /**
2001
2024
  * Find the boundaries of the simple-table region containing the given hint
2002
2025
  * op index. The hint may be:
@@ -2007,8 +2030,9 @@ declare function isTableNewlineOp(op: Op | undefined): boolean;
2007
2030
  * The function walks **forward** from the hint to find the nearest `\n`-op:
2008
2031
  * if it does not carry a `table-row` attribute, the hint is not inside a
2009
2032
  * table and `null` is returned. Otherwise the algorithm extends the region
2010
- * forward through contiguous table newlines and backward to the op just
2011
- * after the previous non-table `\n`-op (or the start of the array).
2033
+ * forward through contiguous table newlines (stopping at adjacent-grid
2034
+ * boundaries) and backward to the op just after the previous non-table
2035
+ * `\n`-op or adjacent-grid boundary (or the start of the array).
2012
2036
  *
2013
2037
  * @param ops - The full ops array (e.g. `delta.ops`).
2014
2038
  * @param hintOpIdx - Any op index known or guessed to be within a table.
@@ -2028,4 +2052,4 @@ declare function isTableNewlineOp(op: Op | undefined): boolean;
2028
2052
  */
2029
2053
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
2030
2054
 
2031
- export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
2055
+ export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
package/dist/index.js CHANGED
@@ -2652,7 +2652,7 @@ function isAdapterAvailable() {
2652
2652
  }
2653
2653
 
2654
2654
  // src/conversion/html/delta-to-html.ts
2655
- import { Delta as Delta7, isInsert as isInsert2, isEmbedInsert as isEmbedInsert2 } from "@scrider/delta";
2655
+ import { Delta as Delta7, isInsert as isInsert3, isEmbedInsert as isEmbedInsert2 } from "@scrider/delta";
2656
2656
 
2657
2657
  // src/conversion/utils/slugify.ts
2658
2658
  function slugify(text) {
@@ -2875,6 +2875,97 @@ function buildTableCellStyleAttr(params) {
2875
2875
  return ` style="${parts.join("; ")}"`;
2876
2876
  }
2877
2877
 
2878
+ // src/conversion/markdown/table-region.ts
2879
+ import { isInsert as isInsert2, isTextInsert as isTextInsert2 } from "@scrider/delta";
2880
+ function isTableNewlineOp(op) {
2881
+ if (!op || !isInsert2(op) || !isTextInsert2(op)) return false;
2882
+ if (!op.insert.includes("\n")) return false;
2883
+ return !!op.attributes && "table-row" in op.attributes;
2884
+ }
2885
+ function tableCellCoordsFromAttributes(attrs) {
2886
+ if (!attrs || typeof attrs["table-row"] !== "number" || typeof attrs["table-col"] !== "number") {
2887
+ return null;
2888
+ }
2889
+ return { row: attrs["table-row"], col: attrs["table-col"] };
2890
+ }
2891
+ function tableCellCoordsFromOp(op) {
2892
+ if (!isTableNewlineOp(op) || !isTextInsert2(op)) return null;
2893
+ return tableCellCoordsFromAttributes(op.attributes);
2894
+ }
2895
+ function isAdjacentSimpleTableGridBoundary(prev, next) {
2896
+ if (next.row < prev.row) return true;
2897
+ if (next.row === 0 && prev.row === 0 && next.col === 0 && prev.col > 0) return true;
2898
+ return false;
2899
+ }
2900
+ function collectAdjacentTableLines(lines, startIndex) {
2901
+ const result = [];
2902
+ let prevCoords = null;
2903
+ for (let i = startIndex; i < lines.length; i++) {
2904
+ const line = lines[i];
2905
+ if (line === void 0) break;
2906
+ const coords = tableCellCoordsFromAttributes(line.attributes);
2907
+ if (!coords) break;
2908
+ if (prevCoords && isAdjacentSimpleTableGridBoundary(prevCoords, coords)) break;
2909
+ result.push(line);
2910
+ prevCoords = coords;
2911
+ }
2912
+ return result;
2913
+ }
2914
+ function extractTableRegion(ops, hintOpIdx) {
2915
+ if (hintOpIdx < 0 || hintOpIdx >= ops.length) return null;
2916
+ let probeIdx = -1;
2917
+ for (let i = hintOpIdx; i < ops.length; i++) {
2918
+ const op = ops[i];
2919
+ if (!op || !isInsert2(op)) continue;
2920
+ if (isTextInsert2(op) && op.insert.includes("\n")) {
2921
+ probeIdx = i;
2922
+ break;
2923
+ }
2924
+ }
2925
+ if (probeIdx < 0) return null;
2926
+ if (!isTableNewlineOp(ops[probeIdx])) return null;
2927
+ const probeCoords = tableCellCoordsFromOp(ops[probeIdx]);
2928
+ if (!probeCoords) return null;
2929
+ let endOpIdx = probeIdx;
2930
+ let prevCoords = probeCoords;
2931
+ for (let i = probeIdx + 1; i < ops.length; i++) {
2932
+ const op = ops[i];
2933
+ if (!op || !isInsert2(op)) break;
2934
+ if (!isTextInsert2(op) || !op.insert.includes("\n")) continue;
2935
+ if (isTableNewlineOp(op)) {
2936
+ const coords = tableCellCoordsFromOp(op);
2937
+ if (isAdjacentSimpleTableGridBoundary(prevCoords, coords)) break;
2938
+ prevCoords = coords;
2939
+ endOpIdx = i;
2940
+ } else {
2941
+ break;
2942
+ }
2943
+ }
2944
+ let startOpIdx = 0;
2945
+ let nextCoords = probeCoords;
2946
+ for (let i = probeIdx - 1; i >= 0; i--) {
2947
+ const op = ops[i];
2948
+ if (!op || !isInsert2(op)) {
2949
+ startOpIdx = i + 1;
2950
+ break;
2951
+ }
2952
+ if (!isTextInsert2(op) || !op.insert.includes("\n")) continue;
2953
+ if (isTableNewlineOp(op)) {
2954
+ const coords = tableCellCoordsFromOp(op);
2955
+ if (isAdjacentSimpleTableGridBoundary(coords, nextCoords)) {
2956
+ startOpIdx = i + 1;
2957
+ break;
2958
+ }
2959
+ nextCoords = coords;
2960
+ } else {
2961
+ startOpIdx = i + 1;
2962
+ break;
2963
+ }
2964
+ }
2965
+ const regionOps = ops.slice(startOpIdx, endOpIdx + 1);
2966
+ return { startOpIdx, endOpIdx, ops: regionOps };
2967
+ }
2968
+
2878
2969
  // src/conversion/html/delta-to-html.ts
2879
2970
  function deltaToHtml(delta, options = {}) {
2880
2971
  const lines = splitIntoLines(delta);
@@ -2895,7 +2986,7 @@ function deltaToHtml(delta, options = {}) {
2895
2986
  html += closeAllLists(listStack, pretty);
2896
2987
  listStack = [];
2897
2988
  counters = [];
2898
- const tableLines = collectTableLines(lines, i);
2989
+ const tableLines = collectAdjacentTableLines(lines, i);
2899
2990
  html += renderTable(tableLines, embedRenderers, pretty, blockHandlers, options);
2900
2991
  i += tableLines.length - 1;
2901
2992
  continue;
@@ -3004,7 +3095,7 @@ function splitIntoLines(delta) {
3004
3095
  const lines = [];
3005
3096
  let currentOps = [];
3006
3097
  for (const op of delta.ops) {
3007
- if (!isInsert2(op)) continue;
3098
+ if (!isInsert3(op)) continue;
3008
3099
  if (isEmbedInsert2(op)) {
3009
3100
  currentOps.push(op);
3010
3101
  continue;
@@ -3053,15 +3144,6 @@ function isBlockLevelEmbedLine(line) {
3053
3144
  function isTableLine(line) {
3054
3145
  return line.attributes != null && typeof line.attributes["table-row"] === "number" && typeof line.attributes["table-col"] === "number";
3055
3146
  }
3056
- function collectTableLines(lines, startIndex) {
3057
- const result = [];
3058
- for (let i = startIndex; i < lines.length; i++) {
3059
- const line = lines[i];
3060
- if (!line || !isTableLine(line)) break;
3061
- result.push(line);
3062
- }
3063
- return result;
3064
- }
3065
3147
  function renderTable(tableLines, embedRenderers, pretty, blockHandlers, options) {
3066
3148
  const rows = /* @__PURE__ */ new Map();
3067
3149
  for (const line of tableLines) {
@@ -3332,7 +3414,7 @@ function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
3332
3414
  function extractPlainText(ops) {
3333
3415
  let text = "";
3334
3416
  for (const op of ops) {
3335
- if (isInsert2(op) && typeof op.insert === "string") {
3417
+ if (isInsert3(op) && typeof op.insert === "string") {
3336
3418
  text += op.insert;
3337
3419
  }
3338
3420
  }
@@ -3341,7 +3423,7 @@ function extractPlainText(ops) {
3341
3423
  function renderLineContent(ops, embedRenderers, blockHandlers, options) {
3342
3424
  let html = "";
3343
3425
  for (const op of ops) {
3344
- if (!isInsert2(op)) continue;
3426
+ if (!isInsert3(op)) continue;
3345
3427
  if (isEmbedInsert2(op)) {
3346
3428
  html += renderEmbed(
3347
3429
  op.insert,
@@ -4139,7 +4221,7 @@ var DEFAULT_TAG_HANDLERS = {
4139
4221
  };
4140
4222
 
4141
4223
  // src/conversion/markdown/delta-to-markdown.ts
4142
- import { Delta as Delta9, isInsert as isInsert3, isTextInsert as isTextInsert2, isEmbedInsert as isEmbedInsert3 } from "@scrider/delta";
4224
+ import { Delta as Delta9, isInsert as isInsert4, isTextInsert as isTextInsert3, isEmbedInsert as isEmbedInsert3 } from "@scrider/delta";
4143
4225
 
4144
4226
  // src/conversion/markdown/config.ts
4145
4227
  var MARKDOWN_ESCAPE_CHARS = /[\\`*_[\]<>#]/g;
@@ -4227,7 +4309,7 @@ function deltaToMarkdown(delta, options = {}) {
4227
4309
  const attrs = line.attributes;
4228
4310
  const isBlockquote = !!attrs.blockquote;
4229
4311
  if (typeof attrs["table-row"] === "number" && typeof attrs["table-col"] === "number") {
4230
- const tableLines = collectTableLines2(lines, i);
4312
+ const tableLines = collectAdjacentTableLines(lines, i);
4231
4313
  result.push(
4232
4314
  renderMarkdownTable(tableLines, embedRenderers, useLatexDelimiters, registry, softBreakStyle)
4233
4315
  );
@@ -4332,9 +4414,9 @@ function splitIntoLines2(ops) {
4332
4414
  const lines = [];
4333
4415
  let currentOps = [];
4334
4416
  for (const op of ops) {
4335
- if (!isInsert3(op)) continue;
4417
+ if (!isInsert4(op)) continue;
4336
4418
  const opAttrs = op.attributes ?? {};
4337
- if (isTextInsert2(op)) {
4419
+ if (isTextInsert3(op)) {
4338
4420
  const text = op.insert;
4339
4421
  const parts = text.split("\n");
4340
4422
  for (let i = 0; i < parts.length; i++) {
@@ -4399,17 +4481,6 @@ function collectCodeBlock(lines, startIndex) {
4399
4481
  }
4400
4482
  return codeLines;
4401
4483
  }
4402
- function collectTableLines2(lines, startIndex) {
4403
- const result = [];
4404
- for (let i = startIndex; i < lines.length; i++) {
4405
- const line = lines[i];
4406
- if (!line || typeof line.attributes["table-row"] !== "number" || typeof line.attributes["table-col"] !== "number") {
4407
- break;
4408
- }
4409
- result.push(line);
4410
- }
4411
- return result;
4412
- }
4413
4484
  function renderMarkdownTable(tableLines, embedRenderers, useLatexDelimiters = false, registry, softBreakStyle = "spaces") {
4414
4485
  const rows = /* @__PURE__ */ new Map();
4415
4486
  for (const line of tableLines) {
@@ -4545,7 +4616,7 @@ function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters
4545
4616
  let result = "";
4546
4617
  for (const op of ops) {
4547
4618
  const attrs = op.attributes;
4548
- if (isTextInsert2(op)) {
4619
+ if (isTextInsert3(op)) {
4549
4620
  const text = op.insert;
4550
4621
  if (inCodeBlock) {
4551
4622
  result += text;
@@ -4774,12 +4845,12 @@ function renderBlockFormat(content, attributes, orderedIndex, _strict) {
4774
4845
  }
4775
4846
 
4776
4847
  // src/conversion/markdown/markdown-to-delta.ts
4777
- import { Delta as Delta10, isInsert as isInsert5 } from "@scrider/delta";
4848
+ import { Delta as Delta10, isInsert as isInsert6 } from "@scrider/delta";
4778
4849
 
4779
4850
  // src/conversion/markdown/table-header-normalize.ts
4780
- import { isInsert as isInsert4 } from "@scrider/delta";
4851
+ import { isInsert as isInsert5 } from "@scrider/delta";
4781
4852
  function isTableCellTerminator(op) {
4782
- return isInsert4(op) && typeof op.insert === "string" && op.insert === "\n" && op.attributes !== void 0 && typeof op.attributes["table-row"] === "number";
4853
+ return isInsert5(op) && typeof op.insert === "string" && op.insert === "\n" && op.attributes !== void 0 && typeof op.attributes["table-row"] === "number";
4783
4854
  }
4784
4855
  function normalizeSyntheticEmptyHeaderRow(ops) {
4785
4856
  const ends = [];
@@ -4788,7 +4859,7 @@ function normalizeSyntheticEmptyHeaderRow(ops) {
4788
4859
  let currentTextOps = [];
4789
4860
  for (let i = 0; i < ops.length; i++) {
4790
4861
  const op = ops[i];
4791
- if (!isInsert4(op)) continue;
4862
+ if (!isInsert5(op)) continue;
4792
4863
  if (typeof op.insert === "string" && op.insert !== "\n") {
4793
4864
  buf += op.insert;
4794
4865
  currentTextOps.push(i);
@@ -4839,7 +4910,7 @@ function normalizeHeaderDashPlaceholders(ops) {
4839
4910
  let currentTextOps = [];
4840
4911
  for (let i = 0; i < ops.length; i++) {
4841
4912
  const op = ops[i];
4842
- if (!isInsert4(op)) continue;
4913
+ if (!isInsert5(op)) continue;
4843
4914
  if (typeof op.insert === "string" && op.insert !== "\n") {
4844
4915
  buf += op.insert;
4845
4916
  currentTextOps.push(i);
@@ -4868,7 +4939,7 @@ function normalizeHeaderDashPlaceholders(ops) {
4868
4939
  out.push(op);
4869
4940
  continue;
4870
4941
  }
4871
- if (!isInsert4(op)) {
4942
+ if (!isInsert5(op)) {
4872
4943
  out.push(op);
4873
4944
  continue;
4874
4945
  }
@@ -4889,7 +4960,7 @@ function normalizeImportedTableOps(ops) {
4889
4960
  const ends = [];
4890
4961
  let buf = "";
4891
4962
  for (const op of ops) {
4892
- if (!isInsert4(op)) continue;
4963
+ if (!isInsert5(op)) continue;
4893
4964
  if (typeof op.insert === "string" && op.insert !== "\n") {
4894
4965
  buf += op.insert;
4895
4966
  continue;
@@ -5425,7 +5496,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
5425
5496
  }
5426
5497
  const tableOps = delta.ops.splice(tableStart);
5427
5498
  for (const op of normalizeImportedTableOps(tableOps)) {
5428
- if (!isInsert5(op)) continue;
5499
+ if (!isInsert6(op)) continue;
5429
5500
  if (op.attributes && Object.keys(op.attributes).length > 0) {
5430
5501
  delta.insert(op.insert, op.attributes);
5431
5502
  } else {
@@ -5611,54 +5682,6 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
5611
5682
  }
5612
5683
  return delta;
5613
5684
  }
5614
-
5615
- // src/conversion/markdown/table-region.ts
5616
- import { isInsert as isInsert6, isTextInsert as isTextInsert3 } from "@scrider/delta";
5617
- function isTableNewlineOp(op) {
5618
- if (!op || !isInsert6(op) || !isTextInsert3(op)) return false;
5619
- if (!op.insert.includes("\n")) return false;
5620
- return !!op.attributes && "table-row" in op.attributes;
5621
- }
5622
- function extractTableRegion(ops, hintOpIdx) {
5623
- if (hintOpIdx < 0 || hintOpIdx >= ops.length) return null;
5624
- let probeIdx = -1;
5625
- for (let i = hintOpIdx; i < ops.length; i++) {
5626
- const op = ops[i];
5627
- if (!op || !isInsert6(op)) continue;
5628
- if (isTextInsert3(op) && op.insert.includes("\n")) {
5629
- probeIdx = i;
5630
- break;
5631
- }
5632
- }
5633
- if (probeIdx < 0) return null;
5634
- if (!isTableNewlineOp(ops[probeIdx])) return null;
5635
- let endOpIdx = probeIdx;
5636
- for (let i = probeIdx + 1; i < ops.length; i++) {
5637
- const op = ops[i];
5638
- if (!op || !isInsert6(op)) break;
5639
- if (isTextInsert3(op) && op.insert.includes("\n")) {
5640
- if (isTableNewlineOp(op)) {
5641
- endOpIdx = i;
5642
- } else {
5643
- break;
5644
- }
5645
- }
5646
- }
5647
- let startOpIdx = 0;
5648
- for (let i = probeIdx - 1; i >= 0; i--) {
5649
- const op = ops[i];
5650
- if (!op || !isInsert6(op)) {
5651
- startOpIdx = i + 1;
5652
- break;
5653
- }
5654
- if (isTextInsert3(op) && op.insert.includes("\n") && !isTableNewlineOp(op)) {
5655
- startOpIdx = i + 1;
5656
- break;
5657
- }
5658
- }
5659
- const regionOps = ops.slice(startOpIdx, endOpIdx + 1);
5660
- return { startOpIdx, endOpIdx, ops: regionOps };
5661
- }
5662
5685
  export {
5663
5686
  ALERT_TYPES,
5664
5687
  BOX_FLOAT_VALUES,
@@ -5690,6 +5713,7 @@ export {
5690
5713
  codeBlockFormat,
5691
5714
  codeFormat,
5692
5715
  codeWidgetFormat,
5716
+ collectAdjacentTableLines,
5693
5717
  colorFormat,
5694
5718
  columnsBlockHandler,
5695
5719
  createDefaultBlockHandlers,
@@ -5717,6 +5741,7 @@ export {
5717
5741
  imageFormat,
5718
5742
  indentFormat,
5719
5743
  isAdapterAvailable,
5744
+ isAdjacentSimpleTableGridBoundary,
5720
5745
  isElement,
5721
5746
  isRemarkAvailable,
5722
5747
  isTableNewlineOp,
@@ -5749,6 +5774,8 @@ export {
5749
5774
  subscriptFormat,
5750
5775
  superscriptFormat,
5751
5776
  tableBlockHandler,
5777
+ tableCellCoordsFromAttributes,
5778
+ tableCellCoordsFromOp,
5752
5779
  tableColAlignFormat,
5753
5780
  tableColFormat,
5754
5781
  tableHeaderFormat,