markdown-codec 6.7.5 → 6.7.6

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.
@@ -37,7 +37,7 @@ const OPAQUE_KINDS = /* @__PURE__ */ new Set([
37
37
  "autolink"
38
38
  ]);
39
39
  function isWhitespace(char) {
40
- return char === "" || char === " " || char === " " || char === "\n" || char === "\r" || char === "\f";
40
+ return char === " " || char === " " || char === "\n" || char === "\r" || char === "\f";
41
41
  }
42
42
  function isValidStartBoundary(text, index) {
43
43
  if (index === 0) return true;
@@ -54,28 +54,31 @@ function trimTrailingPunctuation(candidate) {
54
54
  let end = candidate.length;
55
55
  for (;;) {
56
56
  const before = end;
57
- while (end > 0 && TRAILING_PUNCTUATION.has(candidate.charAt(end - 1))) end -= 1;
58
- if (end > 0 && candidate.charAt(end - 1) === ")") {
57
+ while (TRAILING_PUNCTUATION.has(candidate.charAt(end - 1))) end -= 1;
58
+ if (candidate.charAt(end - 1) === ")") {
59
59
  const slice = candidate.slice(0, end);
60
60
  if (slice.split(")").length > slice.split("(").length) end -= 1;
61
61
  }
62
- if (end > 0 && candidate.charAt(end - 1) === ";") {
63
- const entityTail = ENTITY_TAIL_PATTERN.exec(candidate.slice(0, end));
64
- if (entityTail !== null) end -= entityTail[0].length;
65
- }
62
+ const entityTail = ENTITY_TAIL_PATTERN.exec(candidate.slice(0, end));
63
+ if (entityTail !== null) end -= entityTail[0].length;
66
64
  if (end === before) return candidate.slice(0, end);
67
65
  }
68
66
  }
69
67
  function scanRawCandidate(text, start) {
70
68
  let end = start;
71
- while (end < text.length && !isWhitespace(text.charAt(end)) && text.charAt(end) !== "<") end += 1;
72
- return text.slice(start, end);
69
+ for (;;) {
70
+ const char = text.charAt(end);
71
+ if (char === "" || isWhitespace(char) || char === "<") return text.slice(start, end);
72
+ end += 1;
73
+ }
73
74
  }
74
75
  function matchPrefixed(text, index, prefixLength, destinationPrefix, requireValidDomain) {
75
76
  const trimmed = trimTrailingPunctuation(scanRawCandidate(text, index));
76
- if (trimmed.length <= prefixLength) return;
77
+ const afterPrefix = trimmed.slice(prefixLength);
78
+ if (afterPrefix === "") return;
77
79
  if (requireValidDomain) {
78
- if (!isValidDomain(trimmed.slice(prefixLength).split(/[/?#]/)[0] ?? "")) return;
80
+ const domain = afterPrefix.split(/[/?#]/)[0];
81
+ if (!isValidDomain(domain)) return;
79
82
  }
80
83
  return {
81
84
  text: trimmed,
@@ -85,17 +88,17 @@ function matchPrefixed(text, index, prefixLength, destinationPrefix, requireVali
85
88
  }
86
89
  function scanEmailDomain(text, start) {
87
90
  let end = start;
88
- while (end < text.length && EMAIL_DOMAIN_PATTERN.test(text.charAt(end))) end += 1;
91
+ while (EMAIL_DOMAIN_PATTERN.test(text.charAt(end))) end += 1;
89
92
  return text.slice(start, end);
90
93
  }
91
94
  function matchEmailAt(text, atIndex) {
92
95
  let start = atIndex;
93
- while (start > 0 && EMAIL_LOCAL_PART_PATTERN.test(text.charAt(start - 1))) start -= 1;
96
+ while (EMAIL_LOCAL_PART_PATTERN.test(text.charAt(start - 1))) start -= 1;
94
97
  if (start === atIndex || !isValidStartBoundary(text, start)) return;
95
98
  const local = text.slice(start, atIndex);
96
99
  if (local.startsWith(".") || local.endsWith(".")) return;
97
100
  const domain = scanEmailDomain(text, atIndex + 1).replace(/\.+$/, "");
98
- if (domain.endsWith("-") || domain.endsWith("_") || !isValidDomain(domain)) return;
101
+ if (domain.endsWith("-") || !isValidDomain(domain)) return;
99
102
  const address = `${local}@${domain}`;
100
103
  return {
101
104
  text: address,
@@ -117,11 +120,10 @@ function expandTextNode(node) {
117
120
  const text = node.literal;
118
121
  let cursor = 0;
119
122
  let anchor = node;
120
- let matches = 0;
121
123
  let index = 0;
122
- while (index < text.length) {
124
+ while (text.charAt(index) !== "") {
123
125
  const found = findAutolinkAt(text, index);
124
- if (found === void 0 || found.start < cursor) {
126
+ if (found === void 0) {
125
127
  index += 1;
126
128
  continue;
127
129
  }
@@ -136,10 +138,9 @@ function expandTextNode(node) {
136
138
  anchor.insertAfter(link);
137
139
  anchor = link;
138
140
  cursor = found.start + found.text.length;
139
- matches += 1;
140
141
  index = cursor;
141
142
  }
142
- if (matches === 0) return;
143
+ if (anchor === node) return;
143
144
  if (cursor < text.length) anchor.insertAfter(require_inline_node.createTextNode(text.slice(cursor)));
144
145
  node.unlink();
145
146
  }
@@ -36,7 +36,7 @@ const OPAQUE_KINDS = /* @__PURE__ */ new Set([
36
36
  "autolink"
37
37
  ]);
38
38
  function isWhitespace(char) {
39
- return char === "" || char === " " || char === " " || char === "\n" || char === "\r" || char === "\f";
39
+ return char === " " || char === " " || char === "\n" || char === "\r" || char === "\f";
40
40
  }
41
41
  function isValidStartBoundary(text, index) {
42
42
  if (index === 0) return true;
@@ -53,28 +53,31 @@ function trimTrailingPunctuation(candidate) {
53
53
  let end = candidate.length;
54
54
  for (;;) {
55
55
  const before = end;
56
- while (end > 0 && TRAILING_PUNCTUATION.has(candidate.charAt(end - 1))) end -= 1;
57
- if (end > 0 && candidate.charAt(end - 1) === ")") {
56
+ while (TRAILING_PUNCTUATION.has(candidate.charAt(end - 1))) end -= 1;
57
+ if (candidate.charAt(end - 1) === ")") {
58
58
  const slice = candidate.slice(0, end);
59
59
  if (slice.split(")").length > slice.split("(").length) end -= 1;
60
60
  }
61
- if (end > 0 && candidate.charAt(end - 1) === ";") {
62
- const entityTail = ENTITY_TAIL_PATTERN.exec(candidate.slice(0, end));
63
- if (entityTail !== null) end -= entityTail[0].length;
64
- }
61
+ const entityTail = ENTITY_TAIL_PATTERN.exec(candidate.slice(0, end));
62
+ if (entityTail !== null) end -= entityTail[0].length;
65
63
  if (end === before) return candidate.slice(0, end);
66
64
  }
67
65
  }
68
66
  function scanRawCandidate(text, start) {
69
67
  let end = start;
70
- while (end < text.length && !isWhitespace(text.charAt(end)) && text.charAt(end) !== "<") end += 1;
71
- return text.slice(start, end);
68
+ for (;;) {
69
+ const char = text.charAt(end);
70
+ if (char === "" || isWhitespace(char) || char === "<") return text.slice(start, end);
71
+ end += 1;
72
+ }
72
73
  }
73
74
  function matchPrefixed(text, index, prefixLength, destinationPrefix, requireValidDomain) {
74
75
  const trimmed = trimTrailingPunctuation(scanRawCandidate(text, index));
75
- if (trimmed.length <= prefixLength) return;
76
+ const afterPrefix = trimmed.slice(prefixLength);
77
+ if (afterPrefix === "") return;
76
78
  if (requireValidDomain) {
77
- if (!isValidDomain(trimmed.slice(prefixLength).split(/[/?#]/)[0] ?? "")) return;
79
+ const domain = afterPrefix.split(/[/?#]/)[0];
80
+ if (!isValidDomain(domain)) return;
78
81
  }
79
82
  return {
80
83
  text: trimmed,
@@ -84,17 +87,17 @@ function matchPrefixed(text, index, prefixLength, destinationPrefix, requireVali
84
87
  }
85
88
  function scanEmailDomain(text, start) {
86
89
  let end = start;
87
- while (end < text.length && EMAIL_DOMAIN_PATTERN.test(text.charAt(end))) end += 1;
90
+ while (EMAIL_DOMAIN_PATTERN.test(text.charAt(end))) end += 1;
88
91
  return text.slice(start, end);
89
92
  }
90
93
  function matchEmailAt(text, atIndex) {
91
94
  let start = atIndex;
92
- while (start > 0 && EMAIL_LOCAL_PART_PATTERN.test(text.charAt(start - 1))) start -= 1;
95
+ while (EMAIL_LOCAL_PART_PATTERN.test(text.charAt(start - 1))) start -= 1;
93
96
  if (start === atIndex || !isValidStartBoundary(text, start)) return;
94
97
  const local = text.slice(start, atIndex);
95
98
  if (local.startsWith(".") || local.endsWith(".")) return;
96
99
  const domain = scanEmailDomain(text, atIndex + 1).replace(/\.+$/, "");
97
- if (domain.endsWith("-") || domain.endsWith("_") || !isValidDomain(domain)) return;
100
+ if (domain.endsWith("-") || !isValidDomain(domain)) return;
98
101
  const address = `${local}@${domain}`;
99
102
  return {
100
103
  text: address,
@@ -116,11 +119,10 @@ function expandTextNode(node) {
116
119
  const text = node.literal;
117
120
  let cursor = 0;
118
121
  let anchor = node;
119
- let matches = 0;
120
122
  let index = 0;
121
- while (index < text.length) {
123
+ while (text.charAt(index) !== "") {
122
124
  const found = findAutolinkAt(text, index);
123
- if (found === void 0 || found.start < cursor) {
125
+ if (found === void 0) {
124
126
  index += 1;
125
127
  continue;
126
128
  }
@@ -135,10 +137,9 @@ function expandTextNode(node) {
135
137
  anchor.insertAfter(link);
136
138
  anchor = link;
137
139
  cursor = found.start + found.text.length;
138
- matches += 1;
139
140
  index = cursor;
140
141
  }
141
- if (matches === 0) return;
142
+ if (anchor === node) return;
142
143
  if (cursor < text.length) anchor.insertAfter(createTextNode(text.slice(cursor)));
143
144
  node.unlink();
144
145
  }
@@ -12,7 +12,7 @@ const require_inline_math = require("./math.cjs");
12
12
  const PLAIN_TEXT_PATTERN = /[^\n`[\]\\!<&*_~]+/y;
13
13
  const URI_AUTOLINK_PATTERN = /<[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>]*>/y;
14
14
  const EMAIL_AUTOLINK_PATTERN = /<([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/y;
15
- const HARD_BREAK_SPACES = " ";
15
+ const HARD_BREAK_SPACE_COUNT = 2;
16
16
  const EMPTY_LABEL_LENGTH = 2;
17
17
  function stripOneSurroundingSpace(content) {
18
18
  if (content.startsWith(" ") && content.endsWith(" ") && /[^ ]/.test(content)) return content.slice(1, content.length - 1);
@@ -45,6 +45,13 @@ var InlineParser = class {
45
45
  return this.container;
46
46
  }
47
47
  step() {
48
+ PLAIN_TEXT_PATTERN.lastIndex = this.pos;
49
+ const plain = PLAIN_TEXT_PATTERN.exec(this.text);
50
+ if (plain !== null) {
51
+ this.appendText(plain[0]);
52
+ this.pos += plain[0].length;
53
+ return;
54
+ }
48
55
  const char = this.text.charAt(this.pos);
49
56
  switch (char) {
50
57
  case "\n":
@@ -71,12 +78,9 @@ var InlineParser = class {
71
78
  case "]":
72
79
  this.parseCloseBracket();
73
80
  return;
74
- default:
75
- if (require_inline_delimiter.isDelimiterChar(char)) {
76
- this.parseDelimiterRun(char);
77
- return;
78
- }
79
- this.parsePlainText();
81
+ case "*":
82
+ case "_":
83
+ case "~": this.parseDelimiterRun(char);
80
84
  }
81
85
  }
82
86
  appendText(literal) {
@@ -84,25 +88,16 @@ var InlineParser = class {
84
88
  this.container.appendChild(node);
85
89
  return node;
86
90
  }
87
- parsePlainText() {
88
- PLAIN_TEXT_PATTERN.lastIndex = this.pos;
89
- const match = PLAIN_TEXT_PATTERN.exec(this.text);
90
- if (match === null) {
91
- this.appendText(this.text.charAt(this.pos));
92
- this.pos += 1;
93
- return;
94
- }
95
- this.appendText(match[0]);
96
- this.pos += match[0].length;
97
- }
98
91
  parseLineBreak() {
99
92
  this.pos += 1;
100
93
  const last = this.container.lastChild;
101
- if (last?.kind === "text" && last.literal.endsWith(" ")) {
102
- const hard = last.literal.endsWith(HARD_BREAK_SPACES);
103
- last.literal = last.literal.replace(/ +$/, "");
104
- this.container.appendChild(new require_inline_node.InlineNode(hard ? "hardBreak" : "softBreak"));
105
- } else this.container.appendChild(new require_inline_node.InlineNode("softBreak"));
94
+ let hard = false;
95
+ if (last?.kind === "text") {
96
+ const withoutTrailingSpaces = last.literal.replace(/ +$/, "");
97
+ hard = last.literal.length - withoutTrailingSpaces.length >= HARD_BREAK_SPACE_COUNT;
98
+ last.literal = withoutTrailingSpaces;
99
+ }
100
+ this.container.appendChild(new require_inline_node.InlineNode(hard ? "hardBreak" : "softBreak"));
106
101
  while (this.text.charAt(this.pos) === " ") this.pos += 1;
107
102
  }
108
103
  parseBackslash() {
@@ -114,15 +109,13 @@ var InlineParser = class {
114
109
  this.container.appendChild(new require_inline_node.InlineNode("hardBreak"));
115
110
  return;
116
111
  }
117
- if (next === "(") {
118
- const span = require_inline_math.matchMathInlineSpan(this.text, backslashIndex);
119
- if (span !== void 0) {
120
- const node = new require_inline_node.InlineNode("mathInline");
121
- node.literal = span.slice(2, span.length - 2);
122
- this.container.appendChild(node);
123
- this.pos = backslashIndex + span.length;
124
- return;
125
- }
112
+ const span = require_inline_math.matchMathInlineSpan(this.text, backslashIndex);
113
+ if (span !== void 0) {
114
+ const node = new require_inline_node.InlineNode("mathInline");
115
+ node.literal = span.slice(2, span.length - 2);
116
+ this.container.appendChild(node);
117
+ this.pos = backslashIndex + span.length;
118
+ return;
126
119
  }
127
120
  if (require_inline_chars.isAsciiPunctuation(next)) {
128
121
  this.appendText(next);
@@ -137,7 +130,7 @@ var InlineParser = class {
137
130
  while (this.text.charAt(start + openLength) === "`") openLength += 1;
138
131
  const afterOpen = start + openLength;
139
132
  let scan = afterOpen;
140
- while (scan < this.text.length) {
133
+ while (this.text.charAt(scan) !== "") {
141
134
  if (this.text.charAt(scan) !== "`") {
142
135
  scan += 1;
143
136
  continue;
@@ -219,7 +212,7 @@ var InlineParser = class {
219
212
  }
220
213
  const node = this.appendText(this.text.slice(this.pos, this.pos + run.count));
221
214
  this.pos += run.count;
222
- if (run.canOpen || run.canClose) this.delimiters.push(char, run, node);
215
+ this.delimiters.push(char, run, node);
223
216
  }
224
217
  parseLiteralRun(char) {
225
218
  let length = 0;
@@ -343,7 +336,7 @@ var InlineParser = class {
343
336
  let label;
344
337
  if (labelLength > EMPTY_LABEL_LENGTH) label = this.text.slice(labelStart, labelStart + labelLength);
345
338
  else if (!opener.bracketAfter) label = this.text.slice(opener.index, afterCloseBracket);
346
- if (labelLength > 0) this.pos = labelStart + labelLength;
339
+ this.pos = labelStart + labelLength;
347
340
  if (label === void 0) return;
348
341
  const definition = this.references.get(require_inline_link.normalizeLinkLabel(label));
349
342
  if (definition === void 0) {
@@ -488,10 +481,7 @@ function toAstNode(node) {
488
481
  }
489
482
  function parseInlines(content, references, footnotes, options = {}) {
490
483
  const root = new InlineParser(content, references, footnotes, options).parse();
491
- if (options.gfmAutolinks ?? true) {
492
- require_inline_gfm_autolink.applyGfmAutolinks(root);
493
- mergeAdjacentText(root);
494
- }
484
+ if (options.gfmAutolinks ?? true) require_inline_gfm_autolink.applyGfmAutolinks(root);
495
485
  return toChildAstNodes(root);
496
486
  }
497
487
  //#endregion
@@ -2,7 +2,7 @@ import { matchFootnoteLabel } from "./footnote.js";
2
2
  import { matchHtmlTag } from "../html/html.js";
3
3
  import { containsAsciiControlOrSpace, isAsciiPunctuation } from "./chars.js";
4
4
  import { matchEntity } from "./entity.js";
5
- import { DelimiterStack, isDelimiterChar, processEmphasis, scanDelimiterRun } from "./delimiter.js";
5
+ import { DelimiterStack, processEmphasis, scanDelimiterRun } from "./delimiter.js";
6
6
  import { InlineNode, createTextNode } from "./node.js";
7
7
  import { applyGfmAutolinks } from "./gfm-autolink.js";
8
8
  import { matchLinkLabel, normalizeLinkLabel, parseLinkDestination, parseLinkTitle, skipInlineWhitespace } from "./link.js";
@@ -11,7 +11,7 @@ import { matchMathInlineSpan } from "./math.js";
11
11
  const PLAIN_TEXT_PATTERN = /[^\n`[\]\\!<&*_~]+/y;
12
12
  const URI_AUTOLINK_PATTERN = /<[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>]*>/y;
13
13
  const EMAIL_AUTOLINK_PATTERN = /<([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/y;
14
- const HARD_BREAK_SPACES = " ";
14
+ const HARD_BREAK_SPACE_COUNT = 2;
15
15
  const EMPTY_LABEL_LENGTH = 2;
16
16
  function stripOneSurroundingSpace(content) {
17
17
  if (content.startsWith(" ") && content.endsWith(" ") && /[^ ]/.test(content)) return content.slice(1, content.length - 1);
@@ -44,6 +44,13 @@ var InlineParser = class {
44
44
  return this.container;
45
45
  }
46
46
  step() {
47
+ PLAIN_TEXT_PATTERN.lastIndex = this.pos;
48
+ const plain = PLAIN_TEXT_PATTERN.exec(this.text);
49
+ if (plain !== null) {
50
+ this.appendText(plain[0]);
51
+ this.pos += plain[0].length;
52
+ return;
53
+ }
47
54
  const char = this.text.charAt(this.pos);
48
55
  switch (char) {
49
56
  case "\n":
@@ -70,12 +77,9 @@ var InlineParser = class {
70
77
  case "]":
71
78
  this.parseCloseBracket();
72
79
  return;
73
- default:
74
- if (isDelimiterChar(char)) {
75
- this.parseDelimiterRun(char);
76
- return;
77
- }
78
- this.parsePlainText();
80
+ case "*":
81
+ case "_":
82
+ case "~": this.parseDelimiterRun(char);
79
83
  }
80
84
  }
81
85
  appendText(literal) {
@@ -83,25 +87,16 @@ var InlineParser = class {
83
87
  this.container.appendChild(node);
84
88
  return node;
85
89
  }
86
- parsePlainText() {
87
- PLAIN_TEXT_PATTERN.lastIndex = this.pos;
88
- const match = PLAIN_TEXT_PATTERN.exec(this.text);
89
- if (match === null) {
90
- this.appendText(this.text.charAt(this.pos));
91
- this.pos += 1;
92
- return;
93
- }
94
- this.appendText(match[0]);
95
- this.pos += match[0].length;
96
- }
97
90
  parseLineBreak() {
98
91
  this.pos += 1;
99
92
  const last = this.container.lastChild;
100
- if (last?.kind === "text" && last.literal.endsWith(" ")) {
101
- const hard = last.literal.endsWith(HARD_BREAK_SPACES);
102
- last.literal = last.literal.replace(/ +$/, "");
103
- this.container.appendChild(new InlineNode(hard ? "hardBreak" : "softBreak"));
104
- } else this.container.appendChild(new InlineNode("softBreak"));
93
+ let hard = false;
94
+ if (last?.kind === "text") {
95
+ const withoutTrailingSpaces = last.literal.replace(/ +$/, "");
96
+ hard = last.literal.length - withoutTrailingSpaces.length >= HARD_BREAK_SPACE_COUNT;
97
+ last.literal = withoutTrailingSpaces;
98
+ }
99
+ this.container.appendChild(new InlineNode(hard ? "hardBreak" : "softBreak"));
105
100
  while (this.text.charAt(this.pos) === " ") this.pos += 1;
106
101
  }
107
102
  parseBackslash() {
@@ -113,15 +108,13 @@ var InlineParser = class {
113
108
  this.container.appendChild(new InlineNode("hardBreak"));
114
109
  return;
115
110
  }
116
- if (next === "(") {
117
- const span = matchMathInlineSpan(this.text, backslashIndex);
118
- if (span !== void 0) {
119
- const node = new InlineNode("mathInline");
120
- node.literal = span.slice(2, span.length - 2);
121
- this.container.appendChild(node);
122
- this.pos = backslashIndex + span.length;
123
- return;
124
- }
111
+ const span = matchMathInlineSpan(this.text, backslashIndex);
112
+ if (span !== void 0) {
113
+ const node = new InlineNode("mathInline");
114
+ node.literal = span.slice(2, span.length - 2);
115
+ this.container.appendChild(node);
116
+ this.pos = backslashIndex + span.length;
117
+ return;
125
118
  }
126
119
  if (isAsciiPunctuation(next)) {
127
120
  this.appendText(next);
@@ -136,7 +129,7 @@ var InlineParser = class {
136
129
  while (this.text.charAt(start + openLength) === "`") openLength += 1;
137
130
  const afterOpen = start + openLength;
138
131
  let scan = afterOpen;
139
- while (scan < this.text.length) {
132
+ while (this.text.charAt(scan) !== "") {
140
133
  if (this.text.charAt(scan) !== "`") {
141
134
  scan += 1;
142
135
  continue;
@@ -218,7 +211,7 @@ var InlineParser = class {
218
211
  }
219
212
  const node = this.appendText(this.text.slice(this.pos, this.pos + run.count));
220
213
  this.pos += run.count;
221
- if (run.canOpen || run.canClose) this.delimiters.push(char, run, node);
214
+ this.delimiters.push(char, run, node);
222
215
  }
223
216
  parseLiteralRun(char) {
224
217
  let length = 0;
@@ -342,7 +335,7 @@ var InlineParser = class {
342
335
  let label;
343
336
  if (labelLength > EMPTY_LABEL_LENGTH) label = this.text.slice(labelStart, labelStart + labelLength);
344
337
  else if (!opener.bracketAfter) label = this.text.slice(opener.index, afterCloseBracket);
345
- if (labelLength > 0) this.pos = labelStart + labelLength;
338
+ this.pos = labelStart + labelLength;
346
339
  if (label === void 0) return;
347
340
  const definition = this.references.get(normalizeLinkLabel(label));
348
341
  if (definition === void 0) {
@@ -487,10 +480,7 @@ function toAstNode(node) {
487
480
  }
488
481
  function parseInlines(content, references, footnotes, options = {}) {
489
482
  const root = new InlineParser(content, references, footnotes, options).parse();
490
- if (options.gfmAutolinks ?? true) {
491
- applyGfmAutolinks(root);
492
- mergeAdjacentText(root);
493
- }
483
+ if (options.gfmAutolinks ?? true) applyGfmAutolinks(root);
494
484
  return toChildAstNodes(root);
495
485
  }
496
486
  //#endregion
@@ -49,8 +49,8 @@ function lowerParagraph(node, context) {
49
49
  const blocks = [];
50
50
  const inlineCtx = inlineContext(context);
51
51
  let segment = [];
52
- const flushSegment = (force) => {
53
- if (segment.length === 0 && !force) return;
52
+ const flushSegment = () => {
53
+ if (segment.length === 0) return;
54
54
  const inline = require_lower_inline.lowerInlineNodes(segment, inlineCtx);
55
55
  blocks.push(decorateParagraph({
56
56
  kind: "paragraph",
@@ -76,7 +76,7 @@ function lowerParagraph(node, context) {
76
76
  segment.push(child);
77
77
  continue;
78
78
  }
79
- flushSegment(false);
79
+ flushSegment();
80
80
  if (context.list !== void 0) context.sink({
81
81
  code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.LIST_ITEM_BLOCK_UNLISTED,
82
82
  severity: "info",
@@ -106,7 +106,7 @@ function lowerParagraph(node, context) {
106
106
  }
107
107
  }, image, { kind: "constructEnd" });
108
108
  }
109
- flushSegment(blocks.length === 0);
109
+ flushSegment();
110
110
  return blocks;
111
111
  }
112
112
  function splitInfoString(infoString) {
@@ -176,10 +176,9 @@ function lowerHtmlBlock(node, context, contentWidthPt) {
176
176
  severity: "info",
177
177
  message: "block-level raw HTML was preserved as literal text (styleId \"HTMLPreformatted\"); it will not be rendered as HTML by any consumer of the resulting ContentDocument, and its verbatim original rides the paragraph's own markdown residue for this package's writer to re-emit as-is"
178
178
  });
179
- const literal = node.literal.replace(/\n+$/, "");
180
179
  return [decorateParagraph({
181
180
  kind: "paragraph",
182
- runs: literal.length === 0 ? [] : [{ text: literal }],
181
+ runs: [{ text: node.literal }],
183
182
  styleId: require_shared_style_constants.HTML_PREFORMATTED_STYLE_ID,
184
183
  source: {
185
184
  format: "markdown",
@@ -242,7 +241,6 @@ function lowerListItem(item, numId, level, context, contentWidthPt) {
242
241
  list: membership
243
242
  };
244
243
  const blocks = [];
245
- let ownLevelBlockCount = 0;
246
244
  let firstOwnBlock;
247
245
  for (const child of item.children) {
248
246
  if (child.type === "list") {
@@ -250,11 +248,10 @@ function lowerListItem(item, numId, level, context, contentWidthPt) {
250
248
  continue;
251
249
  }
252
250
  const childBlocks = lowerBlock(child, itemContext, contentWidthPt);
253
- ownLevelBlockCount += childBlocks.length;
254
251
  firstOwnBlock ??= childBlocks[0];
255
252
  blocks.push(...childBlocks);
256
253
  }
257
- if (ownLevelBlockCount === 0 || firstOwnBlock?.kind === "constructStart") blocks.unshift(decorateParagraph({
254
+ if (firstOwnBlock === void 0 || firstOwnBlock.kind === "constructStart") blocks.unshift(decorateParagraph({
258
255
  kind: "paragraph",
259
256
  runs: []
260
257
  }, itemContext));
@@ -274,7 +271,7 @@ function lowerList(node, ancestorNumId, level, context, contentWidthPt) {
274
271
  } else {
275
272
  numId = ancestorNumId;
276
273
  const mintedType = require_shared_list_id.mintedListType(numId);
277
- if (mintedType !== void 0 && mintedType !== node.markerType) context.sink({
274
+ if (mintedType === (node.markerType === "bullet" ? "ordered" : "bullet")) context.sink({
278
275
  code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.LIST_MARKER_TYPE_CONFLICT,
279
276
  severity: "warning",
280
277
  message: `a nested ${node.markerType} list sits under a list minted as ${mintedType}; the enclosing list's own marker type is kept (first-wins) and this nested list's own type is not separately represented`
@@ -48,8 +48,8 @@ function lowerParagraph(node, context) {
48
48
  const blocks = [];
49
49
  const inlineCtx = inlineContext(context);
50
50
  let segment = [];
51
- const flushSegment = (force) => {
52
- if (segment.length === 0 && !force) return;
51
+ const flushSegment = () => {
52
+ if (segment.length === 0) return;
53
53
  const inline = lowerInlineNodes(segment, inlineCtx);
54
54
  blocks.push(decorateParagraph({
55
55
  kind: "paragraph",
@@ -75,7 +75,7 @@ function lowerParagraph(node, context) {
75
75
  segment.push(child);
76
76
  continue;
77
77
  }
78
- flushSegment(false);
78
+ flushSegment();
79
79
  if (context.list !== void 0) context.sink({
80
80
  code: MarkdownDiagnosticCodes.LIST_ITEM_BLOCK_UNLISTED,
81
81
  severity: "info",
@@ -105,7 +105,7 @@ function lowerParagraph(node, context) {
105
105
  }
106
106
  }, image, { kind: "constructEnd" });
107
107
  }
108
- flushSegment(blocks.length === 0);
108
+ flushSegment();
109
109
  return blocks;
110
110
  }
111
111
  function splitInfoString(infoString) {
@@ -175,10 +175,9 @@ function lowerHtmlBlock(node, context, contentWidthPt) {
175
175
  severity: "info",
176
176
  message: "block-level raw HTML was preserved as literal text (styleId \"HTMLPreformatted\"); it will not be rendered as HTML by any consumer of the resulting ContentDocument, and its verbatim original rides the paragraph's own markdown residue for this package's writer to re-emit as-is"
177
177
  });
178
- const literal = node.literal.replace(/\n+$/, "");
179
178
  return [decorateParagraph({
180
179
  kind: "paragraph",
181
- runs: literal.length === 0 ? [] : [{ text: literal }],
180
+ runs: [{ text: node.literal }],
182
181
  styleId: HTML_PREFORMATTED_STYLE_ID,
183
182
  source: {
184
183
  format: "markdown",
@@ -241,7 +240,6 @@ function lowerListItem(item, numId, level, context, contentWidthPt) {
241
240
  list: membership
242
241
  };
243
242
  const blocks = [];
244
- let ownLevelBlockCount = 0;
245
243
  let firstOwnBlock;
246
244
  for (const child of item.children) {
247
245
  if (child.type === "list") {
@@ -249,11 +247,10 @@ function lowerListItem(item, numId, level, context, contentWidthPt) {
249
247
  continue;
250
248
  }
251
249
  const childBlocks = lowerBlock(child, itemContext, contentWidthPt);
252
- ownLevelBlockCount += childBlocks.length;
253
250
  firstOwnBlock ??= childBlocks[0];
254
251
  blocks.push(...childBlocks);
255
252
  }
256
- if (ownLevelBlockCount === 0 || firstOwnBlock?.kind === "constructStart") blocks.unshift(decorateParagraph({
253
+ if (firstOwnBlock === void 0 || firstOwnBlock.kind === "constructStart") blocks.unshift(decorateParagraph({
257
254
  kind: "paragraph",
258
255
  runs: []
259
256
  }, itemContext));
@@ -273,7 +270,7 @@ function lowerList(node, ancestorNumId, level, context, contentWidthPt) {
273
270
  } else {
274
271
  numId = ancestorNumId;
275
272
  const mintedType = mintedListType(numId);
276
- if (mintedType !== void 0 && mintedType !== node.markerType) context.sink({
273
+ if (mintedType === (node.markerType === "bullet" ? "ordered" : "bullet")) context.sink({
277
274
  code: MarkdownDiagnosticCodes.LIST_MARKER_TYPE_CONFLICT,
278
275
  severity: "warning",
279
276
  message: `a nested ${node.markerType} list sits under a list minted as ${mintedType}; the enclosing list's own marker type is kept (first-wins) and this nested list's own type is not separately represented`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-codec",
3
- "version": "6.7.5",
3
+ "version": "6.7.6",
4
4
  "description": "Hand-written CommonMark+GFM <-> DocumentTree codec, built on document-schema.js",
5
5
  "type": "module",
6
6
  "repository": {