@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.cjs +127 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -3
- package/dist/index.d.ts +27 -3
- package/dist/index.js +113 -86
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -2778,7 +2782,7 @@ function isAdapterAvailable() {
|
|
|
2778
2782
|
}
|
|
2779
2783
|
|
|
2780
2784
|
// src/conversion/html/delta-to-html.ts
|
|
2781
|
-
var
|
|
2785
|
+
var import_delta8 = require("@scrider/delta");
|
|
2782
2786
|
|
|
2783
2787
|
// src/conversion/utils/slugify.ts
|
|
2784
2788
|
function slugify(text) {
|
|
@@ -3001,6 +3005,97 @@ function buildTableCellStyleAttr(params) {
|
|
|
3001
3005
|
return ` style="${parts.join("; ")}"`;
|
|
3002
3006
|
}
|
|
3003
3007
|
|
|
3008
|
+
// src/conversion/markdown/table-region.ts
|
|
3009
|
+
var import_delta7 = require("@scrider/delta");
|
|
3010
|
+
function isTableNewlineOp(op) {
|
|
3011
|
+
if (!op || !(0, import_delta7.isInsert)(op) || !(0, import_delta7.isTextInsert)(op)) return false;
|
|
3012
|
+
if (!op.insert.includes("\n")) return false;
|
|
3013
|
+
return !!op.attributes && "table-row" in op.attributes;
|
|
3014
|
+
}
|
|
3015
|
+
function tableCellCoordsFromAttributes(attrs) {
|
|
3016
|
+
if (!attrs || typeof attrs["table-row"] !== "number" || typeof attrs["table-col"] !== "number") {
|
|
3017
|
+
return null;
|
|
3018
|
+
}
|
|
3019
|
+
return { row: attrs["table-row"], col: attrs["table-col"] };
|
|
3020
|
+
}
|
|
3021
|
+
function tableCellCoordsFromOp(op) {
|
|
3022
|
+
if (!isTableNewlineOp(op) || !(0, import_delta7.isTextInsert)(op)) return null;
|
|
3023
|
+
return tableCellCoordsFromAttributes(op.attributes);
|
|
3024
|
+
}
|
|
3025
|
+
function isAdjacentSimpleTableGridBoundary(prev, next) {
|
|
3026
|
+
if (next.row < prev.row) return true;
|
|
3027
|
+
if (next.row === 0 && prev.row === 0 && next.col === 0 && prev.col > 0) return true;
|
|
3028
|
+
return false;
|
|
3029
|
+
}
|
|
3030
|
+
function collectAdjacentTableLines(lines, startIndex) {
|
|
3031
|
+
const result = [];
|
|
3032
|
+
let prevCoords = null;
|
|
3033
|
+
for (let i = startIndex; i < lines.length; i++) {
|
|
3034
|
+
const line = lines[i];
|
|
3035
|
+
if (line === void 0) break;
|
|
3036
|
+
const coords = tableCellCoordsFromAttributes(line.attributes);
|
|
3037
|
+
if (!coords) break;
|
|
3038
|
+
if (prevCoords && isAdjacentSimpleTableGridBoundary(prevCoords, coords)) break;
|
|
3039
|
+
result.push(line);
|
|
3040
|
+
prevCoords = coords;
|
|
3041
|
+
}
|
|
3042
|
+
return result;
|
|
3043
|
+
}
|
|
3044
|
+
function extractTableRegion(ops, hintOpIdx) {
|
|
3045
|
+
if (hintOpIdx < 0 || hintOpIdx >= ops.length) return null;
|
|
3046
|
+
let probeIdx = -1;
|
|
3047
|
+
for (let i = hintOpIdx; i < ops.length; i++) {
|
|
3048
|
+
const op = ops[i];
|
|
3049
|
+
if (!op || !(0, import_delta7.isInsert)(op)) continue;
|
|
3050
|
+
if ((0, import_delta7.isTextInsert)(op) && op.insert.includes("\n")) {
|
|
3051
|
+
probeIdx = i;
|
|
3052
|
+
break;
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
if (probeIdx < 0) return null;
|
|
3056
|
+
if (!isTableNewlineOp(ops[probeIdx])) return null;
|
|
3057
|
+
const probeCoords = tableCellCoordsFromOp(ops[probeIdx]);
|
|
3058
|
+
if (!probeCoords) return null;
|
|
3059
|
+
let endOpIdx = probeIdx;
|
|
3060
|
+
let prevCoords = probeCoords;
|
|
3061
|
+
for (let i = probeIdx + 1; i < ops.length; i++) {
|
|
3062
|
+
const op = ops[i];
|
|
3063
|
+
if (!op || !(0, import_delta7.isInsert)(op)) break;
|
|
3064
|
+
if (!(0, import_delta7.isTextInsert)(op) || !op.insert.includes("\n")) continue;
|
|
3065
|
+
if (isTableNewlineOp(op)) {
|
|
3066
|
+
const coords = tableCellCoordsFromOp(op);
|
|
3067
|
+
if (isAdjacentSimpleTableGridBoundary(prevCoords, coords)) break;
|
|
3068
|
+
prevCoords = coords;
|
|
3069
|
+
endOpIdx = i;
|
|
3070
|
+
} else {
|
|
3071
|
+
break;
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
let startOpIdx = 0;
|
|
3075
|
+
let nextCoords = probeCoords;
|
|
3076
|
+
for (let i = probeIdx - 1; i >= 0; i--) {
|
|
3077
|
+
const op = ops[i];
|
|
3078
|
+
if (!op || !(0, import_delta7.isInsert)(op)) {
|
|
3079
|
+
startOpIdx = i + 1;
|
|
3080
|
+
break;
|
|
3081
|
+
}
|
|
3082
|
+
if (!(0, import_delta7.isTextInsert)(op) || !op.insert.includes("\n")) continue;
|
|
3083
|
+
if (isTableNewlineOp(op)) {
|
|
3084
|
+
const coords = tableCellCoordsFromOp(op);
|
|
3085
|
+
if (isAdjacentSimpleTableGridBoundary(coords, nextCoords)) {
|
|
3086
|
+
startOpIdx = i + 1;
|
|
3087
|
+
break;
|
|
3088
|
+
}
|
|
3089
|
+
nextCoords = coords;
|
|
3090
|
+
} else {
|
|
3091
|
+
startOpIdx = i + 1;
|
|
3092
|
+
break;
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
const regionOps = ops.slice(startOpIdx, endOpIdx + 1);
|
|
3096
|
+
return { startOpIdx, endOpIdx, ops: regionOps };
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3004
3099
|
// src/conversion/html/delta-to-html.ts
|
|
3005
3100
|
function deltaToHtml(delta, options = {}) {
|
|
3006
3101
|
const lines = splitIntoLines(delta);
|
|
@@ -3021,7 +3116,7 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3021
3116
|
html += closeAllLists(listStack, pretty);
|
|
3022
3117
|
listStack = [];
|
|
3023
3118
|
counters = [];
|
|
3024
|
-
const tableLines =
|
|
3119
|
+
const tableLines = collectAdjacentTableLines(lines, i);
|
|
3025
3120
|
html += renderTable(tableLines, embedRenderers, pretty, blockHandlers, options);
|
|
3026
3121
|
i += tableLines.length - 1;
|
|
3027
3122
|
continue;
|
|
@@ -3130,8 +3225,8 @@ function splitIntoLines(delta) {
|
|
|
3130
3225
|
const lines = [];
|
|
3131
3226
|
let currentOps = [];
|
|
3132
3227
|
for (const op of delta.ops) {
|
|
3133
|
-
if (!(0,
|
|
3134
|
-
if ((0,
|
|
3228
|
+
if (!(0, import_delta8.isInsert)(op)) continue;
|
|
3229
|
+
if ((0, import_delta8.isEmbedInsert)(op)) {
|
|
3135
3230
|
currentOps.push(op);
|
|
3136
3231
|
continue;
|
|
3137
3232
|
}
|
|
@@ -3168,7 +3263,7 @@ var BLOCK_LEVEL_EMBEDS = /* @__PURE__ */ new Set(["divider", "block"]);
|
|
|
3168
3263
|
function isBlockLevelEmbedLine(line) {
|
|
3169
3264
|
if (line.ops.length !== 1) return false;
|
|
3170
3265
|
const op = line.ops[0];
|
|
3171
|
-
if (!op || !(0,
|
|
3266
|
+
if (!op || !(0, import_delta8.isEmbedInsert)(op)) return false;
|
|
3172
3267
|
const embed = op.insert;
|
|
3173
3268
|
const embedType = Object.keys(embed)[0];
|
|
3174
3269
|
if (!!embedType && BLOCK_LEVEL_EMBEDS.has(embedType)) return true;
|
|
@@ -3179,15 +3274,6 @@ function isBlockLevelEmbedLine(line) {
|
|
|
3179
3274
|
function isTableLine(line) {
|
|
3180
3275
|
return line.attributes != null && typeof line.attributes["table-row"] === "number" && typeof line.attributes["table-col"] === "number";
|
|
3181
3276
|
}
|
|
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
3277
|
function renderTable(tableLines, embedRenderers, pretty, blockHandlers, options) {
|
|
3192
3278
|
const rows = /* @__PURE__ */ new Map();
|
|
3193
3279
|
for (const line of tableLines) {
|
|
@@ -3458,7 +3544,7 @@ function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
|
|
|
3458
3544
|
function extractPlainText(ops) {
|
|
3459
3545
|
let text = "";
|
|
3460
3546
|
for (const op of ops) {
|
|
3461
|
-
if ((0,
|
|
3547
|
+
if ((0, import_delta8.isInsert)(op) && typeof op.insert === "string") {
|
|
3462
3548
|
text += op.insert;
|
|
3463
3549
|
}
|
|
3464
3550
|
}
|
|
@@ -3467,8 +3553,8 @@ function extractPlainText(ops) {
|
|
|
3467
3553
|
function renderLineContent(ops, embedRenderers, blockHandlers, options) {
|
|
3468
3554
|
let html = "";
|
|
3469
3555
|
for (const op of ops) {
|
|
3470
|
-
if (!(0,
|
|
3471
|
-
if ((0,
|
|
3556
|
+
if (!(0, import_delta8.isInsert)(op)) continue;
|
|
3557
|
+
if ((0, import_delta8.isEmbedInsert)(op)) {
|
|
3472
3558
|
html += renderEmbed(
|
|
3473
3559
|
op.insert,
|
|
3474
3560
|
op.attributes,
|
|
@@ -3524,7 +3610,7 @@ function renderEmbed(value, attributes, renderers, blockHandlers, options) {
|
|
|
3524
3610
|
const context = {
|
|
3525
3611
|
registry: null,
|
|
3526
3612
|
options: { pretty: options?.pretty ?? false },
|
|
3527
|
-
renderDelta: (ops) => deltaToHtml(new
|
|
3613
|
+
renderDelta: (ops) => deltaToHtml(new import_delta8.Delta(ops), options ?? {}),
|
|
3528
3614
|
...attributes ? { opAttributes: attributes } : {}
|
|
3529
3615
|
};
|
|
3530
3616
|
return handler.toHtml(blockData, context);
|
|
@@ -3549,13 +3635,13 @@ function renderEmbed(value, attributes, renderers, blockHandlers, options) {
|
|
|
3549
3635
|
}
|
|
3550
3636
|
|
|
3551
3637
|
// src/conversion/html/html-to-delta.ts
|
|
3552
|
-
var
|
|
3638
|
+
var import_delta9 = require("@scrider/delta");
|
|
3553
3639
|
function htmlToDelta(html, options = {}) {
|
|
3554
3640
|
const adapter = options.adapter ?? getAdapter();
|
|
3555
3641
|
const normalizeWhitespace = options.normalizeWhitespace ?? true;
|
|
3556
3642
|
const tagHandlers = { ...DEFAULT_TAG_HANDLERS, ...options.tagHandlers };
|
|
3557
3643
|
const fragment = adapter.parseHTML(html);
|
|
3558
|
-
const delta = new
|
|
3644
|
+
const delta = new import_delta9.Delta();
|
|
3559
3645
|
let currentAttributes = {};
|
|
3560
3646
|
let currentBlockAttributes = {};
|
|
3561
3647
|
let pendingText = "";
|
|
@@ -4265,7 +4351,7 @@ var DEFAULT_TAG_HANDLERS = {
|
|
|
4265
4351
|
};
|
|
4266
4352
|
|
|
4267
4353
|
// src/conversion/markdown/delta-to-markdown.ts
|
|
4268
|
-
var
|
|
4354
|
+
var import_delta10 = require("@scrider/delta");
|
|
4269
4355
|
|
|
4270
4356
|
// src/conversion/markdown/config.ts
|
|
4271
4357
|
var MARKDOWN_ESCAPE_CHARS = /[\\`*_[\]<>#]/g;
|
|
@@ -4353,7 +4439,7 @@ function deltaToMarkdown(delta, options = {}) {
|
|
|
4353
4439
|
const attrs = line.attributes;
|
|
4354
4440
|
const isBlockquote = !!attrs.blockquote;
|
|
4355
4441
|
if (typeof attrs["table-row"] === "number" && typeof attrs["table-col"] === "number") {
|
|
4356
|
-
const tableLines =
|
|
4442
|
+
const tableLines = collectAdjacentTableLines(lines, i);
|
|
4357
4443
|
result.push(
|
|
4358
4444
|
renderMarkdownTable(tableLines, embedRenderers, useLatexDelimiters, registry, softBreakStyle)
|
|
4359
4445
|
);
|
|
@@ -4458,9 +4544,9 @@ function splitIntoLines2(ops) {
|
|
|
4458
4544
|
const lines = [];
|
|
4459
4545
|
let currentOps = [];
|
|
4460
4546
|
for (const op of ops) {
|
|
4461
|
-
if (!(0,
|
|
4547
|
+
if (!(0, import_delta10.isInsert)(op)) continue;
|
|
4462
4548
|
const opAttrs = op.attributes ?? {};
|
|
4463
|
-
if ((0,
|
|
4549
|
+
if ((0, import_delta10.isTextInsert)(op)) {
|
|
4464
4550
|
const text = op.insert;
|
|
4465
4551
|
const parts = text.split("\n");
|
|
4466
4552
|
for (let i = 0; i < parts.length; i++) {
|
|
@@ -4525,17 +4611,6 @@ function collectCodeBlock(lines, startIndex) {
|
|
|
4525
4611
|
}
|
|
4526
4612
|
return codeLines;
|
|
4527
4613
|
}
|
|
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
4614
|
function renderMarkdownTable(tableLines, embedRenderers, useLatexDelimiters = false, registry, softBreakStyle = "spaces") {
|
|
4540
4615
|
const rows = /* @__PURE__ */ new Map();
|
|
4541
4616
|
for (const line of tableLines) {
|
|
@@ -4671,14 +4746,14 @@ function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters
|
|
|
4671
4746
|
let result = "";
|
|
4672
4747
|
for (const op of ops) {
|
|
4673
4748
|
const attrs = op.attributes;
|
|
4674
|
-
if ((0,
|
|
4749
|
+
if ((0, import_delta10.isTextInsert)(op)) {
|
|
4675
4750
|
const text = op.insert;
|
|
4676
4751
|
if (inCodeBlock) {
|
|
4677
4752
|
result += text;
|
|
4678
4753
|
} else {
|
|
4679
4754
|
result += renderInlineText2(text, attrs);
|
|
4680
4755
|
}
|
|
4681
|
-
} else if ((0,
|
|
4756
|
+
} else if ((0, import_delta10.isEmbedInsert)(op)) {
|
|
4682
4757
|
const embed = op.insert;
|
|
4683
4758
|
result += renderEmbed2(
|
|
4684
4759
|
embed,
|
|
@@ -4743,7 +4818,7 @@ function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = f
|
|
|
4743
4818
|
if (handler.toMarkdown) {
|
|
4744
4819
|
const mdContext = {
|
|
4745
4820
|
registry: void 0,
|
|
4746
|
-
renderDelta: (ops) => deltaToMarkdown(new
|
|
4821
|
+
renderDelta: (ops) => deltaToMarkdown(new import_delta10.Delta(ops), { blockHandlers }),
|
|
4747
4822
|
...opAttrs
|
|
4748
4823
|
};
|
|
4749
4824
|
const md = handler.toMarkdown(blockData, mdContext);
|
|
@@ -4752,7 +4827,7 @@ function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = f
|
|
|
4752
4827
|
const htmlContext = {
|
|
4753
4828
|
registry: void 0,
|
|
4754
4829
|
...prettyHtml ? { options: { pretty: true } } : {},
|
|
4755
|
-
renderDelta: (ops) => deltaToHtml(new
|
|
4830
|
+
renderDelta: (ops) => deltaToHtml(new import_delta10.Delta(ops), { blockHandlers, pretty: prettyHtml }),
|
|
4756
4831
|
...opAttrs
|
|
4757
4832
|
};
|
|
4758
4833
|
return "\n" + handler.toHtml(blockData, htmlContext) + "\n";
|
|
@@ -4900,12 +4975,12 @@ function renderBlockFormat(content, attributes, orderedIndex, _strict) {
|
|
|
4900
4975
|
}
|
|
4901
4976
|
|
|
4902
4977
|
// src/conversion/markdown/markdown-to-delta.ts
|
|
4903
|
-
var
|
|
4978
|
+
var import_delta12 = require("@scrider/delta");
|
|
4904
4979
|
|
|
4905
4980
|
// src/conversion/markdown/table-header-normalize.ts
|
|
4906
|
-
var
|
|
4981
|
+
var import_delta11 = require("@scrider/delta");
|
|
4907
4982
|
function isTableCellTerminator(op) {
|
|
4908
|
-
return (0,
|
|
4983
|
+
return (0, import_delta11.isInsert)(op) && typeof op.insert === "string" && op.insert === "\n" && op.attributes !== void 0 && typeof op.attributes["table-row"] === "number";
|
|
4909
4984
|
}
|
|
4910
4985
|
function normalizeSyntheticEmptyHeaderRow(ops) {
|
|
4911
4986
|
const ends = [];
|
|
@@ -4914,7 +4989,7 @@ function normalizeSyntheticEmptyHeaderRow(ops) {
|
|
|
4914
4989
|
let currentTextOps = [];
|
|
4915
4990
|
for (let i = 0; i < ops.length; i++) {
|
|
4916
4991
|
const op = ops[i];
|
|
4917
|
-
if (!(0,
|
|
4992
|
+
if (!(0, import_delta11.isInsert)(op)) continue;
|
|
4918
4993
|
if (typeof op.insert === "string" && op.insert !== "\n") {
|
|
4919
4994
|
buf += op.insert;
|
|
4920
4995
|
currentTextOps.push(i);
|
|
@@ -4965,7 +5040,7 @@ function normalizeHeaderDashPlaceholders(ops) {
|
|
|
4965
5040
|
let currentTextOps = [];
|
|
4966
5041
|
for (let i = 0; i < ops.length; i++) {
|
|
4967
5042
|
const op = ops[i];
|
|
4968
|
-
if (!(0,
|
|
5043
|
+
if (!(0, import_delta11.isInsert)(op)) continue;
|
|
4969
5044
|
if (typeof op.insert === "string" && op.insert !== "\n") {
|
|
4970
5045
|
buf += op.insert;
|
|
4971
5046
|
currentTextOps.push(i);
|
|
@@ -4994,7 +5069,7 @@ function normalizeHeaderDashPlaceholders(ops) {
|
|
|
4994
5069
|
out.push(op);
|
|
4995
5070
|
continue;
|
|
4996
5071
|
}
|
|
4997
|
-
if (!(0,
|
|
5072
|
+
if (!(0, import_delta11.isInsert)(op)) {
|
|
4998
5073
|
out.push(op);
|
|
4999
5074
|
continue;
|
|
5000
5075
|
}
|
|
@@ -5015,7 +5090,7 @@ function normalizeImportedTableOps(ops) {
|
|
|
5015
5090
|
const ends = [];
|
|
5016
5091
|
let buf = "";
|
|
5017
5092
|
for (const op of ops) {
|
|
5018
|
-
if (!(0,
|
|
5093
|
+
if (!(0, import_delta11.isInsert)(op)) continue;
|
|
5019
5094
|
if (typeof op.insert === "string" && op.insert !== "\n") {
|
|
5020
5095
|
buf += op.insert;
|
|
5021
5096
|
continue;
|
|
@@ -5168,7 +5243,7 @@ function markdownToDeltaSync(markdown, options = {}) {
|
|
|
5168
5243
|
);
|
|
5169
5244
|
}
|
|
5170
5245
|
function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock, blockHandlers) {
|
|
5171
|
-
const delta = new
|
|
5246
|
+
const delta = new import_delta12.Delta();
|
|
5172
5247
|
let currentInlineAttrs = {};
|
|
5173
5248
|
let pendingText = "";
|
|
5174
5249
|
const spanAttrStack = [];
|
|
@@ -5551,7 +5626,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
5551
5626
|
}
|
|
5552
5627
|
const tableOps = delta.ops.splice(tableStart);
|
|
5553
5628
|
for (const op of normalizeImportedTableOps(tableOps)) {
|
|
5554
|
-
if (!(0,
|
|
5629
|
+
if (!(0, import_delta12.isInsert)(op)) continue;
|
|
5555
5630
|
if (op.attributes && Object.keys(op.attributes).length > 0) {
|
|
5556
5631
|
delta.insert(op.insert, op.attributes);
|
|
5557
5632
|
} else {
|
|
@@ -5737,54 +5812,6 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
5737
5812
|
}
|
|
5738
5813
|
return delta;
|
|
5739
5814
|
}
|
|
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
5815
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5789
5816
|
0 && (module.exports = {
|
|
5790
5817
|
ALERT_TYPES,
|
|
@@ -5817,6 +5844,7 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5817
5844
|
codeBlockFormat,
|
|
5818
5845
|
codeFormat,
|
|
5819
5846
|
codeWidgetFormat,
|
|
5847
|
+
collectAdjacentTableLines,
|
|
5820
5848
|
colorFormat,
|
|
5821
5849
|
columnsBlockHandler,
|
|
5822
5850
|
createDefaultBlockHandlers,
|
|
@@ -5844,6 +5872,7 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5844
5872
|
imageFormat,
|
|
5845
5873
|
indentFormat,
|
|
5846
5874
|
isAdapterAvailable,
|
|
5875
|
+
isAdjacentSimpleTableGridBoundary,
|
|
5847
5876
|
isElement,
|
|
5848
5877
|
isRemarkAvailable,
|
|
5849
5878
|
isTableNewlineOp,
|
|
@@ -5876,6 +5905,8 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5876
5905
|
subscriptFormat,
|
|
5877
5906
|
superscriptFormat,
|
|
5878
5907
|
tableBlockHandler,
|
|
5908
|
+
tableCellCoordsFromAttributes,
|
|
5909
|
+
tableCellCoordsFromOp,
|
|
5879
5910
|
tableColAlignFormat,
|
|
5880
5911
|
tableColFormat,
|
|
5881
5912
|
tableHeaderFormat,
|