markdown-codec 11.1.13 → 11.1.14

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.
Files changed (101) hide show
  1. package/dist/block/block.cjs +23 -612
  2. package/dist/block/block.d.cts +22 -3
  3. package/dist/block/block.d.ts +22 -3
  4. package/dist/block/block.js +2 -607
  5. package/dist/block/definitions.d.cts +1 -1
  6. package/dist/block/definitions.d.ts +1 -1
  7. package/dist/block/list.d.cts +1 -1
  8. package/dist/block/list.d.ts +1 -1
  9. package/dist/block/node.d.cts +1 -45
  10. package/dist/block/node.d.ts +1 -45
  11. package/dist/block/parser.cjs +3 -0
  12. package/dist/block/parser.d.cts +57 -0
  13. package/dist/block/parser.d.ts +57 -0
  14. package/dist/block/parser.js +2 -0
  15. package/dist/block-C3ftt8qO.js +610 -0
  16. package/dist/block-DsxTiUms.cjs +747 -0
  17. package/dist/codec.d.cts +8 -8
  18. package/dist/codec.d.ts +8 -8
  19. package/dist/defaults/defaults.d.cts +1 -1
  20. package/dist/defaults/defaults.d.ts +1 -1
  21. package/dist/emit/emit.cjs +7 -647
  22. package/dist/emit/emit.d.cts +22 -3
  23. package/dist/emit/emit.d.ts +22 -3
  24. package/dist/emit/emit.js +2 -646
  25. package/dist/emit/html-table.d.cts +1 -1
  26. package/dist/emit/html-table.d.ts +1 -1
  27. package/dist/emit/inline.cjs +1 -1
  28. package/dist/emit/inline.js +1 -1
  29. package/dist/emit/list-render.cjs +29 -0
  30. package/dist/emit/list-render.d.cts +81 -0
  31. package/dist/emit/list-render.d.ts +81 -0
  32. package/dist/emit/list-render.js +2 -0
  33. package/dist/emit/setext.cjs +143 -0
  34. package/dist/emit/setext.d.cts +30 -0
  35. package/dist/emit/setext.d.ts +30 -0
  36. package/dist/emit/setext.js +119 -0
  37. package/dist/emit/table.d.cts +1 -11
  38. package/dist/emit/table.d.ts +1 -11
  39. package/dist/emit-CCOoudJW.cjs +734 -0
  40. package/dist/emit-Do1KMQHB.js +537 -0
  41. package/dist/index.d.cts +2 -2
  42. package/dist/index.d.ts +2 -2
  43. package/dist/inline/entity.cjs +1 -1
  44. package/dist/inline/entity.js +1 -1
  45. package/dist/inline/inline.cjs +2 -2
  46. package/dist/inline/inline.d.cts +1 -1
  47. package/dist/inline/inline.d.ts +1 -1
  48. package/dist/inline/inline.js +2 -2
  49. package/dist/{inline-CArcArOD.d.ts → inline-BG6ge5m2.d.ts} +1 -1
  50. package/dist/{inline-GzD5QtFh.d.cts → inline-BxX0iOy6.d.cts} +1 -1
  51. package/dist/lower/lower.cjs +3 -3
  52. package/dist/lower/lower.d.cts +1 -1
  53. package/dist/lower/lower.d.ts +1 -1
  54. package/dist/lower/lower.js +2 -2
  55. package/dist/node-DcxnTjF0.d.cts +46 -0
  56. package/dist/node-w8dVfAUD.d.ts +46 -0
  57. package/dist/options/options.d.cts +1 -43
  58. package/dist/options/options.d.ts +1 -43
  59. package/dist/options-CZoMEGL8.d.ts +44 -0
  60. package/dist/options-ZnZOMG3X.d.cts +44 -0
  61. package/dist/read.d.cts +1 -1
  62. package/dist/read.d.ts +1 -1
  63. package/dist/scan/entity-table-n-z.cjs +207 -0
  64. package/dist/scan/entity-table-n-z.d.cts +4 -0
  65. package/dist/scan/entity-table-n-z.d.ts +4 -0
  66. package/dist/scan/entity-table-n-z.js +206 -0
  67. package/dist/scan/entity-table-t-z.cjs +28 -0
  68. package/dist/scan/entity-table-t-z.d.cts +4 -0
  69. package/dist/scan/entity-table-t-z.d.ts +4 -0
  70. package/dist/scan/entity-table-t-z.js +27 -0
  71. package/dist/scan/entity-table-u-z.cjs +59 -0
  72. package/dist/scan/entity-table-u-z.d.cts +4 -0
  73. package/dist/scan/entity-table-u-z.d.ts +4 -0
  74. package/dist/scan/entity-table-u-z.js +58 -0
  75. package/dist/scan/entity-table-w-z.cjs +11 -0
  76. package/dist/scan/entity-table-w-z.d.cts +4 -0
  77. package/dist/scan/entity-table-w-z.d.ts +4 -0
  78. package/dist/scan/entity-table-w-z.js +10 -0
  79. package/dist/scan/entity-table-x-z.cjs +10 -0
  80. package/dist/scan/entity-table-x-z.d.cts +4 -0
  81. package/dist/scan/entity-table-x-z.d.ts +4 -0
  82. package/dist/scan/entity-table-x-z.js +9 -0
  83. package/dist/scan/entity-table-y-z-2.cjs +780 -0
  84. package/dist/scan/entity-table-y-z-2.d.cts +4 -0
  85. package/dist/scan/entity-table-y-z-2.d.ts +4 -0
  86. package/dist/scan/entity-table-y-z-2.js +779 -0
  87. package/dist/scan/entity-table-y-z.cjs +779 -0
  88. package/dist/scan/entity-table-y-z.d.cts +4 -0
  89. package/dist/scan/entity-table-y-z.d.ts +4 -0
  90. package/dist/scan/entity-table-y-z.js +778 -0
  91. package/dist/scan/entity-table.cjs +20 -1834
  92. package/dist/scan/entity-table.d.cts +2 -1
  93. package/dist/scan/entity-table.d.ts +2 -1
  94. package/dist/scan/entity-table.js +20 -1835
  95. package/dist/table-BFbOhm0R.d.ts +12 -0
  96. package/dist/table-PtkYEYdL.d.cts +12 -0
  97. package/dist/write.cjs +2 -2
  98. package/dist/write.d.cts +1 -1
  99. package/dist/write.d.ts +1 -1
  100. package/dist/write.js +1 -1
  101. package/package.json +1 -1
@@ -1,613 +1,24 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_inline_footnote = require("../inline/footnote.cjs");
3
- require("../defaults/defaults.cjs");
4
- const require_diagnostics_diagnostics = require("../diagnostics/diagnostics.cjs");
5
- const require_html_html = require("../html/html.cjs");
6
- const require_inline_entity = require("../inline/entity.cjs");
7
- const require_inline_inline = require("../inline/inline.cjs");
8
- const require_shared_line_ending = require("../shared/line-ending.cjs");
9
- const require_block_definitions = require("./definitions.cjs");
10
- const require_block_line = require("./line.cjs");
11
- const require_block_list = require("./list.cjs");
12
- const require_block_node = require("./node.cjs");
13
- const require_block_table = require("./table.cjs");
14
- //#region src/block/block.ts
15
- const TASK_LIST_MARKER_PATTERN = /^\[([ xX])\][ \t]/;
16
- const NUL_REPLACEMENT = "�";
17
- const NUL_PATTERN = /\0/g;
18
- const ATX_MARKER_PATTERN = /^#{1,6}(?:[ \t]+|$)/;
19
- const ATX_ONLY_CLOSING_SEQUENCE_PATTERN = /^[ \t]*#+[ \t]*$/;
20
- const ATX_TRAILING_CLOSING_SEQUENCE_PATTERN = /[ \t]+#+[ \t]*$/;
21
- const CODE_FENCE_PATTERN = /^`{3,}(?!.*`)|^~{3,}/;
22
- const CLOSING_CODE_FENCE_PATTERN = /^(?:`{3,}|~{3,})(?=[ \t]*$)/;
23
- const MATH_BLOCK_MARKER_PATTERN = /^\$\$[ \t]*$/;
24
- const ACCUMULATED_LINE_ENDING = "\n";
25
- const SETEXT_UNDERLINE_PATTERN = /^(?:=+|-+)[ \t]*$/;
26
- const THEMATIC_BREAK_PATTERN = /^(?:\*[ \t]*){3,}$|^(?:_[ \t]*){3,}$|^(?:-[ \t]*){3,}$/;
27
- const BLANK_CONTENT_PATTERN = /^[ \t\n]*$/;
28
- const TRAILING_BLANK_LINES_PATTERN = /(?:\n[ \t]*)+$/;
29
- const TRAILING_HTML_BLANK_LINES_PATTERN = /(?:\n *)+$/;
30
- const MAX_HEADING_LEVEL = 6;
31
- const SETEXT_LEVEL_1 = 1;
32
- const SETEXT_LEVEL_2 = 2;
33
- const HTML_BLOCK_BLANK_LINE_END_TYPES = [6, 7];
34
- function isBlankContent(content) {
35
- return BLANK_CONTENT_PATTERN.test(content);
36
- }
37
- function headingLevelOf(hashes) {
38
- if (hashes >= 1 && hashes < MAX_HEADING_LEVEL) return hashes;
39
- return MAX_HEADING_LEVEL;
40
- }
41
- var BlockParser = class {
42
- references = /* @__PURE__ */ new Map();
43
- footnotes = /* @__PURE__ */ new Set();
44
- document = new require_block_node.BlockNode("document", 1);
45
- tables;
46
- footnotesEnabled;
47
- sink;
48
- maxNesting;
49
- tip = this.document;
50
- oldTip = this.document;
51
- lastMatchedContainer = this.document;
52
- line;
53
- lineNumber = 0;
54
- nestingDepth = 0;
55
- constructor(options) {
56
- this.tables = options.gfmTables ?? true;
57
- this.footnotesEnabled = options.footnotes ?? true;
58
- this.sink = options.sink ?? require_diagnostics_diagnostics.NOOP_MARKDOWN_DIAGNOSTIC_SINK;
59
- this.maxNesting = options.maxNesting ?? 250;
60
- }
61
- parse(source) {
62
- const lines = source.split(require_shared_line_ending.LINE_ENDING_PATTERN);
63
- const count = source.endsWith("\n") || source.endsWith("\r") ? lines.length - 1 : lines.length;
64
- for (let index = 0; index < count; index += 1) {
65
- const text = lines[index];
66
- if (text !== void 0) this.incorporateLine(text);
67
- }
68
- while (this.tip !== this.document) {
69
- this.reportUnterminatedAtEof(this.tip);
70
- this.finalize(this.tip);
71
- }
72
- return this.document;
73
- }
74
- reportUnterminatedAtEof(node) {
75
- if (node.fenced) {
76
- this.sink({
77
- code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.UNCLOSED_FENCE,
78
- severity: "warning",
79
- message: `fenced code block starting at line ${String(node.startLine)} was never closed by a matching closing fence before the end of the document`,
80
- line: node.startLine
81
- });
82
- return;
83
- }
84
- if (node.kind === "htmlBlock" && !HTML_BLOCK_BLANK_LINE_END_TYPES.includes(node.htmlBlockType)) {
85
- this.sink({
86
- code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.UNTERMINATED_HTML_BLOCK,
87
- severity: "warning",
88
- message: `HTML block (type ${String(node.htmlBlockType)}) starting at line ${String(node.startLine)} never met its own end condition before the end of the document`,
89
- line: node.startLine
90
- });
91
- return;
92
- }
93
- if (node.kind === "mathBlock") this.sink({
94
- code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.UNCLOSED_MATH_BLOCK,
95
- severity: "warning",
96
- message: `math block starting at line ${String(node.startLine)} was never closed by a matching closing $$ before the end of the document`,
97
- line: node.startLine
98
- });
99
- }
100
- incorporateLine(rawText) {
101
- this.lineNumber += 1;
102
- this.line = new require_block_line.LineCursor(rawText.replace(NUL_PATTERN, NUL_REPLACEMENT));
103
- this.oldTip = this.tip;
104
- const matched = this.walkOpenBlocks();
105
- if (matched === void 0) return;
106
- this.lastMatchedContainer = matched;
107
- this.addTextToContainer(this.openNewBlocks(matched));
108
- }
109
- walkOpenBlocks() {
110
- let container = this.document;
111
- for (;;) {
112
- const lastChild = container.lastChild;
113
- if (lastChild?.open !== true) return container;
114
- this.line.findNextNonspace();
115
- const result = this.continueBlock(lastChild);
116
- if (result !== "matched") return result === "finished" ? void 0 : container;
117
- container = lastChild;
118
- }
119
- }
120
- continueBlock(node) {
121
- switch (node.kind) {
122
- case "document":
123
- case "list": return "matched";
124
- case "blockquote": return this.continueBlockquote();
125
- case "listItem": return this.continueListItem(node);
126
- case "footnoteDefinition": return this.continueFootnoteDefinition(node);
127
- case "codeBlock": return this.continueCodeBlock(node);
128
- case "mathBlock": return this.continueMathBlock(node);
129
- case "htmlBlock": return this.line.blank && HTML_BLOCK_BLANK_LINE_END_TYPES.includes(node.htmlBlockType) ? "not-matched" : "matched";
130
- case "paragraph":
131
- case "table": return this.line.blank ? "not-matched" : "matched";
132
- case "heading":
133
- case "thematicBreak": return "not-matched";
134
- }
135
- return assertNeverBlockKind(node.kind);
136
- }
137
- continueBlockquote() {
138
- if (!this.consumeBlockquoteMarker()) return "not-matched";
139
- return "matched";
140
- }
141
- consumeBlockquoteMarker() {
142
- if (this.line.indented || this.line.peekNextNonspace() !== ">") return false;
143
- this.line.advanceToNextNonspace();
144
- this.line.advance(1);
145
- if (this.line.peek() === " ") this.line.advance(1);
146
- return true;
147
- }
148
- continueListItem(node) {
149
- const listData = node.listData;
150
- if (listData === void 0) return "not-matched";
151
- if (this.line.blank) {
152
- if (node.children.length === 0) return "not-matched";
153
- this.line.advanceToNextNonspace();
154
- return "matched";
155
- }
156
- if (this.line.indent >= listData.markerOffset + listData.padding) {
157
- this.line.advance(listData.markerOffset + listData.padding);
158
- return "matched";
159
- }
160
- return "not-matched";
161
- }
162
- continueFootnoteDefinition(node) {
163
- if (this.line.blank) {
164
- if (node.children.length === 0) return "not-matched";
165
- this.line.advanceToNextNonspace();
166
- return "matched";
167
- }
168
- if (this.line.indent >= 4) {
169
- this.line.advance(4);
170
- return "matched";
171
- }
172
- return "not-matched";
173
- }
174
- continueCodeBlock(node) {
175
- if (!node.fenced) {
176
- if (this.line.indent >= 4) {
177
- this.line.advance(4);
178
- return "matched";
179
- }
180
- if (this.line.blank) {
181
- this.line.advanceToNextNonspace();
182
- return "matched";
183
- }
184
- return "not-matched";
185
- }
186
- const rest = this.line.restFromNextNonspace();
187
- const closing = this.line.indented || !rest.startsWith(node.fenceChar) ? null : CLOSING_CODE_FENCE_PATTERN.exec(rest);
188
- if (closing !== null && closing[0].length >= node.fenceLength) {
189
- this.finalize(node);
190
- return "finished";
191
- }
192
- for (let remaining = node.fenceOffset; remaining > 0 && this.line.peek() === " "; remaining -= 1) this.line.advance(1);
193
- return "matched";
194
- }
195
- continueMathBlock(node) {
196
- if (!this.line.indented && MATH_BLOCK_MARKER_PATTERN.test(this.line.restFromNextNonspace())) {
197
- this.finalize(node);
198
- return "finished";
199
- }
200
- return "matched";
201
- }
202
- openNewBlocks(matchedContainer) {
203
- let container = matchedContainer;
204
- let matchedLeaf = require_block_node.suppressesBlockStarts(container.kind);
205
- while (!matchedLeaf) {
206
- this.line.findNextNonspace();
207
- const result = this.tryBlockStart(container);
208
- if (result === "none") {
209
- this.line.advanceToNextNonspace();
210
- break;
211
- }
212
- container = this.tip;
213
- matchedLeaf = result === "leaf";
214
- }
215
- return container;
216
- }
217
- tryBlockStart(container) {
218
- const starts = [
219
- () => this.tryBlockquoteStart(),
220
- () => this.tryAtxHeadingStart(),
221
- () => this.tryCodeFenceStart(),
222
- () => this.tryMathBlockStart(),
223
- () => this.tryFootnoteDefinitionStart(container),
224
- () => this.tryHtmlBlockStart(),
225
- () => this.tryPromoteParagraph(container),
226
- () => this.tryThematicBreakStart(),
227
- () => this.tryListItemStart(container),
228
- () => this.tryIndentedCodeStart()
229
- ];
230
- for (const start of starts) {
231
- const result = start();
232
- if (result !== "none") return result;
233
- }
234
- return "none";
235
- }
236
- tryBlockquoteStart() {
237
- if (!this.consumeBlockquoteMarker()) return "none";
238
- this.closeUnmatchedBlocks();
239
- this.addChild("blockquote");
240
- return "container";
241
- }
242
- tryAtxHeadingStart() {
243
- if (this.line.indented) return "none";
244
- const rest = this.line.restFromNextNonspace();
245
- const match = ATX_MARKER_PATTERN.exec(rest);
246
- if (match === null) return "none";
247
- this.closeUnmatchedBlocks();
248
- const heading = this.addChild("heading");
249
- heading.level = headingLevelOf(match[0].trim().length);
250
- heading.content = rest.slice(match[0].length).replace(ATX_ONLY_CLOSING_SEQUENCE_PATTERN, "").replace(ATX_TRAILING_CLOSING_SEQUENCE_PATTERN, "");
251
- this.line.advanceToEndOfLine();
252
- return "leaf";
253
- }
254
- tryCodeFenceStart() {
255
- if (this.line.indented) return "none";
256
- const match = CODE_FENCE_PATTERN.exec(this.line.restFromNextNonspace());
257
- if (match === null) return "none";
258
- const fence = match[0];
259
- const fenceChar = fence.charAt(0);
260
- if (fenceChar !== "`" && fenceChar !== "~") return "none";
261
- this.closeUnmatchedBlocks();
262
- const block = this.addChild("codeBlock");
263
- block.fenced = true;
264
- block.fenceChar = fenceChar;
265
- block.fenceLength = fence.length;
266
- block.fenceOffset = this.line.indent;
267
- this.line.advanceToNextNonspace();
268
- this.line.advance(fence.length);
269
- return "leaf";
270
- }
271
- tryMathBlockStart() {
272
- if (this.line.indented) return "none";
273
- if (!MATH_BLOCK_MARKER_PATTERN.test(this.line.restFromNextNonspace())) return "none";
274
- this.closeUnmatchedBlocks();
275
- this.addChild("mathBlock");
276
- this.line.advanceToEndOfLine();
277
- return "leaf";
278
- }
279
- tryFootnoteDefinitionStart(container) {
280
- if (!this.footnotesEnabled || this.line.indented || !this.footnoteDefinitionMayOpenIn(container)) return "none";
281
- const marker = require_inline_footnote.matchFootnoteDefinitionMarker(this.line.restFromNextNonspace());
282
- if (marker === void 0) return "none";
283
- if (this.footnotes.has(marker.label)) this.sink({
284
- code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.DUPLICATE_FOOTNOTE_DEFINITION,
285
- severity: "warning",
286
- message: `footnote "${marker.label}" was already defined earlier in the document; every reference resolves to the first definition, and both definitions are kept as written`,
287
- line: this.lineNumber
288
- });
289
- this.footnotes.add(marker.label);
290
- this.line.advanceToNextNonspace();
291
- this.closeUnmatchedBlocks();
292
- const node = this.addChild("footnoteDefinition");
293
- node.footnoteLabel = marker.label;
294
- this.line.advance(marker.markerLength);
295
- return "container";
296
- }
297
- footnoteDefinitionMayOpenIn(container) {
298
- let node = container;
299
- while (node?.kind === "list") node = node.parent;
300
- return node?.kind === "document" || node?.kind === "blockquote" || node?.kind === "listItem";
301
- }
302
- tryHtmlBlockStart() {
303
- if (this.line.indented) return "none";
304
- const interruptsParagraph = this.tip.kind === "paragraph";
305
- const type = require_html_html.matchHtmlBlockStart(this.line.restFromNextNonspace(), interruptsParagraph);
306
- if (type === void 0) return "none";
307
- this.closeUnmatchedBlocks();
308
- this.addChild("htmlBlock").htmlBlockType = type;
309
- return "leaf";
310
- }
311
- tryPromoteParagraph(container) {
312
- if (this.line.indented || container.kind !== "paragraph") return "none";
313
- const setext = this.trySetextHeading(container);
314
- return setext === "none" ? this.tryTableHeader(container) : setext;
315
- }
316
- trySetextHeading(paragraph) {
317
- const match = SETEXT_UNDERLINE_PATTERN.exec(this.line.restFromNextNonspace());
318
- if (match === null) return "none";
319
- paragraph.content = require_block_definitions.extractDefinitions(paragraph.content, this.references, this.sink, paragraph.startLine);
320
- if (isBlankContent(paragraph.content)) return "none";
321
- const heading = new require_block_node.BlockNode("heading", paragraph.startLine);
322
- heading.level = match[0].startsWith("=") ? SETEXT_LEVEL_1 : SETEXT_LEVEL_2;
323
- heading.setext = true;
324
- heading.content = paragraph.content;
325
- paragraph.replaceWith(heading);
326
- this.tip = heading;
327
- this.line.advanceToEndOfLine();
328
- return "leaf";
329
- }
330
- tryTableHeader(paragraph) {
331
- if (!this.tables) return "none";
332
- const alignments = require_block_table.parseTableDelimiterRow(this.line.restFromNextNonspace());
333
- if (alignments === void 0) return "none";
334
- const lines = paragraph.content.split("\n");
335
- const secondToLastLineOffset = -2;
336
- const headerLine = lines.at(secondToLastLineOffset);
337
- if (headerLine === void 0 || require_block_table.splitTableRow(headerLine).length !== alignments.length) return "none";
338
- paragraph.content = lines.slice(0, secondToLastLineOffset).map((text) => `${text}\n`).join("");
339
- const table = this.addChild("table");
340
- table.alignments = alignments;
341
- table.headerLine = headerLine;
342
- this.line.advanceToEndOfLine();
343
- return "leaf";
344
- }
345
- tryThematicBreakStart() {
346
- if (this.line.indented || !THEMATIC_BREAK_PATTERN.test(this.line.restFromNextNonspace())) return "none";
347
- this.closeUnmatchedBlocks();
348
- this.addChild("thematicBreak");
349
- this.line.advanceToEndOfLine();
350
- return "leaf";
351
- }
352
- tryListItemStart(container) {
353
- const data = require_block_list.parseListMarker(this.line, container.kind === "paragraph");
354
- if (data === void 0) return "none";
355
- this.closeUnmatchedBlocks();
356
- const openList = this.tip.listData;
357
- if (this.tip.kind !== "list" || openList === void 0 || !require_block_list.listsMatch(openList, data)) this.addChild("list").listData = data;
358
- this.addChild("listItem").listData = data;
359
- return "container";
360
- }
361
- tryIndentedCodeStart() {
362
- if (!this.line.indented || this.tip.kind === "paragraph" || this.line.blank) return "none";
363
- this.line.advance(4);
364
- this.closeUnmatchedBlocks();
365
- this.addChild("codeBlock");
366
- return "leaf";
367
- }
368
- addTextToContainer(container) {
369
- if (this.tip.kind === "paragraph" && !this.line.blank) {
370
- this.addLine();
371
- return;
372
- }
373
- this.closeUnmatchedBlocks();
374
- const lastChild = container.lastChild;
375
- if (this.line.blank && lastChild !== void 0) lastChild.lastLineBlank = true;
376
- this.recordBlankLineForTightness(container);
377
- if (require_block_node.suppressesBlockStarts(container.kind) || container.kind === "table") {
378
- this.addLine();
379
- if (container.kind === "htmlBlock" && require_html_html.matchesHtmlBlockEnd(this.line.rest(), container.htmlBlockType)) this.finalize(container);
380
- return;
381
- }
382
- if (!this.line.atEnd && !this.line.blank) {
383
- this.addChild("paragraph");
384
- this.addLine();
385
- }
386
- }
387
- recordBlankLineForTightness(container) {
388
- const blank = this.line.blank && !(container.kind === "blockquote" || container.fenced || container.kind === "listItem");
389
- for (let node = container; node !== void 0; node = node.parent) node.lastLineBlank = blank;
390
- }
391
- addLine() {
392
- this.tip.content += `${this.line.rest()}${ACCUMULATED_LINE_ENDING}`;
393
- }
394
- addChild(kind) {
395
- while (!require_block_node.canContain(this.tip.kind, kind)) this.finalize(this.tip);
396
- if (this.nestingDepth >= this.maxNesting) throw new require_diagnostics_diagnostics.MarkdownNestingLimitExceededError(this.maxNesting);
397
- const node = new require_block_node.BlockNode(kind, this.lineNumber);
398
- this.tip.appendChild(node);
399
- this.tip = node;
400
- this.nestingDepth += 1;
401
- return node;
402
- }
403
- closeUnmatchedBlocks() {
404
- while (this.oldTip !== this.lastMatchedContainer) {
405
- const parent = this.oldTip.parent;
406
- this.finalize(this.oldTip);
407
- if (parent === void 0) break;
408
- this.oldTip = parent;
409
- }
410
- }
411
- finalize(node) {
412
- const above = node.parent;
413
- node.open = false;
414
- this.finalizeContent(node);
415
- this.nestingDepth -= 1;
416
- this.tip = above ?? this.document;
417
- }
418
- finalizeContent(node) {
419
- switch (node.kind) {
420
- case "paragraph":
421
- node.content = require_block_definitions.extractDefinitions(node.content, this.references, this.sink, node.startLine);
422
- if (isBlankContent(node.content)) node.unlink();
423
- return;
424
- case "codeBlock":
425
- this.finalizeCodeBlock(node);
426
- return;
427
- case "mathBlock":
428
- this.finalizeMathBlock(node);
429
- return;
430
- case "htmlBlock":
431
- node.literal = node.content.replace(TRAILING_HTML_BLANK_LINES_PATTERN, "");
432
- return;
433
- case "list":
434
- require_block_list.finalizeListTightness(node);
435
- return;
436
- default: return;
437
- }
438
- }
439
- finalizeCodeBlock(node) {
440
- if (!node.fenced) {
441
- node.literal = node.content.replace(TRAILING_BLANK_LINES_PATTERN, "\n");
442
- return;
443
- }
444
- const breakIndex = node.content.indexOf("\n");
445
- node.infoString = require_inline_entity.unescapeString(node.content.slice(0, breakIndex).trim());
446
- node.literal = node.content.slice(breakIndex + 1);
447
- }
448
- finalizeMathBlock(node) {
449
- node.literal = node.content.slice(1);
450
- }
451
- };
452
- const BLOCK_EDGE_SPACE_OR_TAB_PATTERN = /^[ \t]+|[ \t]+$/g;
453
- function trimBlockContent(text) {
454
- return (text.endsWith("\n") ? text.slice(0, -1) : text).replace(BLOCK_EDGE_SPACE_OR_TAB_PATTERN, "");
455
- }
456
- function toInlineChildren(content, context) {
457
- return require_inline_inline.parseInlines(trimBlockContent(content), context.references, context.footnotes, context.options);
458
- }
459
- function toHeadingNode(node, context) {
460
- return {
461
- type: "heading",
462
- level: node.level,
463
- style: node.setext ? "setext" : "atx",
464
- children: toInlineChildren(node.content, context)
465
- };
466
- }
467
- function extractTaskListMarker(itemChildren) {
468
- const first = itemChildren[0];
469
- if (first?.kind !== "paragraph") return;
470
- const match = TASK_LIST_MARKER_PATTERN.exec(first.content);
471
- if (match === null) return;
472
- first.content = first.content.slice(match[0].length);
473
- return match[1] !== " ";
474
- }
475
- function toListItemNode(item, context) {
476
- const checked = context.options.gfmTaskLists ?? true ? extractTaskListMarker(item.children) : void 0;
477
- return checked === void 0 ? {
478
- type: "listItem",
479
- children: toAstBlocks(item.children, context)
480
- } : {
481
- type: "listItem",
482
- checked,
483
- children: toAstBlocks(item.children, context)
484
- };
485
- }
486
- function toListNode(node, context) {
487
- const children = node.children.map((item) => toListItemNode(item, context));
488
- const data = node.listData;
489
- if (data?.type === "ordered") return {
490
- type: "list",
491
- markerType: "ordered",
492
- orderedDelimiter: data.delimiter,
493
- start: data.start,
494
- tight: node.tight,
495
- children
496
- };
497
- return {
498
- type: "list",
499
- markerType: "bullet",
500
- bulletMarker: data?.bulletChar,
501
- tight: node.tight,
502
- children
503
- };
504
- }
505
- function toTableRow(cells, header, context) {
506
- return {
507
- type: "tableRow",
508
- header,
509
- children: cells.map((cell) => ({
510
- type: "tableCell",
511
- children: toInlineChildren(cell, context)
512
- }))
513
- };
514
- }
515
- function toTableNode(node, context) {
516
- const sink = context.options.sink ?? require_diagnostics_diagnostics.NOOP_MARKDOWN_DIAGNOSTIC_SINK;
517
- const columnCount = node.alignments.length;
518
- const rows = [toTableRow(require_block_table.fitRowToColumns(require_block_table.splitTableRow(node.headerLine), columnCount), true, context)];
519
- for (const rowLine of node.content.split(ACCUMULATED_LINE_ENDING)) {
520
- if (rowLine.length === 0) continue;
521
- const cells = require_block_table.splitTableRow(rowLine);
522
- if (cells.length !== columnCount) sink({
523
- code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.TABLE_CELL_COUNT_MISMATCH,
524
- severity: "warning",
525
- message: `table row has ${String(cells.length)} cell(s), but the header row declares ${String(columnCount)}; the row is padded with empty cells or truncated to fit`,
526
- line: node.startLine
527
- });
528
- rows.push(toTableRow(require_block_table.fitRowToColumns(cells, columnCount), false, context));
529
- }
530
- return {
531
- type: "table",
532
- alignments: node.alignments,
533
- children: rows
534
- };
535
- }
536
- function toAstBlock(node, context) {
537
- switch (node.kind) {
538
- case "paragraph": return {
539
- type: "paragraph",
540
- children: toInlineChildren(node.content, context)
541
- };
542
- case "heading": return toHeadingNode(node, context);
543
- case "blockquote": return {
544
- type: "blockquote",
545
- children: toAstBlocks(node.children, context)
546
- };
547
- case "list": return toListNode(node, context);
548
- case "footnoteDefinition": return {
549
- type: "footnoteDefinition",
550
- label: node.footnoteLabel,
551
- children: toAstBlocks(node.children, context)
552
- };
553
- case "codeBlock": return node.fenced ? {
554
- type: "codeBlock",
555
- fenced: true,
556
- fenceChar: node.fenceChar,
557
- infoString: node.infoString,
558
- literal: node.literal
559
- } : {
560
- type: "codeBlock",
561
- fenced: false,
562
- literal: node.literal
563
- };
564
- case "htmlBlock": return {
565
- type: "htmlBlock",
566
- literal: node.literal
567
- };
568
- case "thematicBreak": return { type: "thematicBreak" };
569
- case "mathBlock": return {
570
- type: "mathBlock",
571
- literal: node.literal
572
- };
573
- case "table": return toTableNode(node, context);
574
- case "document":
575
- case "listItem": return;
576
- }
577
- return assertNeverBlockKind(node.kind);
578
- }
579
- function toAstBlocks(nodes, context) {
580
- const blocks = [];
581
- for (const node of nodes) {
582
- const converted = toAstBlock(node, context);
583
- if (converted !== void 0) blocks.push(converted);
584
- }
585
- return blocks;
586
- }
587
- function parseMarkdown(source, options = {}) {
588
- const parser = new BlockParser(options);
589
- const root = parser.parse(source);
590
- const context = {
591
- references: parser.references,
592
- footnotes: parser.footnotes,
593
- options
594
- };
595
- return {
596
- document: {
597
- type: "document",
598
- children: toAstBlocks(root.children, context)
599
- },
600
- references: context.references,
601
- footnotes: context.footnotes
602
- };
603
- }
604
- function assertNeverBlockKind(kind) {
605
- throw new Error(`markdown-codec: unhandled block kind ${JSON.stringify(kind)}`);
606
- }
607
- //#endregion
608
- exports.ATX_MARKER_PATTERN = ATX_MARKER_PATTERN;
609
- exports.CODE_FENCE_PATTERN = CODE_FENCE_PATTERN;
610
- exports.MATH_BLOCK_MARKER_PATTERN = MATH_BLOCK_MARKER_PATTERN;
611
- exports.THEMATIC_BREAK_PATTERN = THEMATIC_BREAK_PATTERN;
612
- exports.assertNeverBlockKind = assertNeverBlockKind;
613
- exports.parseMarkdown = parseMarkdown;
2
+ const require_block = require("../block-DsxTiUms.cjs");
3
+ exports.ACCUMULATED_LINE_ENDING = require_block.ACCUMULATED_LINE_ENDING;
4
+ exports.ATX_MARKER_PATTERN = require_block.ATX_MARKER_PATTERN;
5
+ exports.ATX_ONLY_CLOSING_SEQUENCE_PATTERN = require_block.ATX_ONLY_CLOSING_SEQUENCE_PATTERN;
6
+ exports.ATX_TRAILING_CLOSING_SEQUENCE_PATTERN = require_block.ATX_TRAILING_CLOSING_SEQUENCE_PATTERN;
7
+ exports.CLOSING_CODE_FENCE_PATTERN = require_block.CLOSING_CODE_FENCE_PATTERN;
8
+ exports.CODE_FENCE_PATTERN = require_block.CODE_FENCE_PATTERN;
9
+ exports.HTML_BLOCK_BLANK_LINE_END_TYPES = require_block.HTML_BLOCK_BLANK_LINE_END_TYPES;
10
+ exports.MATH_BLOCK_MARKER_PATTERN = require_block.MATH_BLOCK_MARKER_PATTERN;
11
+ exports.NUL_PATTERN = require_block.NUL_PATTERN;
12
+ exports.NUL_REPLACEMENT = require_block.NUL_REPLACEMENT;
13
+ exports.SETEXT_LEVEL_1 = require_block.SETEXT_LEVEL_1;
14
+ exports.SETEXT_LEVEL_2 = require_block.SETEXT_LEVEL_2;
15
+ exports.SETEXT_UNDERLINE_PATTERN = require_block.SETEXT_UNDERLINE_PATTERN;
16
+ exports.TASK_LIST_MARKER_PATTERN = require_block.TASK_LIST_MARKER_PATTERN;
17
+ exports.THEMATIC_BREAK_PATTERN = require_block.THEMATIC_BREAK_PATTERN;
18
+ exports.TRAILING_BLANK_LINES_PATTERN = require_block.TRAILING_BLANK_LINES_PATTERN;
19
+ exports.TRAILING_HTML_BLANK_LINES_PATTERN = require_block.TRAILING_HTML_BLANK_LINES_PATTERN;
20
+ exports.assertNeverBlockKind = require_block.assertNeverBlockKind;
21
+ exports.headingLevelOf = require_block.headingLevelOf;
22
+ exports.isBlankContent = require_block.isBlankContent;
23
+ exports.parseMarkdown = require_block.parseMarkdown;
24
+ exports.trimBlockContent = require_block.trimBlockContent;
@@ -1,13 +1,29 @@
1
1
  import { s as MarkdownDocumentNode } from "../ast-DI-t9uKv.cjs";
2
+ import { LinkReferenceMap } from "../inline/link.cjs";
2
3
  import { r as FootnoteLabelSet } from "../footnote-CKk4JbLk.cjs";
3
4
  import { i as MarkdownDiagnosticSink } from "../diagnostics-D3UiC9HL.cjs";
4
- import { LinkReferenceMap } from "../inline/link.cjs";
5
- import { t as InlineParseOptions } from "../inline-GzD5QtFh.cjs";
5
+ import { t as InlineParseOptions } from "../inline-BxX0iOy6.cjs";
6
+ import { t as BlockHeadingLevel } from "../node-DcxnTjF0.cjs";
6
7
  //#region src/block/block.d.ts
8
+ declare const TASK_LIST_MARKER_PATTERN: RegExp;
9
+ declare const NUL_REPLACEMENT = "�";
10
+ declare const NUL_PATTERN: RegExp;
7
11
  declare const ATX_MARKER_PATTERN: RegExp;
12
+ declare const ATX_ONLY_CLOSING_SEQUENCE_PATTERN: RegExp;
13
+ declare const ATX_TRAILING_CLOSING_SEQUENCE_PATTERN: RegExp;
8
14
  declare const CODE_FENCE_PATTERN: RegExp;
15
+ declare const CLOSING_CODE_FENCE_PATTERN: RegExp;
9
16
  declare const MATH_BLOCK_MARKER_PATTERN: RegExp;
17
+ declare const ACCUMULATED_LINE_ENDING = "\n";
18
+ declare const SETEXT_UNDERLINE_PATTERN: RegExp;
10
19
  declare const THEMATIC_BREAK_PATTERN: RegExp;
20
+ declare const TRAILING_BLANK_LINES_PATTERN: RegExp;
21
+ declare const TRAILING_HTML_BLANK_LINES_PATTERN: RegExp;
22
+ declare const SETEXT_LEVEL_1 = 1;
23
+ declare const SETEXT_LEVEL_2 = 2;
24
+ declare const HTML_BLOCK_BLANK_LINE_END_TYPES: readonly number[];
25
+ type BlockStartResult = "none" | "container" | "leaf";
26
+ type ContinueResult = "matched" | "not-matched" | "finished";
11
27
  interface MarkdownParseOptions extends InlineParseOptions {
12
28
  readonly gfmTables?: boolean;
13
29
  readonly gfmTaskLists?: boolean;
@@ -20,7 +36,10 @@ interface ParsedMarkdown {
20
36
  readonly references: LinkReferenceMap;
21
37
  readonly footnotes: FootnoteLabelSet;
22
38
  }
39
+ declare function isBlankContent(content: string): boolean;
40
+ declare function headingLevelOf(hashes: number): BlockHeadingLevel;
41
+ declare function trimBlockContent(text: string): string;
23
42
  declare function parseMarkdown(source: string, options?: MarkdownParseOptions): ParsedMarkdown;
24
43
  declare function assertNeverBlockKind(kind: never): never;
25
44
  //#endregion
26
- export { ATX_MARKER_PATTERN, CODE_FENCE_PATTERN, MATH_BLOCK_MARKER_PATTERN, MarkdownParseOptions, ParsedMarkdown, THEMATIC_BREAK_PATTERN, assertNeverBlockKind, parseMarkdown };
45
+ export { ACCUMULATED_LINE_ENDING, ATX_MARKER_PATTERN, ATX_ONLY_CLOSING_SEQUENCE_PATTERN, ATX_TRAILING_CLOSING_SEQUENCE_PATTERN, BlockStartResult, CLOSING_CODE_FENCE_PATTERN, CODE_FENCE_PATTERN, ContinueResult, HTML_BLOCK_BLANK_LINE_END_TYPES, MATH_BLOCK_MARKER_PATTERN, MarkdownParseOptions, NUL_PATTERN, NUL_REPLACEMENT, ParsedMarkdown, SETEXT_LEVEL_1, SETEXT_LEVEL_2, SETEXT_UNDERLINE_PATTERN, TASK_LIST_MARKER_PATTERN, THEMATIC_BREAK_PATTERN, TRAILING_BLANK_LINES_PATTERN, TRAILING_HTML_BLANK_LINES_PATTERN, assertNeverBlockKind, headingLevelOf, isBlankContent, parseMarkdown, trimBlockContent };