markdown-codec 6.7.3 → 6.7.5

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 (56) hide show
  1. package/README.md +2 -1
  2. package/dist/block/definitions.cjs +1 -5
  3. package/dist/block/definitions.js +1 -5
  4. package/dist/block/line.cjs +2 -2
  5. package/dist/block/line.js +2 -2
  6. package/dist/block/list.cjs +7 -14
  7. package/dist/block/list.js +7 -14
  8. package/dist/block/table.cjs +3 -4
  9. package/dist/block/table.js +3 -4
  10. package/dist/codec.d.cts +36 -36
  11. package/dist/codec.d.ts +36 -36
  12. package/dist/emit/emit.cjs +35 -37
  13. package/dist/emit/emit.js +35 -37
  14. package/dist/emit/table.cjs +2 -2
  15. package/dist/emit/table.js +2 -2
  16. package/dist/html/html.cjs +0 -2
  17. package/dist/html/html.js +0 -2
  18. package/dist/html/render.cjs +3 -11
  19. package/dist/html/render.js +3 -11
  20. package/dist/image/image.cjs +0 -49
  21. package/dist/image/image.d.cts +2 -2
  22. package/dist/image/image.d.ts +2 -2
  23. package/dist/image/image.js +1 -48
  24. package/dist/{image-BtmTG4_a.d.cts → image-83yql5ES.d.cts} +1 -3
  25. package/dist/{image-BtmTG4_a.d.ts → image-83yql5ES.d.ts} +1 -3
  26. package/dist/{image-B5L0HpAJ.d.cts → image-B6p0Ovgy.d.cts} +1 -1
  27. package/dist/{image-C390OIB3.d.ts → image-gR1vISI0.d.ts} +1 -1
  28. package/dist/index.d.cts +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/inline/chars.cjs +3 -6
  31. package/dist/inline/chars.js +3 -6
  32. package/dist/inline/delimiter.cjs +5 -12
  33. package/dist/inline/delimiter.d.cts +2 -1
  34. package/dist/inline/delimiter.d.ts +2 -1
  35. package/dist/inline/delimiter.js +5 -13
  36. package/dist/inline/entity.cjs +6 -10
  37. package/dist/inline/entity.js +6 -10
  38. package/dist/inline/link.cjs +4 -5
  39. package/dist/inline/link.js +4 -5
  40. package/dist/lower/front-matter.cjs +4 -8
  41. package/dist/lower/front-matter.js +4 -8
  42. package/dist/lower/image.cjs +3 -2
  43. package/dist/lower/image.d.cts +1 -1
  44. package/dist/lower/image.d.ts +1 -1
  45. package/dist/lower/image.js +2 -1
  46. package/dist/lower/inline.cjs +0 -2
  47. package/dist/lower/inline.js +0 -2
  48. package/dist/options/options.d.cts +1 -1
  49. package/dist/options/options.d.ts +1 -1
  50. package/dist/read.cjs +2 -2
  51. package/dist/read.js +2 -2
  52. package/dist/scan/scan.cjs +1 -3
  53. package/dist/scan/scan.js +1 -3
  54. package/dist/shared/list-id.cjs +1 -1
  55. package/dist/shared/list-id.js +1 -1
  56. package/package.json +3 -2
package/dist/emit/emit.js CHANGED
@@ -3,7 +3,6 @@ import "../defaults/defaults.js";
3
3
  import { MarkdownDiagnosticCodes, MarkdownInvalidRunConstructExtentError, MarkdownUnbalancedConstructMarkersError, MarkdownUnsupportedDocumentKindError, NOOP_MARKDOWN_DIAGNOSTIC_SINK } from "../diagnostics/diagnostics.js";
4
4
  import { matchHtmlBlockStart } from "../html/html.js";
5
5
  import { ESCAPED_HARD_BREAK_PATTERN, LINE_ENDING_PATTERN } from "../shared/line-ending.js";
6
- import "../scan/scan.js";
7
6
  import { LineCursor } from "../block/line.js";
8
7
  import { parseListMarker } from "../block/list.js";
9
8
  import { parseTableDelimiterRow, splitTableRow } from "../block/table.js";
@@ -23,9 +22,13 @@ const MAX_SETEXT_LEVEL = 2;
23
22
  const SETEXT_LEVEL_1_CHAR = "=";
24
23
  const SETEXT_LEVEL_2_CHAR = "-";
25
24
  const MIN_SETEXT_UNDERLINE_LENGTH = 1;
25
+ function splitLines(text, pattern) {
26
+ const [first, ...rest] = text.split(pattern);
27
+ return [first, ...rest];
28
+ }
26
29
  function renderSetextHeading(level, text) {
27
30
  const underlineChar = level === 1 ? SETEXT_LEVEL_1_CHAR : SETEXT_LEVEL_2_CHAR;
28
- const firstLine = text.split(LINE_ENDING_PATTERN)[0] ?? "";
31
+ const [firstLine] = splitLines(text, LINE_ENDING_PATTERN);
29
32
  return `${text}\n${underlineChar.repeat(Math.max(MIN_SETEXT_UNDERLINE_LENGTH, firstLine.length))}`;
30
33
  }
31
34
  const MIN_CODE_FENCE_LENGTH = 3;
@@ -53,19 +56,17 @@ function isQuotableStyle(styleId) {
53
56
  return QUOTABLE_STYLE_IDS.has(styleId) || parseHeadingStyleId(styleId) !== void 0;
54
57
  }
55
58
  function terminatesCleanly(styleId) {
56
- if (styleId === void 0 || styleId === "Quote" || styleId === "HTMLPreformatted") return false;
57
- return styleId === "CodeBlock" || styleId === "MathBlock" || styleId === "HorizontalRule" || parseHeadingStyleId(styleId) !== void 0;
59
+ return styleId === "CodeBlock" || styleId === "MathBlock" || styleId === "HorizontalRule" || styleId !== void 0 && parseHeadingStyleId(styleId) !== void 0;
58
60
  }
59
61
  const BLANK_OR_WHITESPACE_ONLY_LINE = /^[ \t]*$/;
60
62
  function firstContentLineIndex(text) {
61
63
  return text.split(LINE_ENDING_PATTERN).findIndex((line) => !BLANK_OR_WHITESPACE_ONLY_LINE.test(line));
62
64
  }
63
- function leadingIndentColumns(line) {
65
+ function leadingIndentReachesCodeThreshold(line) {
64
66
  let column = 0;
65
- for (const char of line) if (char === " ") column += 1;
66
- else if (char === " ") column += 4 - column % 4;
67
- else break;
68
- return column;
67
+ while (column < line.length && line[column] === " ") column += 1;
68
+ if (column >= 4) return true;
69
+ return line[column] === " ";
69
70
  }
70
71
  const MAX_LEADING_BLANK_LINES_FOR_SETEXT = 1;
71
72
  function interruptsSetextParagraph(line, atBlockStart) {
@@ -94,7 +95,7 @@ function unsafeSetextBreakReason(text) {
94
95
  continue;
95
96
  }
96
97
  sawContentLine = true;
97
- if (leadingIndentColumns(line) >= 4) return "leading-indentation";
98
+ if (leadingIndentReachesCodeThreshold(line)) return "leading-indentation";
98
99
  if (interruptsSetextParagraph(line, true)) return "interrupting-line";
99
100
  precedingLine = line;
100
101
  continue;
@@ -123,7 +124,7 @@ function willRenderAsSetext(paragraph, level, context) {
123
124
  }
124
125
  function canInterruptOpenParagraph(paragraph, context) {
125
126
  const styleId = paragraph.styleId;
126
- if (styleId === void 0 || styleId === "Quote" || styleId === "HTMLPreformatted") return false;
127
+ if (styleId === void 0) return false;
127
128
  if (styleId === "CodeBlock" || styleId === "MathBlock") return true;
128
129
  if (styleId === "HorizontalRule") return context.thematicBreakChar !== SETEXT_LEVEL_2_CHAR;
129
130
  const headingLevel = parseHeadingStyleId(styleId);
@@ -263,24 +264,24 @@ function toEmitItem(item) {
263
264
  function firstBlockCheckbox(first, taskNumId) {
264
265
  if (first.list.checked !== void 0) return {
265
266
  checkboxText: first.list.checked ? "[x] " : "[ ] ",
266
- stripGlyph: false
267
+ strippedFirstBlock: void 0
267
268
  };
268
269
  if (!taskNumId || first.kind !== "paragraph") return {
269
270
  checkboxText: "",
270
- stripGlyph: false
271
+ strippedFirstBlock: void 0
271
272
  };
272
273
  const leading = first.block.runs[0]?.text ?? "";
273
274
  if (leading.startsWith(`☒ `)) return {
274
275
  checkboxText: "[x] ",
275
- stripGlyph: true
276
+ strippedFirstBlock: stripCheckboxRun(first.block)
276
277
  };
277
278
  if (leading.startsWith(`☐ `)) return {
278
279
  checkboxText: "[ ] ",
279
- stripGlyph: true
280
+ strippedFirstBlock: stripCheckboxRun(first.block)
280
281
  };
281
282
  return {
282
283
  checkboxText: "",
283
- stripGlyph: false
284
+ strippedFirstBlock: void 0
284
285
  };
285
286
  }
286
287
  function renderListItemMarker(numId, info, glyph, checkboxText, context) {
@@ -315,7 +316,7 @@ function resolveListGlyph(numId, type, previousSibling, context) {
315
316
  }
316
317
  function consumeSameItemRun(items, from, level, itemId) {
317
318
  let end = from;
318
- while (end < items.length) {
319
+ for (;;) {
319
320
  const candidate = items[end];
320
321
  if (candidate?.list.level !== level || candidate.list.itemId !== itemId) break;
321
322
  end += 1;
@@ -333,7 +334,7 @@ function collectListItem(items, start, level, itemId) {
333
334
  index = ownEnd;
334
335
  for (;;) {
335
336
  let nestedEnd = index;
336
- while (nestedEnd < items.length) {
337
+ for (;;) {
337
338
  const candidateLevel = items[nestedEnd]?.list.level;
338
339
  if (candidateLevel === void 0 || candidateLevel <= level) break;
339
340
  nestedEnd += 1;
@@ -346,7 +347,6 @@ function collectListItem(items, start, level, itemId) {
346
347
  index = nestedEnd;
347
348
  if (itemId === void 0) break;
348
349
  const resumedEnd = consumeSameItemRun(items, index, level, itemId);
349
- if (resumedEnd === index) break;
350
350
  segments.push({
351
351
  kind: "own",
352
352
  blocks: items.slice(index, resumedEnd)
@@ -377,8 +377,8 @@ function regionItemCanInterrupt(item, context) {
377
377
  function lastStyleIdOfRegionItem(item) {
378
378
  return lastStyleIdOf(toEmitItem(item));
379
379
  }
380
- function listRegionItemBody(item, context, stripGlyph) {
381
- if (item.kind === "paragraph") return renderParagraphBody(stripGlyph ? stripCheckboxRun(item.block) : item.block, context);
380
+ function listRegionItemBody(item, context, overrideParagraph) {
381
+ if (item.kind === "paragraph") return renderParagraphBody(overrideParagraph ?? item.block, context);
382
382
  const previousEnclosingItemId = context.enclosingItemId;
383
383
  context.enclosingItemId = item.list.itemId;
384
384
  const body = renderConstruct(item.item, context);
@@ -393,14 +393,14 @@ function renderListRegion(items, context) {
393
393
  const parts = [];
394
394
  let index = 0;
395
395
  let previousSibling;
396
- while (index < items.length) {
396
+ for (;;) {
397
397
  const item = items[index];
398
398
  if (item === void 0) break;
399
399
  const { numId, level, itemId } = item.list;
400
400
  const info = listInfoFor(numId, context);
401
401
  const loose = info?.loose === true;
402
402
  const type = info?.type ?? "bullet";
403
- const glyph = numId === void 0 ? type === "ordered" ? context.orderedDelimiter : context.bulletMarker : resolveListGlyph(numId, type, previousSibling, context);
403
+ const glyph = numId === void 0 ? context.bulletMarker : resolveListGlyph(numId, type, previousSibling, context);
404
404
  if (numId !== void 0) previousSibling = {
405
405
  numId,
406
406
  type,
@@ -409,7 +409,7 @@ function renderListRegion(items, context) {
409
409
  const { segments, next } = collectListItem(items, index, level, itemId);
410
410
  const first = segments[0]?.blocks[0];
411
411
  if (first === void 0) break;
412
- const { checkboxText, stripGlyph } = firstBlockCheckbox(first, info?.task === true);
412
+ const { checkboxText, strippedFirstBlock } = firstBlockCheckbox(first, info?.task === true);
413
413
  const marker = renderListItemMarker(numId, info, glyph, checkboxText, context);
414
414
  const indent = " ".repeat(marker.bareLength);
415
415
  let text = "";
@@ -425,13 +425,13 @@ function renderListRegion(items, context) {
425
425
  }
426
426
  for (const block of segment.blocks) {
427
427
  if (!renderedFirstLine) {
428
- const [firstLine = "", ...restLines] = listRegionItemBody(block, context, stripGlyph).split("\n");
428
+ const [firstLine, ...restLines] = splitLines(listRegionItemBody(block, context, strippedFirstBlock), "\n");
429
429
  text = [`${marker.full}${firstLine}`, ...restLines.map((line) => `${indent}${line}`)].join("\n");
430
430
  renderedFirstLine = true;
431
431
  previousStyleId = lastStyleIdOfRegionItem(block);
432
432
  continue;
433
433
  }
434
- const rendered = listRegionItemBody(block, context, false).split("\n").map((line) => line.length === 0 ? line : `${indent}${line}`).join("\n");
434
+ const rendered = listRegionItemBody(block, context, void 0).split("\n").map((line) => line.length === 0 ? line : `${indent}${line}`).join("\n");
435
435
  const blank = loose || requiresBlankLineBefore(block, previousStyleId, context);
436
436
  text += blank ? `\n\n${rendered}` : `\n${rendered}`;
437
437
  previousStyleId = lastStyleIdOfRegionItem(block);
@@ -467,7 +467,7 @@ function isMaterialisedDivision(item) {
467
467
  function groupConstructItems(blocks, start) {
468
468
  const items = [];
469
469
  let index = start;
470
- while (index < blocks.length) {
470
+ for (;;) {
471
471
  const block = blocks[index];
472
472
  if (block === void 0) break;
473
473
  index += 1;
@@ -496,7 +496,7 @@ function renderFootnoteDefinition(name, body) {
496
496
  const marker = `[^${name}]:`;
497
497
  if (body.length === 0) return marker;
498
498
  const indent = " ".repeat(FOOTNOTE_CONTINUATION_INDENT);
499
- const [firstLine = "", ...restLines] = body.split("\n");
499
+ const [firstLine, ...restLines] = splitLines(body, "\n");
500
500
  return [`${marker} ${firstLine}`, ...restLines.map((line) => line.length === 0 ? line : `${indent}${line}`)].join("\n");
501
501
  }
502
502
  function renderConstruct(item, context) {
@@ -511,13 +511,11 @@ function renderConstruct(item, context) {
511
511
  });
512
512
  return body;
513
513
  }
514
- if (descriptor.kind === "division") {
515
- if (isMaterialisedDivision(item)) {
516
- context.divisionDepth += 1;
517
- const body = renderItems(item.children, context);
518
- context.divisionDepth -= 1;
519
- return body.split("\n").map((line) => line.length === 0 ? ">" : `> ${line}`).join("\n");
520
- }
514
+ if (isMaterialisedDivision(item)) {
515
+ context.divisionDepth += 1;
516
+ const body = renderItems(item.children, context);
517
+ context.divisionDepth -= 1;
518
+ return body.split("\n").map((line) => line.length === 0 ? ">" : `> ${line}`).join("\n");
521
519
  }
522
520
  if (descriptor.kind === "link" && descriptor.target.kind === "external") {
523
521
  const onlyChild = item.children.length === 1 && !isConstructItem(item.children[0]) ? item.children[0].block : void 0;
@@ -548,7 +546,7 @@ function isInheritedListMembership(list, context) {
548
546
  function renderItems(items, context) {
549
547
  const parts = [];
550
548
  let index = 0;
551
- while (index < items.length) {
549
+ for (;;) {
552
550
  const item = items[index];
553
551
  if (item === void 0) break;
554
552
  if (isConstructItem(item)) {
@@ -611,7 +609,7 @@ function emitBlocks(blocks, context) {
611
609
  }
612
610
  function validateRunConstructExtents(blocks) {
613
611
  for (const block of blocks) {
614
- if (block.kind === "paragraph" && block.constructs !== void 0) {
612
+ if (block.kind === "paragraph") {
615
613
  const fault = findRunConstructFault(block);
616
614
  if (fault !== void 0) throw new MarkdownInvalidRunConstructExtentError(fault.kind, fault.index);
617
615
  }
@@ -18,9 +18,9 @@ function delimiterCell(alignment) {
18
18
  function escapeUnescapedPipes(text) {
19
19
  let out = "";
20
20
  let index = 0;
21
- while (index < text.length) {
21
+ while (text.charAt(index) !== "") {
22
22
  const char = text.charAt(index);
23
- if (char === "\\" && index + 1 < text.length) {
23
+ if (char === "\\") {
24
24
  out += char + text.charAt(index + 1);
25
25
  index += 2;
26
26
  continue;
@@ -17,9 +17,9 @@ function delimiterCell(alignment) {
17
17
  function escapeUnescapedPipes(text) {
18
18
  let out = "";
19
19
  let index = 0;
20
- while (index < text.length) {
20
+ while (text.charAt(index) !== "") {
21
21
  const char = text.charAt(index);
22
- if (char === "\\" && index + 1 < text.length) {
22
+ if (char === "\\") {
23
23
  out += char + text.charAt(index + 1);
24
24
  index += 2;
25
25
  continue;
@@ -5,7 +5,6 @@ const OPEN_TAG = `<${TAG_NAME}(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^
5
5
  const CLOSING_TAG = `</${TAG_NAME}\\s*>`;
6
6
  const HTML_TAG_PATTERN = new RegExp(`^(?:${OPEN_TAG}|${CLOSING_TAG}|<!-->|<!--->|<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)`);
7
7
  function matchHtmlTag(text, start) {
8
- if (text.charAt(start) !== "<") return;
9
8
  const match = HTML_TAG_PATTERN.exec(text.slice(start));
10
9
  return match === null ? void 0 : match[0];
11
10
  }
@@ -101,7 +100,6 @@ const HTML_BLOCK_TYPES = [
101
100
  ];
102
101
  const LAST_HTML_BLOCK_TYPE = 7;
103
102
  function matchHtmlBlockStart(line, interruptsParagraph) {
104
- if (!line.startsWith("<")) return;
105
103
  for (const type of HTML_BLOCK_TYPES) {
106
104
  if (type === LAST_HTML_BLOCK_TYPE && interruptsParagraph) continue;
107
105
  if (HTML_BLOCK_START_PATTERNS[type]?.test(line) === true) return type;
package/dist/html/html.js CHANGED
@@ -4,7 +4,6 @@ const OPEN_TAG = `<${TAG_NAME}(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^
4
4
  const CLOSING_TAG = `</${TAG_NAME}\\s*>`;
5
5
  const HTML_TAG_PATTERN = new RegExp(`^(?:${OPEN_TAG}|${CLOSING_TAG}|<!-->|<!--->|<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)`);
6
6
  function matchHtmlTag(text, start) {
7
- if (text.charAt(start) !== "<") return;
8
7
  const match = HTML_TAG_PATTERN.exec(text.slice(start));
9
8
  return match === null ? void 0 : match[0];
10
9
  }
@@ -100,7 +99,6 @@ const HTML_BLOCK_TYPES = [
100
99
  ];
101
100
  const LAST_HTML_BLOCK_TYPE = 7;
102
101
  function matchHtmlBlockStart(line, interruptsParagraph) {
103
- if (!line.startsWith("<")) return;
104
102
  for (const type of HTML_BLOCK_TYPES) {
105
103
  if (type === LAST_HTML_BLOCK_TYPE && interruptsParagraph) continue;
106
104
  if (HTML_BLOCK_START_PATTERNS[type]?.test(line) === true) return type;
@@ -40,7 +40,7 @@ function escapeHref(href) {
40
40
  let result = "";
41
41
  for (const byte of bytes) {
42
42
  const char = String.fromCharCode(byte);
43
- if (byte < 128 && (ALPHANUMERIC_PATTERN.test(char) || HREF_SAFE_PUNCTUATION.has(char))) {
43
+ if (ALPHANUMERIC_PATTERN.test(char) || HREF_SAFE_PUNCTUATION.has(char)) {
44
44
  result += char;
45
45
  continue;
46
46
  }
@@ -67,7 +67,7 @@ function renderTaskCheckbox(checked) {
67
67
  }
68
68
  function renderInline(node) {
69
69
  switch (node.type) {
70
- case "text": return escapeHtml(node.value);
70
+ case "text":
71
71
  case "entity": return escapeHtml(node.value);
72
72
  case "codeSpan": return `<code>${escapeHtml(node.literal)}</code>`;
73
73
  case "emphasis": return `<em>${renderInlines(node.children)}</em>`;
@@ -127,7 +127,6 @@ var HtmlRenderer = class {
127
127
  this.cr();
128
128
  this.out += "<blockquote>\n";
129
129
  this.render(node.children, false);
130
- this.cr();
131
130
  this.out += "</blockquote>\n";
132
131
  return;
133
132
  case "list":
@@ -139,23 +138,17 @@ var HtmlRenderer = class {
139
138
  case "mathBlock":
140
139
  this.cr();
141
140
  this.out += `$$\n${escapeHtml(node.literal)}\n$$\n`;
142
- this.cr();
143
141
  return;
144
142
  case "footnoteDefinition":
145
143
  this.cr();
146
144
  this.out += `${escapeHtml(`[^${node.label}]:`)}\n`;
147
145
  this.render(node.children, false);
148
- this.cr();
149
146
  return;
150
- case "document":
151
- case "listItem":
152
- case "tableRow":
153
- case "tableCell": return;
154
147
  }
155
148
  }
156
149
  renderCodeBlock(infoString, literal) {
157
150
  this.cr();
158
- const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0] ?? "";
151
+ const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0];
159
152
  const attribute = language.length === 0 ? "" : ` class="language-${escapeHtml(language)}"`;
160
153
  this.out += `<pre><code${attribute}>${escapeHtml(literal)}</code></pre>\n`;
161
154
  }
@@ -165,7 +158,6 @@ var HtmlRenderer = class {
165
158
  const orderedOpenTag = start === DEFAULT_ORDERED_LIST_START ? "<ol>" : `<ol start="${String(start)}">`;
166
159
  this.out += `${node.markerType === "bullet" ? "<ul>" : orderedOpenTag}\n`;
167
160
  for (const item of node.children) {
168
- this.cr();
169
161
  this.out += "<li>";
170
162
  if (item.checked !== void 0) this.out += renderTaskCheckbox(item.checked);
171
163
  this.render(item.children, node.tight);
@@ -39,7 +39,7 @@ function escapeHref(href) {
39
39
  let result = "";
40
40
  for (const byte of bytes) {
41
41
  const char = String.fromCharCode(byte);
42
- if (byte < 128 && (ALPHANUMERIC_PATTERN.test(char) || HREF_SAFE_PUNCTUATION.has(char))) {
42
+ if (ALPHANUMERIC_PATTERN.test(char) || HREF_SAFE_PUNCTUATION.has(char)) {
43
43
  result += char;
44
44
  continue;
45
45
  }
@@ -66,7 +66,7 @@ function renderTaskCheckbox(checked) {
66
66
  }
67
67
  function renderInline(node) {
68
68
  switch (node.type) {
69
- case "text": return escapeHtml(node.value);
69
+ case "text":
70
70
  case "entity": return escapeHtml(node.value);
71
71
  case "codeSpan": return `<code>${escapeHtml(node.literal)}</code>`;
72
72
  case "emphasis": return `<em>${renderInlines(node.children)}</em>`;
@@ -126,7 +126,6 @@ var HtmlRenderer = class {
126
126
  this.cr();
127
127
  this.out += "<blockquote>\n";
128
128
  this.render(node.children, false);
129
- this.cr();
130
129
  this.out += "</blockquote>\n";
131
130
  return;
132
131
  case "list":
@@ -138,23 +137,17 @@ var HtmlRenderer = class {
138
137
  case "mathBlock":
139
138
  this.cr();
140
139
  this.out += `$$\n${escapeHtml(node.literal)}\n$$\n`;
141
- this.cr();
142
140
  return;
143
141
  case "footnoteDefinition":
144
142
  this.cr();
145
143
  this.out += `${escapeHtml(`[^${node.label}]:`)}\n`;
146
144
  this.render(node.children, false);
147
- this.cr();
148
145
  return;
149
- case "document":
150
- case "listItem":
151
- case "tableRow":
152
- case "tableCell": return;
153
146
  }
154
147
  }
155
148
  renderCodeBlock(infoString, literal) {
156
149
  this.cr();
157
- const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0] ?? "";
150
+ const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0];
158
151
  const attribute = language.length === 0 ? "" : ` class="language-${escapeHtml(language)}"`;
159
152
  this.out += `<pre><code${attribute}>${escapeHtml(literal)}</code></pre>\n`;
160
153
  }
@@ -164,7 +157,6 @@ var HtmlRenderer = class {
164
157
  const orderedOpenTag = start === DEFAULT_ORDERED_LIST_START ? "<ol>" : `<ol start="${String(start)}">`;
165
158
  this.out += `${node.markerType === "bullet" ? "<ul>" : orderedOpenTag}\n`;
166
159
  for (const item of node.children) {
167
- this.cr();
168
160
  this.out += "<li>";
169
161
  if (item.checked !== void 0) this.out += renderTaskCheckbox(item.checked);
170
162
  this.render(item.children, node.tight);
@@ -1,52 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/image/image.ts
3
- const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4
- const BASE64_DECODE = (() => {
5
- const map = (/* @__PURE__ */ new Uint8Array(256)).fill(255);
6
- for (let index = 0; index < 64; index += 1) map[BASE64_TABLE.charCodeAt(index)] = index;
7
- return map;
8
- })();
9
- const BASE64_PADDING_CODE = 61;
10
- function bytesToBase64(bytes) {
11
- let out = "";
12
- const { length } = bytes;
13
- for (let index = 0; index < length; index += 3) {
14
- const b0 = bytes[index];
15
- const b1 = index + 1 < length ? bytes[index + 1] : 0;
16
- const b2 = index + 2 < length ? bytes[index + 2] : 0;
17
- out += BASE64_TABLE.charAt(b0 >> 2);
18
- out += BASE64_TABLE.charAt((b0 & 3) << 4 | b1 >> 4);
19
- out += index + 1 < length ? BASE64_TABLE.charAt((b1 & 15) << 2 | b2 >> 6) : "=";
20
- out += index + 2 < length ? BASE64_TABLE.charAt(b2 & 63) : "=";
21
- }
22
- return out;
23
- }
24
- function base64ToBytes(base64) {
25
- const clean = base64.replace(/[^A-Za-z0-9+/=]/g, "");
26
- const { length } = clean;
27
- const out = new Uint8Array(Math.floor(length * 3 / 4));
28
- let position = 0;
29
- for (let index = 0; index < length; index += 4) {
30
- const c0 = BASE64_DECODE[clean.charCodeAt(index)];
31
- const c1 = BASE64_DECODE[clean.charCodeAt(index + 1)];
32
- const code2 = clean.charCodeAt(index + 2);
33
- const code3 = clean.charCodeAt(index + 3);
34
- if (c0 === 255 || c1 === 255) throw new Error("invalid base64 input");
35
- out[position] = c0 << 2 | c1 >> 4;
36
- position += 1;
37
- if (code2 !== BASE64_PADDING_CODE) {
38
- const d2 = BASE64_DECODE[code2];
39
- out[position] = (c1 & 15) << 4 | d2 >> 2;
40
- position += 1;
41
- if (code3 !== BASE64_PADDING_CODE) {
42
- const d3 = BASE64_DECODE[code3];
43
- out[position] = (d2 & 3) << 6 | d3;
44
- position += 1;
45
- }
46
- }
47
- }
48
- return out.subarray(0, position);
49
- }
50
3
  function readUint16BE(bytes, offset) {
51
4
  return (bytes[offset] << 8 | bytes[offset + 1]) & 65535;
52
5
  }
@@ -123,7 +76,5 @@ function readImageDimensions(bytes) {
123
76
  return readJpegDimensions(bytes);
124
77
  }
125
78
  //#endregion
126
- exports.base64ToBytes = base64ToBytes;
127
- exports.bytesToBase64 = bytesToBase64;
128
79
  exports.detectImageFormat = detectImageFormat;
129
80
  exports.readImageDimensions = readImageDimensions;
@@ -1,2 +1,2 @@
1
- import { a as detectImageFormat, i as bytesToBase64, n as ImageFormat, o as readImageDimensions, r as base64ToBytes, t as ImageDimensions } from "../image-BtmTG4_a.cjs";
2
- export { ImageDimensions, ImageFormat, base64ToBytes, bytesToBase64, detectImageFormat, readImageDimensions };
1
+ import { i as readImageDimensions, n as ImageFormat, r as detectImageFormat, t as ImageDimensions } from "../image-83yql5ES.cjs";
2
+ export { ImageDimensions, ImageFormat, detectImageFormat, readImageDimensions };
@@ -1,2 +1,2 @@
1
- import { a as detectImageFormat, i as bytesToBase64, n as ImageFormat, o as readImageDimensions, r as base64ToBytes, t as ImageDimensions } from "../image-BtmTG4_a.js";
2
- export { ImageDimensions, ImageFormat, base64ToBytes, bytesToBase64, detectImageFormat, readImageDimensions };
1
+ import { i as readImageDimensions, n as ImageFormat, r as detectImageFormat, t as ImageDimensions } from "../image-83yql5ES.js";
2
+ export { ImageDimensions, ImageFormat, detectImageFormat, readImageDimensions };
@@ -1,51 +1,4 @@
1
1
  //#region src/image/image.ts
2
- const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3
- const BASE64_DECODE = (() => {
4
- const map = (/* @__PURE__ */ new Uint8Array(256)).fill(255);
5
- for (let index = 0; index < 64; index += 1) map[BASE64_TABLE.charCodeAt(index)] = index;
6
- return map;
7
- })();
8
- const BASE64_PADDING_CODE = 61;
9
- function bytesToBase64(bytes) {
10
- let out = "";
11
- const { length } = bytes;
12
- for (let index = 0; index < length; index += 3) {
13
- const b0 = bytes[index];
14
- const b1 = index + 1 < length ? bytes[index + 1] : 0;
15
- const b2 = index + 2 < length ? bytes[index + 2] : 0;
16
- out += BASE64_TABLE.charAt(b0 >> 2);
17
- out += BASE64_TABLE.charAt((b0 & 3) << 4 | b1 >> 4);
18
- out += index + 1 < length ? BASE64_TABLE.charAt((b1 & 15) << 2 | b2 >> 6) : "=";
19
- out += index + 2 < length ? BASE64_TABLE.charAt(b2 & 63) : "=";
20
- }
21
- return out;
22
- }
23
- function base64ToBytes(base64) {
24
- const clean = base64.replace(/[^A-Za-z0-9+/=]/g, "");
25
- const { length } = clean;
26
- const out = new Uint8Array(Math.floor(length * 3 / 4));
27
- let position = 0;
28
- for (let index = 0; index < length; index += 4) {
29
- const c0 = BASE64_DECODE[clean.charCodeAt(index)];
30
- const c1 = BASE64_DECODE[clean.charCodeAt(index + 1)];
31
- const code2 = clean.charCodeAt(index + 2);
32
- const code3 = clean.charCodeAt(index + 3);
33
- if (c0 === 255 || c1 === 255) throw new Error("invalid base64 input");
34
- out[position] = c0 << 2 | c1 >> 4;
35
- position += 1;
36
- if (code2 !== BASE64_PADDING_CODE) {
37
- const d2 = BASE64_DECODE[code2];
38
- out[position] = (c1 & 15) << 4 | d2 >> 2;
39
- position += 1;
40
- if (code3 !== BASE64_PADDING_CODE) {
41
- const d3 = BASE64_DECODE[code3];
42
- out[position] = (d2 & 3) << 6 | d3;
43
- position += 1;
44
- }
45
- }
46
- }
47
- return out.subarray(0, position);
48
- }
49
2
  function readUint16BE(bytes, offset) {
50
3
  return (bytes[offset] << 8 | bytes[offset + 1]) & 65535;
51
4
  }
@@ -122,4 +75,4 @@ function readImageDimensions(bytes) {
122
75
  return readJpegDimensions(bytes);
123
76
  }
124
77
  //#endregion
125
- export { base64ToBytes, bytesToBase64, detectImageFormat, readImageDimensions };
78
+ export { detectImageFormat, readImageDimensions };
@@ -4,9 +4,7 @@ interface ImageDimensions {
4
4
  readonly heightPx: number;
5
5
  }
6
6
  type ImageFormat = "png" | "jpeg";
7
- declare function bytesToBase64(bytes: Uint8Array): string;
8
- declare function base64ToBytes(base64: string): Uint8Array;
9
7
  declare function detectImageFormat(bytes: Uint8Array): ImageFormat | undefined;
10
8
  declare function readImageDimensions(bytes: Uint8Array): ImageDimensions | undefined;
11
9
  //#endregion
12
- export { detectImageFormat as a, bytesToBase64 as i, ImageFormat as n, readImageDimensions as o, base64ToBytes as r, ImageDimensions as t };
10
+ export { readImageDimensions as i, ImageFormat as n, detectImageFormat as r, ImageDimensions as t };
@@ -4,9 +4,7 @@ interface ImageDimensions {
4
4
  readonly heightPx: number;
5
5
  }
6
6
  type ImageFormat = "png" | "jpeg";
7
- declare function bytesToBase64(bytes: Uint8Array): string;
8
- declare function base64ToBytes(base64: string): Uint8Array;
9
7
  declare function detectImageFormat(bytes: Uint8Array): ImageFormat | undefined;
10
8
  declare function readImageDimensions(bytes: Uint8Array): ImageDimensions | undefined;
11
9
  //#endregion
12
- export { detectImageFormat as a, bytesToBase64 as i, ImageFormat as n, readImageDimensions as o, base64ToBytes as r, ImageDimensions as t };
10
+ export { readImageDimensions as i, ImageFormat as n, detectImageFormat as r, ImageDimensions as t };
@@ -1,4 +1,4 @@
1
- import { n as ImageFormat } from "./image-BtmTG4_a.cjs";
1
+ import { n as ImageFormat } from "./image-83yql5ES.cjs";
2
2
  //#region src/lower/image.d.ts
3
3
  interface MarkdownImageResolveContext {
4
4
  readonly alt: string;
@@ -1,4 +1,4 @@
1
- import { n as ImageFormat } from "./image-BtmTG4_a.js";
1
+ import { n as ImageFormat } from "./image-83yql5ES.js";
2
2
  //#region src/lower/image.d.ts
3
3
  interface MarkdownImageResolveContext {
4
4
  readonly alt: string;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as MarkdownInputTooLargeError, c as MarkdownNestingLimitExceededError, d as MarkdownUnbalancedConstructMarkersError, f as MarkdownUnsupportedDocumentKindError, i as MarkdownDiagnosticSink, m as NOOP_MARKDOWN_DIAGNOSTIC_SINK, n as MarkdownDiagnosticCodes, o as MarkdownInvalidRunConstructExtentError, p as MarkdownWriteError, r as MarkdownDiagnosticSeverity, s as MarkdownInvalidUtf8Error, t as MarkdownDiagnostic, u as MarkdownParseError } from "./diagnostics-CjfBoW4K.cjs";
2
2
  import { MarkdownBytesSchema, markdownCodec, markdownContentCodec } from "./codec.cjs";
3
- import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-B5L0HpAJ.cjs";
3
+ import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-B6p0Ovgy.cjs";
4
4
  import { MarkdownBulletListMarker, MarkdownCodeFenceChar, MarkdownEmphasisMarker, MarkdownHeadingStyle, MarkdownLineEnding, MarkdownOrderedListDelimiter, MarkdownThematicBreakChar, ReadMarkdownOptions, WriteMarkdownOptions, WriteMarkdownStyleOptions } from "./options/options.cjs";
5
5
  import { ReadMarkdownContentResult, ReadMarkdownResult, readMarkdown, readMarkdownContent } from "./read.cjs";
6
6
  import { writeMarkdown, writeMarkdownContent } from "./write.cjs";
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as MarkdownInputTooLargeError, c as MarkdownNestingLimitExceededError, d as MarkdownUnbalancedConstructMarkersError, f as MarkdownUnsupportedDocumentKindError, i as MarkdownDiagnosticSink, m as NOOP_MARKDOWN_DIAGNOSTIC_SINK, n as MarkdownDiagnosticCodes, o as MarkdownInvalidRunConstructExtentError, p as MarkdownWriteError, r as MarkdownDiagnosticSeverity, s as MarkdownInvalidUtf8Error, t as MarkdownDiagnostic, u as MarkdownParseError } from "./diagnostics-CjfBoW4K.js";
2
2
  import { MarkdownBytesSchema, markdownCodec, markdownContentCodec } from "./codec.js";
3
- import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-C390OIB3.js";
3
+ import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-gR1vISI0.js";
4
4
  import { MarkdownBulletListMarker, MarkdownCodeFenceChar, MarkdownEmphasisMarker, MarkdownHeadingStyle, MarkdownLineEnding, MarkdownOrderedListDelimiter, MarkdownThematicBreakChar, ReadMarkdownOptions, WriteMarkdownOptions, WriteMarkdownStyleOptions } from "./options/options.js";
5
5
  import { ReadMarkdownContentResult, ReadMarkdownResult, readMarkdown, readMarkdownContent } from "./read.js";
6
6
  import { writeMarkdown, writeMarkdownContent } from "./write.js";
@@ -18,8 +18,7 @@ function isAsciiControl(char) {
18
18
  return code <= 31 || code === 127;
19
19
  }
20
20
  function containsAsciiControlOrSpace(text) {
21
- for (let index = 0; index < text.length; index += 1) if (isAsciiControl(text.charAt(index)) || text.charAt(index) === " ") return true;
22
- return false;
21
+ return text.split("").some((char) => isAsciiControl(char) || char === " ");
23
22
  }
24
23
  function isMarkdownSpace(char) {
25
24
  return char === " " || char === " " || char === "\n" || char === "\r";
@@ -27,7 +26,7 @@ function isMarkdownSpace(char) {
27
26
  function codePointBefore(text, index) {
28
27
  if (index <= 0) return "\n";
29
28
  const low = text.charCodeAt(index - 1);
30
- if (index >= 2 && low >= 56320 && low <= 57343) {
29
+ if (low >= 56320 && low <= 57343) {
31
30
  const high = text.charCodeAt(index - 2);
32
31
  if (high >= 55296 && high <= 56319) return text.slice(index - 2, index);
33
32
  }
@@ -35,9 +34,7 @@ function codePointBefore(text, index) {
35
34
  }
36
35
  function codePointAt(text, index) {
37
36
  if (index >= text.length) return "\n";
38
- const code = text.codePointAt(index);
39
- if (code === void 0) return "\n";
40
- return String.fromCodePoint(code);
37
+ return String.fromCodePoint(text.codePointAt(index));
41
38
  }
42
39
  //#endregion
43
40
  exports.codePointAt = codePointAt;
@@ -17,8 +17,7 @@ function isAsciiControl(char) {
17
17
  return code <= 31 || code === 127;
18
18
  }
19
19
  function containsAsciiControlOrSpace(text) {
20
- for (let index = 0; index < text.length; index += 1) if (isAsciiControl(text.charAt(index)) || text.charAt(index) === " ") return true;
21
- return false;
20
+ return text.split("").some((char) => isAsciiControl(char) || char === " ");
22
21
  }
23
22
  function isMarkdownSpace(char) {
24
23
  return char === " " || char === " " || char === "\n" || char === "\r";
@@ -26,7 +25,7 @@ function isMarkdownSpace(char) {
26
25
  function codePointBefore(text, index) {
27
26
  if (index <= 0) return "\n";
28
27
  const low = text.charCodeAt(index - 1);
29
- if (index >= 2 && low >= 56320 && low <= 57343) {
28
+ if (low >= 56320 && low <= 57343) {
30
29
  const high = text.charCodeAt(index - 2);
31
30
  if (high >= 55296 && high <= 56319) return text.slice(index - 2, index);
32
31
  }
@@ -34,9 +33,7 @@ function codePointBefore(text, index) {
34
33
  }
35
34
  function codePointAt(text, index) {
36
35
  if (index >= text.length) return "\n";
37
- const code = text.codePointAt(index);
38
- if (code === void 0) return "\n";
39
- return String.fromCodePoint(code);
36
+ return String.fromCodePoint(text.codePointAt(index));
40
37
  }
41
38
  //#endregion
42
39
  export { codePointAt, codePointBefore, containsAsciiControlOrSpace, isAsciiControl, isAsciiPunctuation, isMarkdownSpace, isUnicodePunctuation, isUnicodeWhitespace };