markdown-codec 6.7.5 → 7.0.0

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/README.md CHANGED
@@ -280,6 +280,16 @@ This package also published under an alternate name from the pre-monorepo pipeli
280
280
 
281
281
  **Republished automatically** — the alias's trusted publisher is registered against this repository and workflow (2026-09-10), so every release from the [backfill run](https://github.com/ExaDev/documents.js/actions/runs/34449796133) onward publishes under this name too; the registration evidence is on [ExaDev/documents.js#728](https://github.com/ExaDev/documents.js/issues/728).
282
282
 
283
+ ## Removed: base64 from `markdown-codec/image/image`
284
+
285
+ `markdown-codec/image/image` still exists and still reads PNG/JPEG dimensions, but it no longer exports `bytesToBase64` or `base64ToBytes`. Those were this package's own copy of helpers every codec carried separately, and they live in [`byte-codec`](../byte-codec/README.md) now, as one implementation ([ExaDev/documents.js#1282](https://github.com/ExaDev/documents.js/issues/1282)).
286
+
287
+ Import from `byte-codec` directly:
288
+
289
+ ```ts
290
+ import { base64ToBytes, bytesToBase64 } from "byte-codec";
291
+ ```
292
+
283
293
  ## License
284
294
 
285
295
  MIT
@@ -15,14 +15,13 @@ const require_block_table = require("./table.cjs");
15
15
  const TASK_LIST_MARKER_PATTERN = /^\[([ xX])\][ \t]/;
16
16
  const NUL_REPLACEMENT = "�";
17
17
  const NUL_PATTERN = /\0/g;
18
- const MAYBE_SPECIAL_PATTERN = /^[#$`~*+_=<>[0-9|:-]/;
19
18
  const ATX_MARKER_PATTERN = /^#{1,6}(?:[ \t]+|$)/;
20
19
  const ATX_ONLY_CLOSING_SEQUENCE_PATTERN = /^[ \t]*#+[ \t]*$/;
21
20
  const ATX_TRAILING_CLOSING_SEQUENCE_PATTERN = /[ \t]+#+[ \t]*$/;
22
21
  const CODE_FENCE_PATTERN = /^`{3,}(?!.*`)|^~{3,}/;
23
22
  const CLOSING_CODE_FENCE_PATTERN = /^(?:`{3,}|~{3,})(?=[ \t]*$)/;
24
23
  const MATH_BLOCK_MARKER_PATTERN = /^\$\$[ \t]*$/;
25
- const MATH_BLOCK_MARKER_LENGTH = 2;
24
+ const ACCUMULATED_LINE_ENDING = "\n";
26
25
  const SETEXT_UNDERLINE_PATTERN = /^(?:=+|-+)[ \t]*$/;
27
26
  const THEMATIC_BREAK_PATTERN = /^(?:\*[ \t]*){3,}$|^(?:_[ \t]*){3,}$|^(?:-[ \t]*){3,}$/;
28
27
  const BLANK_CONTENT_PATTERN = /^[ \t\n]*$/;
@@ -56,8 +55,7 @@ var BlockParser = class {
56
55
  tip = this.document;
57
56
  oldTip = this.document;
58
57
  lastMatchedContainer = this.document;
59
- allClosed = true;
60
- line = new require_block_line.LineCursor("");
58
+ line;
61
59
  lineNumber = 0;
62
60
  nestingDepth = 0;
63
61
  constructor(options) {
@@ -73,14 +71,14 @@ var BlockParser = class {
73
71
  const text = lines[index];
74
72
  if (text !== void 0) this.incorporateLine(text);
75
73
  }
76
- while (this.tip.open) {
74
+ while (this.tip !== this.document) {
77
75
  this.reportUnterminatedAtEof(this.tip);
78
76
  this.finalize(this.tip);
79
77
  }
80
78
  return this.document;
81
79
  }
82
80
  reportUnterminatedAtEof(node) {
83
- if (node.kind === "codeBlock" && node.fenced) {
81
+ if (node.fenced) {
84
82
  this.sink({
85
83
  code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.UNCLOSED_FENCE,
86
84
  severity: "warning",
@@ -111,7 +109,6 @@ var BlockParser = class {
111
109
  this.oldTip = this.tip;
112
110
  const matched = this.walkOpenBlocks();
113
111
  if (matched === void 0) return;
114
- this.allClosed = matched === this.oldTip;
115
112
  this.lastMatchedContainer = matched;
116
113
  this.addTextToContainer(this.openNewBlocks(matched));
117
114
  }
@@ -122,8 +119,7 @@ var BlockParser = class {
122
119
  if (lastChild?.open !== true) return container;
123
120
  this.line.findNextNonspace();
124
121
  const result = this.continueBlock(lastChild);
125
- if (result === "finished") return;
126
- if (result === "not-matched") return container;
122
+ if (result !== "matched") return result === "finished" ? void 0 : container;
127
123
  container = lastChild;
128
124
  }
129
125
  }
@@ -210,13 +206,9 @@ var BlockParser = class {
210
206
  }
211
207
  openNewBlocks(matchedContainer) {
212
208
  let container = matchedContainer;
213
- let matchedLeaf = container.kind !== "paragraph" && container.kind !== "table" && require_block_node.acceptsLines(container.kind);
209
+ let matchedLeaf = require_block_node.suppressesBlockStarts(container.kind);
214
210
  while (!matchedLeaf) {
215
211
  this.line.findNextNonspace();
216
- if (!this.line.indented && !MAYBE_SPECIAL_PATTERN.test(this.line.restFromNextNonspace())) {
217
- this.line.advanceToNextNonspace();
218
- break;
219
- }
220
212
  const result = this.tryBlockStart(container);
221
213
  if (result === "none") {
222
214
  this.line.advanceToNextNonspace();
@@ -234,7 +226,7 @@ var BlockParser = class {
234
226
  () => this.tryCodeFenceStart(),
235
227
  () => this.tryMathBlockStart(),
236
228
  () => this.tryFootnoteDefinitionStart(container),
237
- () => this.tryHtmlBlockStart(container),
229
+ () => this.tryHtmlBlockStart(),
238
230
  () => this.tryPromoteParagraph(container),
239
231
  () => this.tryThematicBreakStart(),
240
232
  () => this.tryListItemStart(container),
@@ -257,7 +249,6 @@ var BlockParser = class {
257
249
  const rest = this.line.restFromNextNonspace();
258
250
  const match = ATX_MARKER_PATTERN.exec(rest);
259
251
  if (match === null) return "none";
260
- this.line.advanceToNextNonspace();
261
252
  this.closeUnmatchedBlocks();
262
253
  const heading = this.addChild("heading");
263
254
  heading.level = headingLevelOf(match[0].trim().length);
@@ -287,8 +278,7 @@ var BlockParser = class {
287
278
  if (!MATH_BLOCK_MARKER_PATTERN.test(this.line.restFromNextNonspace())) return "none";
288
279
  this.closeUnmatchedBlocks();
289
280
  this.addChild("mathBlock");
290
- this.line.advanceToNextNonspace();
291
- this.line.advance(MATH_BLOCK_MARKER_LENGTH);
281
+ this.line.advanceToEndOfLine();
292
282
  return "leaf";
293
283
  }
294
284
  tryFootnoteDefinitionStart(container) {
@@ -314,9 +304,9 @@ var BlockParser = class {
314
304
  while (node?.kind === "list") node = node.parent;
315
305
  return node?.kind === "document" || node?.kind === "blockquote" || node?.kind === "listItem";
316
306
  }
317
- tryHtmlBlockStart(container) {
318
- if (this.line.indented || this.line.peekNextNonspace() !== "<") return "none";
319
- const interruptsParagraph = container.kind === "paragraph" || !this.allClosed && !this.line.blank && this.tip.kind === "paragraph";
307
+ tryHtmlBlockStart() {
308
+ if (this.line.indented) return "none";
309
+ const interruptsParagraph = this.tip.kind === "paragraph";
320
310
  const type = require_html_html.matchHtmlBlockStart(this.line.restFromNextNonspace(), interruptsParagraph);
321
311
  if (type === void 0) return "none";
322
312
  this.closeUnmatchedBlocks();
@@ -331,7 +321,6 @@ var BlockParser = class {
331
321
  trySetextHeading(paragraph) {
332
322
  const match = SETEXT_UNDERLINE_PATTERN.exec(this.line.restFromNextNonspace());
333
323
  if (match === null) return "none";
334
- this.closeUnmatchedBlocks();
335
324
  paragraph.content = require_block_definitions.extractDefinitions(paragraph.content, this.references, this.sink, paragraph.startLine);
336
325
  if (isBlankContent(paragraph.content)) return "none";
337
326
  const heading = new require_block_node.BlockNode("heading", paragraph.startLine);
@@ -350,9 +339,7 @@ var BlockParser = class {
350
339
  const lines = paragraph.content.split("\n");
351
340
  const headerLine = lines.at(-2);
352
341
  if (headerLine === void 0 || require_block_table.splitTableRow(headerLine).length !== alignments.length) return "none";
353
- this.closeUnmatchedBlocks();
354
342
  paragraph.content = lines.slice(0, -2).map((text) => `${text}\n`).join("");
355
- this.finalize(paragraph);
356
343
  const table = this.addChild("table");
357
344
  table.alignments = alignments;
358
345
  table.headerLine = headerLine;
@@ -383,7 +370,7 @@ var BlockParser = class {
383
370
  return "leaf";
384
371
  }
385
372
  addTextToContainer(container) {
386
- if (!this.allClosed && !this.line.blank && this.tip.kind === "paragraph") {
373
+ if (this.tip.kind === "paragraph" && !this.line.blank) {
387
374
  this.addLine();
388
375
  return;
389
376
  }
@@ -391,23 +378,22 @@ var BlockParser = class {
391
378
  const lastChild = container.lastChild;
392
379
  if (this.line.blank && lastChild !== void 0) lastChild.lastLineBlank = true;
393
380
  this.recordBlankLineForTightness(container);
394
- if (require_block_node.acceptsLines(container.kind)) {
381
+ if (require_block_node.suppressesBlockStarts(container.kind) || container.kind === "table") {
395
382
  this.addLine();
396
383
  if (container.kind === "htmlBlock" && require_html_html.matchesHtmlBlockEnd(this.line.rest(), container.htmlBlockType)) this.finalize(container);
397
384
  return;
398
385
  }
399
386
  if (!this.line.atEnd && !this.line.blank) {
400
387
  this.addChild("paragraph");
401
- this.line.advanceToNextNonspace();
402
388
  this.addLine();
403
389
  }
404
390
  }
405
391
  recordBlankLineForTightness(container) {
406
- const blank = this.line.blank && !(container.kind === "blockquote" || container.kind === "codeBlock" && container.fenced || container.kind === "listItem" && container.children.length === 0 && container.startLine === this.lineNumber);
392
+ const blank = this.line.blank && !(container.kind === "blockquote" || container.fenced || container.kind === "listItem");
407
393
  for (let node = container; node !== void 0; node = node.parent) node.lastLineBlank = blank;
408
394
  }
409
395
  addLine() {
410
- this.tip.content += `${this.line.rest()}\n`;
396
+ this.tip.content += `${this.line.rest()}${ACCUMULATED_LINE_ENDING}`;
411
397
  }
412
398
  addChild(kind) {
413
399
  while (!require_block_node.canContain(this.tip.kind, kind)) this.finalize(this.tip);
@@ -419,20 +405,18 @@ var BlockParser = class {
419
405
  return node;
420
406
  }
421
407
  closeUnmatchedBlocks() {
422
- if (this.allClosed) return;
423
408
  while (this.oldTip !== this.lastMatchedContainer) {
424
409
  const parent = this.oldTip.parent;
425
410
  this.finalize(this.oldTip);
426
411
  if (parent === void 0) break;
427
412
  this.oldTip = parent;
428
413
  }
429
- this.allClosed = true;
430
414
  }
431
415
  finalize(node) {
432
416
  const above = node.parent;
433
417
  node.open = false;
434
418
  this.finalizeContent(node);
435
- if (node !== this.document) this.nestingDepth -= 1;
419
+ this.nestingDepth -= 1;
436
420
  this.tip = above ?? this.document;
437
421
  }
438
422
  finalizeContent(node) {
@@ -453,7 +437,6 @@ var BlockParser = class {
453
437
  case "list":
454
438
  require_block_list.finalizeListTightness(node);
455
439
  return;
456
- default: return;
457
440
  }
458
441
  }
459
442
  finalizeCodeBlock(node) {
@@ -466,8 +449,7 @@ var BlockParser = class {
466
449
  node.literal = node.content.slice(breakIndex + 1);
467
450
  }
468
451
  finalizeMathBlock(node) {
469
- const breakIndex = node.content.indexOf("\n");
470
- node.literal = breakIndex === -1 ? "" : node.content.slice(breakIndex + 1);
452
+ node.literal = node.content.slice(1);
471
453
  }
472
454
  };
473
455
  const BLOCK_EDGE_SPACE_OR_TAB_PATTERN = /^[ \t]+|[ \t]+$/g;
@@ -537,8 +519,8 @@ function toTableNode(node, context) {
537
519
  const sink = context.options.sink ?? require_diagnostics_diagnostics.NOOP_MARKDOWN_DIAGNOSTIC_SINK;
538
520
  const columnCount = node.alignments.length;
539
521
  const rows = [toTableRow(require_block_table.fitRowToColumns(require_block_table.splitTableRow(node.headerLine), columnCount), true, context)];
540
- for (const rowLine of node.content.split("\n")) {
541
- if (rowLine.trim().length === 0) continue;
522
+ for (const rowLine of node.content.split(ACCUMULATED_LINE_ENDING)) {
523
+ if (rowLine.length === 0) continue;
542
524
  const cells = require_block_table.splitTableRow(rowLine);
543
525
  if (cells.length !== columnCount) sink({
544
526
  code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.TABLE_CELL_COUNT_MISMATCH,
@@ -8,20 +8,19 @@ import { LINE_ENDING_PATTERN } from "../shared/line-ending.js";
8
8
  import { extractDefinitions } from "./definitions.js";
9
9
  import { LineCursor } from "./line.js";
10
10
  import { finalizeListTightness, listsMatch, parseListMarker } from "./list.js";
11
- import { BlockNode, acceptsLines, canContain } from "./node.js";
11
+ import { BlockNode, canContain, suppressesBlockStarts } from "./node.js";
12
12
  import { fitRowToColumns, parseTableDelimiterRow, splitTableRow } from "./table.js";
13
13
  //#region src/block/block.ts
14
14
  const TASK_LIST_MARKER_PATTERN = /^\[([ xX])\][ \t]/;
15
15
  const NUL_REPLACEMENT = "�";
16
16
  const NUL_PATTERN = /\0/g;
17
- const MAYBE_SPECIAL_PATTERN = /^[#$`~*+_=<>[0-9|:-]/;
18
17
  const ATX_MARKER_PATTERN = /^#{1,6}(?:[ \t]+|$)/;
19
18
  const ATX_ONLY_CLOSING_SEQUENCE_PATTERN = /^[ \t]*#+[ \t]*$/;
20
19
  const ATX_TRAILING_CLOSING_SEQUENCE_PATTERN = /[ \t]+#+[ \t]*$/;
21
20
  const CODE_FENCE_PATTERN = /^`{3,}(?!.*`)|^~{3,}/;
22
21
  const CLOSING_CODE_FENCE_PATTERN = /^(?:`{3,}|~{3,})(?=[ \t]*$)/;
23
22
  const MATH_BLOCK_MARKER_PATTERN = /^\$\$[ \t]*$/;
24
- const MATH_BLOCK_MARKER_LENGTH = 2;
23
+ const ACCUMULATED_LINE_ENDING = "\n";
25
24
  const SETEXT_UNDERLINE_PATTERN = /^(?:=+|-+)[ \t]*$/;
26
25
  const THEMATIC_BREAK_PATTERN = /^(?:\*[ \t]*){3,}$|^(?:_[ \t]*){3,}$|^(?:-[ \t]*){3,}$/;
27
26
  const BLANK_CONTENT_PATTERN = /^[ \t\n]*$/;
@@ -55,8 +54,7 @@ var BlockParser = class {
55
54
  tip = this.document;
56
55
  oldTip = this.document;
57
56
  lastMatchedContainer = this.document;
58
- allClosed = true;
59
- line = new LineCursor("");
57
+ line;
60
58
  lineNumber = 0;
61
59
  nestingDepth = 0;
62
60
  constructor(options) {
@@ -72,14 +70,14 @@ var BlockParser = class {
72
70
  const text = lines[index];
73
71
  if (text !== void 0) this.incorporateLine(text);
74
72
  }
75
- while (this.tip.open) {
73
+ while (this.tip !== this.document) {
76
74
  this.reportUnterminatedAtEof(this.tip);
77
75
  this.finalize(this.tip);
78
76
  }
79
77
  return this.document;
80
78
  }
81
79
  reportUnterminatedAtEof(node) {
82
- if (node.kind === "codeBlock" && node.fenced) {
80
+ if (node.fenced) {
83
81
  this.sink({
84
82
  code: MarkdownDiagnosticCodes.UNCLOSED_FENCE,
85
83
  severity: "warning",
@@ -110,7 +108,6 @@ var BlockParser = class {
110
108
  this.oldTip = this.tip;
111
109
  const matched = this.walkOpenBlocks();
112
110
  if (matched === void 0) return;
113
- this.allClosed = matched === this.oldTip;
114
111
  this.lastMatchedContainer = matched;
115
112
  this.addTextToContainer(this.openNewBlocks(matched));
116
113
  }
@@ -121,8 +118,7 @@ var BlockParser = class {
121
118
  if (lastChild?.open !== true) return container;
122
119
  this.line.findNextNonspace();
123
120
  const result = this.continueBlock(lastChild);
124
- if (result === "finished") return;
125
- if (result === "not-matched") return container;
121
+ if (result !== "matched") return result === "finished" ? void 0 : container;
126
122
  container = lastChild;
127
123
  }
128
124
  }
@@ -209,13 +205,9 @@ var BlockParser = class {
209
205
  }
210
206
  openNewBlocks(matchedContainer) {
211
207
  let container = matchedContainer;
212
- let matchedLeaf = container.kind !== "paragraph" && container.kind !== "table" && acceptsLines(container.kind);
208
+ let matchedLeaf = suppressesBlockStarts(container.kind);
213
209
  while (!matchedLeaf) {
214
210
  this.line.findNextNonspace();
215
- if (!this.line.indented && !MAYBE_SPECIAL_PATTERN.test(this.line.restFromNextNonspace())) {
216
- this.line.advanceToNextNonspace();
217
- break;
218
- }
219
211
  const result = this.tryBlockStart(container);
220
212
  if (result === "none") {
221
213
  this.line.advanceToNextNonspace();
@@ -233,7 +225,7 @@ var BlockParser = class {
233
225
  () => this.tryCodeFenceStart(),
234
226
  () => this.tryMathBlockStart(),
235
227
  () => this.tryFootnoteDefinitionStart(container),
236
- () => this.tryHtmlBlockStart(container),
228
+ () => this.tryHtmlBlockStart(),
237
229
  () => this.tryPromoteParagraph(container),
238
230
  () => this.tryThematicBreakStart(),
239
231
  () => this.tryListItemStart(container),
@@ -256,7 +248,6 @@ var BlockParser = class {
256
248
  const rest = this.line.restFromNextNonspace();
257
249
  const match = ATX_MARKER_PATTERN.exec(rest);
258
250
  if (match === null) return "none";
259
- this.line.advanceToNextNonspace();
260
251
  this.closeUnmatchedBlocks();
261
252
  const heading = this.addChild("heading");
262
253
  heading.level = headingLevelOf(match[0].trim().length);
@@ -286,8 +277,7 @@ var BlockParser = class {
286
277
  if (!MATH_BLOCK_MARKER_PATTERN.test(this.line.restFromNextNonspace())) return "none";
287
278
  this.closeUnmatchedBlocks();
288
279
  this.addChild("mathBlock");
289
- this.line.advanceToNextNonspace();
290
- this.line.advance(MATH_BLOCK_MARKER_LENGTH);
280
+ this.line.advanceToEndOfLine();
291
281
  return "leaf";
292
282
  }
293
283
  tryFootnoteDefinitionStart(container) {
@@ -313,9 +303,9 @@ var BlockParser = class {
313
303
  while (node?.kind === "list") node = node.parent;
314
304
  return node?.kind === "document" || node?.kind === "blockquote" || node?.kind === "listItem";
315
305
  }
316
- tryHtmlBlockStart(container) {
317
- if (this.line.indented || this.line.peekNextNonspace() !== "<") return "none";
318
- const interruptsParagraph = container.kind === "paragraph" || !this.allClosed && !this.line.blank && this.tip.kind === "paragraph";
306
+ tryHtmlBlockStart() {
307
+ if (this.line.indented) return "none";
308
+ const interruptsParagraph = this.tip.kind === "paragraph";
319
309
  const type = matchHtmlBlockStart(this.line.restFromNextNonspace(), interruptsParagraph);
320
310
  if (type === void 0) return "none";
321
311
  this.closeUnmatchedBlocks();
@@ -330,7 +320,6 @@ var BlockParser = class {
330
320
  trySetextHeading(paragraph) {
331
321
  const match = SETEXT_UNDERLINE_PATTERN.exec(this.line.restFromNextNonspace());
332
322
  if (match === null) return "none";
333
- this.closeUnmatchedBlocks();
334
323
  paragraph.content = extractDefinitions(paragraph.content, this.references, this.sink, paragraph.startLine);
335
324
  if (isBlankContent(paragraph.content)) return "none";
336
325
  const heading = new BlockNode("heading", paragraph.startLine);
@@ -349,9 +338,7 @@ var BlockParser = class {
349
338
  const lines = paragraph.content.split("\n");
350
339
  const headerLine = lines.at(-2);
351
340
  if (headerLine === void 0 || splitTableRow(headerLine).length !== alignments.length) return "none";
352
- this.closeUnmatchedBlocks();
353
341
  paragraph.content = lines.slice(0, -2).map((text) => `${text}\n`).join("");
354
- this.finalize(paragraph);
355
342
  const table = this.addChild("table");
356
343
  table.alignments = alignments;
357
344
  table.headerLine = headerLine;
@@ -382,7 +369,7 @@ var BlockParser = class {
382
369
  return "leaf";
383
370
  }
384
371
  addTextToContainer(container) {
385
- if (!this.allClosed && !this.line.blank && this.tip.kind === "paragraph") {
372
+ if (this.tip.kind === "paragraph" && !this.line.blank) {
386
373
  this.addLine();
387
374
  return;
388
375
  }
@@ -390,23 +377,22 @@ var BlockParser = class {
390
377
  const lastChild = container.lastChild;
391
378
  if (this.line.blank && lastChild !== void 0) lastChild.lastLineBlank = true;
392
379
  this.recordBlankLineForTightness(container);
393
- if (acceptsLines(container.kind)) {
380
+ if (suppressesBlockStarts(container.kind) || container.kind === "table") {
394
381
  this.addLine();
395
382
  if (container.kind === "htmlBlock" && matchesHtmlBlockEnd(this.line.rest(), container.htmlBlockType)) this.finalize(container);
396
383
  return;
397
384
  }
398
385
  if (!this.line.atEnd && !this.line.blank) {
399
386
  this.addChild("paragraph");
400
- this.line.advanceToNextNonspace();
401
387
  this.addLine();
402
388
  }
403
389
  }
404
390
  recordBlankLineForTightness(container) {
405
- const blank = this.line.blank && !(container.kind === "blockquote" || container.kind === "codeBlock" && container.fenced || container.kind === "listItem" && container.children.length === 0 && container.startLine === this.lineNumber);
391
+ const blank = this.line.blank && !(container.kind === "blockquote" || container.fenced || container.kind === "listItem");
406
392
  for (let node = container; node !== void 0; node = node.parent) node.lastLineBlank = blank;
407
393
  }
408
394
  addLine() {
409
- this.tip.content += `${this.line.rest()}\n`;
395
+ this.tip.content += `${this.line.rest()}${ACCUMULATED_LINE_ENDING}`;
410
396
  }
411
397
  addChild(kind) {
412
398
  while (!canContain(this.tip.kind, kind)) this.finalize(this.tip);
@@ -418,20 +404,18 @@ var BlockParser = class {
418
404
  return node;
419
405
  }
420
406
  closeUnmatchedBlocks() {
421
- if (this.allClosed) return;
422
407
  while (this.oldTip !== this.lastMatchedContainer) {
423
408
  const parent = this.oldTip.parent;
424
409
  this.finalize(this.oldTip);
425
410
  if (parent === void 0) break;
426
411
  this.oldTip = parent;
427
412
  }
428
- this.allClosed = true;
429
413
  }
430
414
  finalize(node) {
431
415
  const above = node.parent;
432
416
  node.open = false;
433
417
  this.finalizeContent(node);
434
- if (node !== this.document) this.nestingDepth -= 1;
418
+ this.nestingDepth -= 1;
435
419
  this.tip = above ?? this.document;
436
420
  }
437
421
  finalizeContent(node) {
@@ -452,7 +436,6 @@ var BlockParser = class {
452
436
  case "list":
453
437
  finalizeListTightness(node);
454
438
  return;
455
- default: return;
456
439
  }
457
440
  }
458
441
  finalizeCodeBlock(node) {
@@ -465,8 +448,7 @@ var BlockParser = class {
465
448
  node.literal = node.content.slice(breakIndex + 1);
466
449
  }
467
450
  finalizeMathBlock(node) {
468
- const breakIndex = node.content.indexOf("\n");
469
- node.literal = breakIndex === -1 ? "" : node.content.slice(breakIndex + 1);
451
+ node.literal = node.content.slice(1);
470
452
  }
471
453
  };
472
454
  const BLOCK_EDGE_SPACE_OR_TAB_PATTERN = /^[ \t]+|[ \t]+$/g;
@@ -536,8 +518,8 @@ function toTableNode(node, context) {
536
518
  const sink = context.options.sink ?? NOOP_MARKDOWN_DIAGNOSTIC_SINK;
537
519
  const columnCount = node.alignments.length;
538
520
  const rows = [toTableRow(fitRowToColumns(splitTableRow(node.headerLine), columnCount), true, context)];
539
- for (const rowLine of node.content.split("\n")) {
540
- if (rowLine.trim().length === 0) continue;
521
+ for (const rowLine of node.content.split(ACCUMULATED_LINE_ENDING)) {
522
+ if (rowLine.length === 0) continue;
541
523
  const cells = splitTableRow(rowLine);
542
524
  if (cells.length !== columnCount) sink({
543
525
  code: MarkdownDiagnosticCodes.TABLE_CELL_COUNT_MISMATCH,
@@ -61,10 +61,10 @@ function canContain(parent, child) {
61
61
  default: return false;
62
62
  }
63
63
  }
64
- function acceptsLines(kind) {
65
- return kind === "paragraph" || kind === "codeBlock" || kind === "htmlBlock" || kind === "table" || kind === "mathBlock";
64
+ function suppressesBlockStarts(kind) {
65
+ return kind === "codeBlock" || kind === "htmlBlock" || kind === "mathBlock";
66
66
  }
67
67
  //#endregion
68
68
  exports.BlockNode = BlockNode;
69
- exports.acceptsLines = acceptsLines;
70
69
  exports.canContain = canContain;
70
+ exports.suppressesBlockStarts = suppressesBlockStarts;
@@ -41,6 +41,6 @@ declare class BlockNode {
41
41
  unlink(): void;
42
42
  }
43
43
  declare function canContain(parent: BlockNodeKind, child: BlockNodeKind): boolean;
44
- declare function acceptsLines(kind: BlockNodeKind): boolean;
44
+ declare function suppressesBlockStarts(kind: BlockNodeKind): boolean;
45
45
  //#endregion
46
- export { BlockHeadingLevel, BlockNode, BlockNodeKind, ListMarkerData, acceptsLines, canContain };
46
+ export { BlockHeadingLevel, BlockNode, BlockNodeKind, ListMarkerData, canContain, suppressesBlockStarts };
@@ -41,6 +41,6 @@ declare class BlockNode {
41
41
  unlink(): void;
42
42
  }
43
43
  declare function canContain(parent: BlockNodeKind, child: BlockNodeKind): boolean;
44
- declare function acceptsLines(kind: BlockNodeKind): boolean;
44
+ declare function suppressesBlockStarts(kind: BlockNodeKind): boolean;
45
45
  //#endregion
46
- export { BlockHeadingLevel, BlockNode, BlockNodeKind, ListMarkerData, acceptsLines, canContain };
46
+ export { BlockHeadingLevel, BlockNode, BlockNodeKind, ListMarkerData, canContain, suppressesBlockStarts };
@@ -60,8 +60,8 @@ function canContain(parent, child) {
60
60
  default: return false;
61
61
  }
62
62
  }
63
- function acceptsLines(kind) {
64
- return kind === "paragraph" || kind === "codeBlock" || kind === "htmlBlock" || kind === "table" || kind === "mathBlock";
63
+ function suppressesBlockStarts(kind) {
64
+ return kind === "codeBlock" || kind === "htmlBlock" || kind === "mathBlock";
65
65
  }
66
66
  //#endregion
67
- export { BlockNode, acceptsLines, canContain };
67
+ export { BlockNode, canContain, suppressesBlockStarts };