@headwall/markdown-to-blocks 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
13
13
  throw Error('Dynamic require of "' + x + '" is not supported');
14
14
  });
15
15
  var __commonJS = (cb, mod) => function __require2() {
16
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ try {
17
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
+ } catch (e) {
19
+ throw mod = 0, e;
20
+ }
17
21
  };
18
22
  var __export = (target, all2) => {
19
23
  for (var name in all2)
@@ -850,36 +854,38 @@ var require_Alias = __commonJS({
850
854
  if (node2.anchor === this.source)
851
855
  found = node2;
852
856
  }
857
+ if (found && ctx) {
858
+ const { anchors: anchors2, doc: doc2, maxAliasCount } = ctx;
859
+ let data = anchors2.get(found);
860
+ if (!data) {
861
+ toJS.toJS(found, null, ctx);
862
+ data = anchors2.get(found);
863
+ }
864
+ if (data?.res === void 0) {
865
+ const msg = "This should not happen: Alias anchor was not resolved?";
866
+ throw new ReferenceError(msg);
867
+ }
868
+ if (maxAliasCount >= 0) {
869
+ data.count += 1;
870
+ if (data.aliasCount === 0)
871
+ data.aliasCount = getAliasCount(doc2, found, anchors2);
872
+ if (data.count * data.aliasCount > maxAliasCount) {
873
+ const msg = "Excessive alias count indicates a resource exhaustion attack";
874
+ throw new ReferenceError(msg);
875
+ }
876
+ }
877
+ }
853
878
  return found;
854
879
  }
855
880
  toJSON(_arg, ctx) {
856
881
  if (!ctx)
857
882
  return { source: this.source };
858
- const { anchors: anchors2, doc, maxAliasCount } = ctx;
859
- const source = this.resolve(doc, ctx);
883
+ const source = this.resolve(ctx.doc, ctx);
860
884
  if (!source) {
861
885
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
862
886
  throw new ReferenceError(msg);
863
887
  }
864
- let data = anchors2.get(source);
865
- if (!data) {
866
- toJS.toJS(source, null, ctx);
867
- data = anchors2.get(source);
868
- }
869
- if (data?.res === void 0) {
870
- const msg = "This should not happen: Alias anchor was not resolved?";
871
- throw new ReferenceError(msg);
872
- }
873
- if (maxAliasCount >= 0) {
874
- data.count += 1;
875
- if (data.aliasCount === 0)
876
- data.aliasCount = getAliasCount(doc, source, anchors2);
877
- if (data.count * data.aliasCount > maxAliasCount) {
878
- const msg = "Excessive alias count indicates a resource exhaustion attack";
879
- throw new ReferenceError(msg);
880
- }
881
- }
882
- return data.res;
888
+ return ctx.anchors.get(source).res;
883
889
  }
884
890
  toString(ctx, _onComment, _onChompKeep) {
885
891
  const src = `*${this.source}`;
@@ -4881,37 +4887,38 @@ var require_resolve_flow_scalar = __commonJS({
4881
4887
  }
4882
4888
  if (badChar)
4883
4889
  onError(0, "BAD_SCALAR_START", `Plain value cannot start with ${badChar}`);
4884
- return foldLines(source);
4890
+ return unfoldLines(source);
4885
4891
  }
4886
4892
  function singleQuotedValue(source, onError) {
4887
4893
  if (source[source.length - 1] !== "'" || source.length === 1)
4888
4894
  onError(source.length, "MISSING_CHAR", "Missing closing 'quote");
4889
- return foldLines(source.slice(1, -1)).replace(/''/g, "'");
4895
+ return unfoldLines(source.slice(1, -1)).replace(/''/g, "'");
4890
4896
  }
4891
- function foldLines(source) {
4892
- let first, line;
4897
+ function unfoldLines(source) {
4898
+ const line = /(.*?)\r?\n/sy;
4899
+ let match = line.exec(source);
4900
+ if (!match)
4901
+ return source;
4902
+ let trimEnd, trimBoth;
4893
4903
  try {
4894
- first = new RegExp("(.*?)(?<![ ])[ ]*\r?\n", "sy");
4895
- line = new RegExp("[ ]*(.*?)(?:(?<![ ])[ ]*)?\r?\n", "sy");
4904
+ trimEnd = new RegExp("(?<![ ])[ ]+$");
4905
+ trimBoth = new RegExp("^[ ]+|(?<![ ])[ ]+$", "g");
4896
4906
  } catch {
4897
- first = /(.*?)[ \t]*\r?\n/sy;
4898
- line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
4907
+ trimEnd = /[ \t]+$/;
4908
+ trimBoth = /^[ \t]+|[ \t]+$/g;
4899
4909
  }
4900
- let match = first.exec(source);
4901
- if (!match)
4902
- return source;
4903
- let res = match[1];
4910
+ let res = match[1].replace(trimEnd, "");
4904
4911
  let sep = " ";
4905
- let pos = first.lastIndex;
4906
- line.lastIndex = pos;
4912
+ let pos = line.lastIndex;
4907
4913
  while (match = line.exec(source)) {
4908
- if (match[1] === "") {
4914
+ const lm = match[1].replace(trimBoth, "");
4915
+ if (lm === "") {
4909
4916
  if (sep === "\n")
4910
4917
  res += sep;
4911
4918
  else
4912
4919
  sep = "\n";
4913
4920
  } else {
4914
- res += sep + match[1];
4921
+ res += sep + lm;
4915
4922
  sep = " ";
4916
4923
  }
4917
4924
  pos = line.lastIndex;
@@ -8181,15 +8188,12 @@ function findAndReplace(tree, list3, options) {
8181
8188
  find.lastIndex = position2 + 1;
8182
8189
  } else {
8183
8190
  if (start !== position2) {
8184
- nodes.push({
8185
- type: "text",
8186
- value: node2.value.slice(start, position2)
8187
- });
8191
+ add({ type: "text", value: node2.value.slice(start, position2) });
8188
8192
  }
8189
8193
  if (Array.isArray(value2)) {
8190
- nodes.push(...value2);
8194
+ for (const child of value2) add(child);
8191
8195
  } else if (value2) {
8192
- nodes.push(value2);
8196
+ add(value2);
8193
8197
  }
8194
8198
  start = position2 + match[0].length;
8195
8199
  change = true;
@@ -8201,20 +8205,28 @@ function findAndReplace(tree, list3, options) {
8201
8205
  }
8202
8206
  if (change) {
8203
8207
  if (start < node2.value.length) {
8204
- nodes.push({ type: "text", value: node2.value.slice(start) });
8208
+ add({ type: "text", value: node2.value.slice(start) });
8205
8209
  }
8206
8210
  parent.children.splice(index2, 1, ...nodes);
8207
8211
  } else {
8208
8212
  nodes = [node2];
8209
8213
  }
8210
8214
  return index2 + nodes.length;
8215
+ function add(child) {
8216
+ const previous3 = nodes[nodes.length - 1];
8217
+ if (previous3 && previous3.type === "text" && child.type === "text") {
8218
+ previous3.value += child.value;
8219
+ } else {
8220
+ nodes.push(child);
8221
+ }
8222
+ }
8211
8223
  }
8212
8224
  }
8213
8225
  function toPairs(tupleOrList) {
8214
- const result = [];
8215
8226
  if (!Array.isArray(tupleOrList)) {
8216
8227
  throw new TypeError("Expected find and replace tuple or list of tuples");
8217
8228
  }
8229
+ const result = [];
8218
8230
  const list3 = !tupleOrList[0] || Array.isArray(tupleOrList[0]) ? tupleOrList : [tupleOrList];
8219
8231
  let index2 = -1;
8220
8232
  while (++index2 < list3.length) {
@@ -8509,6 +8521,7 @@ var constructsWithoutStrikethrough = [
8509
8521
  "titleQuote",
8510
8522
  "titleApostrophe"
8511
8523
  ];
8524
+ handleDelete.attention = attentionDelete;
8512
8525
  handleDelete.peek = peekDelete;
8513
8526
  function gfmStrikethroughFromMarkdown() {
8514
8527
  return {
@@ -8519,35 +8532,39 @@ function gfmStrikethroughFromMarkdown() {
8519
8532
  }
8520
8533
  function gfmStrikethroughToMarkdown() {
8521
8534
  return {
8535
+ handlers: { delete: handleDelete },
8522
8536
  unsafe: [
8523
8537
  {
8524
8538
  character: "~",
8525
8539
  inConstruct: "phrasing",
8526
8540
  notInConstruct: constructsWithoutStrikethrough
8527
8541
  }
8528
- ],
8529
- handlers: { delete: handleDelete }
8542
+ ]
8530
8543
  };
8531
8544
  }
8532
8545
  function enterStrikethrough(token) {
8533
- this.enter({ type: "delete", children: [] }, token);
8546
+ this.enter({ type: "delete", children: [], position: void 0 }, token);
8534
8547
  }
8535
8548
  function exitStrikethrough(token) {
8536
8549
  this.exit(token);
8537
8550
  }
8538
8551
  function handleDelete(node2, _, state, info) {
8539
8552
  const tracker = state.createTracker(info);
8553
+ const sequence = state.stack.includes("strikethrough") ? "~" : "~~";
8540
8554
  const exit3 = state.enter("strikethrough");
8541
- let value2 = tracker.move("~~");
8555
+ let value2 = tracker.move(sequence);
8542
8556
  value2 += state.containerPhrasing(node2, {
8543
8557
  ...tracker.current(),
8544
8558
  before: value2,
8545
8559
  after: "~"
8546
8560
  });
8547
- value2 += tracker.move("~~");
8561
+ value2 += tracker.move(sequence);
8548
8562
  exit3();
8549
8563
  return value2;
8550
8564
  }
8565
+ function attentionDelete() {
8566
+ return { construct: "strikethrough", markers: ["~"], sizes: [2, 1] };
8567
+ }
8551
8568
  function peekDelete() {
8552
8569
  return "~";
8553
8570
  }
@@ -8693,6 +8710,34 @@ function toAlignment(value2) {
8693
8710
  return code3 === 67 || code3 === 99 ? 99 : code3 === 76 || code3 === 108 ? 108 : code3 === 82 || code3 === 114 ? 114 : 0;
8694
8711
  }
8695
8712
 
8713
+ // node_modules/mdast-util-phrasing/lib/index.js
8714
+ var phrasing = (
8715
+ /** @type {(node?: unknown) => node is Exclude<PhrasingContent, Html>} */
8716
+ convert([
8717
+ "break",
8718
+ "delete",
8719
+ "emphasis",
8720
+ // To do: next major: removed since footnotes were added to GFM.
8721
+ "footnote",
8722
+ "footnoteReference",
8723
+ "image",
8724
+ "imageReference",
8725
+ "inlineCode",
8726
+ // Enabled by `mdast-util-math`:
8727
+ "inlineMath",
8728
+ "link",
8729
+ "linkReference",
8730
+ // Enabled by `mdast-util-mdx`:
8731
+ "mdxJsxTextElement",
8732
+ // Enabled by `mdast-util-mdx`:
8733
+ "mdxTextExpression",
8734
+ "strong",
8735
+ "text",
8736
+ // Enabled by `mdast-util-directive`:
8737
+ "textDirective"
8738
+ ])
8739
+ );
8740
+
8696
8741
  // node_modules/mdast-util-to-markdown/lib/handle/blockquote.js
8697
8742
  function blockquote(node2, _, state, info) {
8698
8743
  const exit3 = state.enter("blockquote");
@@ -8734,8 +8779,9 @@ function listInScope(stack, list3, none) {
8734
8779
  function hardBreak(_, _1, state, info) {
8735
8780
  let index2 = -1;
8736
8781
  while (++index2 < state.unsafe.length) {
8737
- if (state.unsafe[index2].character === "\n" && patternInScope(state.stack, state.unsafe[index2])) {
8738
- return /[ \t]/.test(info.before) ? "" : " ";
8782
+ const pattern = state.unsafe[index2];
8783
+ if (pattern.character === "\n" && !pattern.before && !pattern.after && patternInScope(state.stack, pattern)) {
8784
+ return /[\t ]/.test(info.before) ? "" : " ";
8739
8785
  }
8740
8786
  }
8741
8787
  return "\\\n";
@@ -8770,8 +8816,8 @@ function formatCodeAsIndented(node2, state) {
8770
8816
  return Boolean(
8771
8817
  state.options.fences === false && node2.value && // If there’s no info…
8772
8818
  !node2.lang && // And there’s a non-whitespace character…
8773
- /[^ \r\n]/.test(node2.value) && // And the value doesn’t start or end in a blank…
8774
- !/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(node2.value)
8819
+ /[^\n\r ]/.test(node2.value) && // And the value doesn’t start or end in a blank…
8820
+ !/^[\t ]*(?:[\n\r]|$)|(?:^|[\n\r])[\t ]*$/.test(node2.value)
8775
8821
  );
8776
8822
  }
8777
8823
 
@@ -8790,7 +8836,6 @@ function checkFence(state) {
8790
8836
  function code(node2, _, state, info) {
8791
8837
  const marker = checkFence(state);
8792
8838
  const raw = node2.value || "";
8793
- const suffix = marker === "`" ? "GraveAccent" : "Tilde";
8794
8839
  if (formatCodeAsIndented(node2, state)) {
8795
8840
  const exit4 = state.enter("codeIndented");
8796
8841
  const value3 = state.indentLines(raw, map2);
@@ -8800,6 +8845,7 @@ function code(node2, _, state, info) {
8800
8845
  const tracker = state.createTracker(info);
8801
8846
  const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3));
8802
8847
  const exit3 = state.enter("codeFenced");
8848
+ const suffix = marker === "`" ? "GraveAccent" : "Tilde";
8803
8849
  let value2 = tracker.move(sequence);
8804
8850
  if (node2.lang) {
8805
8851
  const subexit = state.enter(`codeFencedLang${suffix}`);
@@ -8916,103 +8962,32 @@ function checkEmphasis(state) {
8916
8962
  return marker;
8917
8963
  }
8918
8964
 
8919
- // node_modules/mdast-util-to-markdown/lib/util/encode-character-reference.js
8920
- function encodeCharacterReference(code3) {
8921
- return "&#x" + code3.toString(16).toUpperCase() + ";";
8922
- }
8923
-
8924
- // node_modules/micromark-util-classify-character/index.js
8925
- function classifyCharacter(code3) {
8926
- if (code3 === null || markdownLineEndingOrSpace(code3) || unicodeWhitespace(code3)) {
8927
- return 1;
8928
- }
8929
- if (unicodePunctuation(code3)) {
8930
- return 2;
8931
- }
8932
- }
8933
-
8934
- // node_modules/mdast-util-to-markdown/lib/util/encode-info.js
8935
- function encodeInfo(outside, inside, marker) {
8936
- const outsideKind = classifyCharacter(outside);
8937
- const insideKind = classifyCharacter(inside);
8938
- if (outsideKind === void 0) {
8939
- return insideKind === void 0 ? (
8940
- // Letter inside:
8941
- // we have to encode *both* letters for `_` as it is looser.
8942
- // it already forms for `*` (and GFMs `~`).
8943
- marker === "_" ? { inside: true, outside: true } : { inside: false, outside: false }
8944
- ) : insideKind === 1 ? (
8945
- // Whitespace inside: encode both (letter, whitespace).
8946
- { inside: true, outside: true }
8947
- ) : (
8948
- // Punctuation inside: encode outer (letter)
8949
- { inside: false, outside: true }
8950
- );
8951
- }
8952
- if (outsideKind === 1) {
8953
- return insideKind === void 0 ? (
8954
- // Letter inside: already forms.
8955
- { inside: false, outside: false }
8956
- ) : insideKind === 1 ? (
8957
- // Whitespace inside: encode both (whitespace).
8958
- { inside: true, outside: true }
8959
- ) : (
8960
- // Punctuation inside: already forms.
8961
- { inside: false, outside: false }
8962
- );
8963
- }
8964
- return insideKind === void 0 ? (
8965
- // Letter inside: already forms.
8966
- { inside: false, outside: false }
8967
- ) : insideKind === 1 ? (
8968
- // Whitespace inside: encode inner (whitespace).
8969
- { inside: true, outside: false }
8970
- ) : (
8971
- // Punctuation inside: already forms.
8972
- { inside: false, outside: false }
8973
- );
8974
- }
8975
-
8976
8965
  // node_modules/mdast-util-to-markdown/lib/handle/emphasis.js
8977
- emphasis.peek = emphasisPeek;
8966
+ emphasis.attention = attention;
8967
+ emphasis.peek = peek;
8978
8968
  function emphasis(node2, _, state, info) {
8979
- const marker = checkEmphasis(state);
8980
- const exit3 = state.enter("emphasis");
8981
- const tracker = state.createTracker(info);
8982
- const before = tracker.move(marker);
8983
- let between = tracker.move(
8984
- state.containerPhrasing(node2, {
8985
- after: marker,
8986
- before,
8987
- ...tracker.current()
8988
- })
8989
- );
8990
- const betweenHead = between.charCodeAt(0);
8991
- const open = encodeInfo(
8992
- info.before.charCodeAt(info.before.length - 1),
8993
- betweenHead,
8994
- marker
8995
- );
8996
- if (open.inside) {
8997
- between = encodeCharacterReference(betweenHead) + between.slice(1);
8998
- }
8999
- const betweenTail = between.charCodeAt(between.length - 1);
9000
- const close2 = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
9001
- if (close2.inside) {
9002
- between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
9003
- }
9004
- const after = tracker.move(marker);
8969
+ const exit3 = state.enter("phrasing");
8970
+ const value2 = state.containerPhrasing({ type: "root", children: [node2] }, info);
9005
8971
  exit3();
9006
- state.attentionEncodeSurroundingInfo = {
9007
- after: close2.outside,
9008
- before: open.outside
8972
+ return value2;
8973
+ }
8974
+ function attention(_, state) {
8975
+ const marker = checkEmphasis(state);
8976
+ return {
8977
+ construct: "emphasis",
8978
+ markers: marker === "*" ? ["*", "_"] : ["_", "*"],
8979
+ sizes: [1]
9009
8980
  };
9010
- return before + between + after;
9011
8981
  }
9012
- function emphasisPeek(_, _1, state) {
8982
+ function peek(_, _1, state) {
9013
8983
  return state.options.emphasis || "*";
9014
8984
  }
9015
8985
 
8986
+ // node_modules/mdast-util-to-markdown/lib/util/encode-character-reference.js
8987
+ function encodeCharacterReference(code3) {
8988
+ return "&#x" + code3.toString(16).toUpperCase() + ";";
8989
+ }
8990
+
9016
8991
  // node_modules/unist-util-visit/lib/index.js
9017
8992
  function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
9018
8993
  let reverse;
@@ -9116,8 +9091,9 @@ function heading(node2, _, state, info) {
9116
9091
  after: "\n",
9117
9092
  ...tracker.current()
9118
9093
  });
9119
- if (/^[\t ]/.test(value2)) {
9120
- value2 = encodeCharacterReference(value2.charCodeAt(0)) + value2.slice(1);
9094
+ const head = value2.charCodeAt(0);
9095
+ if (head === 9 || head === 32) {
9096
+ value2 = encodeCharacterReference(head) + value2.slice(1);
9121
9097
  }
9122
9098
  value2 = value2 ? sequence + " " + value2 : sequence;
9123
9099
  if (state.options.closeAtx) {
@@ -9210,7 +9186,9 @@ function imageReference(node2, _, state, info) {
9210
9186
  value2 += tracker.move(alt + "][");
9211
9187
  subexit();
9212
9188
  const stack = state.stack;
9213
- state.stack = [];
9189
+ state.stack = stack.filter(function(d) {
9190
+ return d !== "phrasing";
9191
+ });
9214
9192
  subexit = state.enter("reference");
9215
9193
  const reference = state.safe(state.associationId(node2), {
9216
9194
  before: value2,
@@ -9242,14 +9220,14 @@ function inlineCode(node2, _, state) {
9242
9220
  while (new RegExp("(^|[^`])" + sequence + "([^`]|$)").test(value2)) {
9243
9221
  sequence += "`";
9244
9222
  }
9245
- if (/[^ \r\n]/.test(value2) && (/^[ \r\n]/.test(value2) && /[ \r\n]$/.test(value2) || /^`|`$/.test(value2))) {
9223
+ if (/[^\n\r ]/.test(value2) && (/^[\n\r ]/.test(value2) && /[\n\r ]$/.test(value2) || /^`|`$/.test(value2))) {
9246
9224
  value2 = " " + value2 + " ";
9247
9225
  }
9248
9226
  while (++index2 < state.unsafe.length) {
9249
9227
  const pattern = state.unsafe[index2];
9250
9228
  const expression = state.compilePattern(pattern);
9251
- let match;
9252
9229
  if (!pattern.atBreak) continue;
9230
+ let match;
9253
9231
  while (match = expression.exec(value2)) {
9254
9232
  let position2 = match.index;
9255
9233
  if (value2.charCodeAt(position2) === 10 && value2.charCodeAt(position2 - 1) === 13) {
@@ -9269,11 +9247,11 @@ function formatLinkAsAutolink(node2, state) {
9269
9247
  const raw = toString(node2);
9270
9248
  return Boolean(
9271
9249
  !state.options.resourceLink && // If there’s a url…
9272
- node2.url && // And there’s a no title…
9250
+ node2.url && // And there’s no title…
9273
9251
  !node2.title && // And the content of `node` is a single text node…
9274
9252
  node2.children && node2.children.length === 1 && node2.children[0].type === "text" && // And if the url is the same as the content…
9275
9253
  (raw === node2.url || "mailto:" + raw === node2.url) && // And that starts w/ a protocol…
9276
- /^[a-z][a-z+.-]+:/i.test(node2.url) && // And that doesn’t contain ASCII control codes (character escapes and
9254
+ /^[a-z][+\-.a-z]+:/i.test(node2.url) && // And that doesn’t contain ASCII control codes (character escapes and
9277
9255
  // references don’t work), space, or angle brackets…
9278
9256
  !/[\0- <>\u007F]/.test(node2.url)
9279
9257
  );
@@ -9285,12 +9263,12 @@ function link(node2, _, state, info) {
9285
9263
  const quote = checkQuote(state);
9286
9264
  const suffix = quote === '"' ? "Quote" : "Apostrophe";
9287
9265
  const tracker = state.createTracker(info);
9288
- let exit3;
9289
- let subexit;
9290
9266
  if (formatLinkAsAutolink(node2, state)) {
9291
9267
  const stack = state.stack;
9292
- state.stack = [];
9293
- exit3 = state.enter("autolink");
9268
+ state.stack = stack.filter(function(d) {
9269
+ return d !== "phrasing";
9270
+ });
9271
+ const exit4 = state.enter("autolink");
9294
9272
  let value3 = tracker.move("<");
9295
9273
  value3 += tracker.move(
9296
9274
  state.containerPhrasing(node2, {
@@ -9300,12 +9278,12 @@ function link(node2, _, state, info) {
9300
9278
  })
9301
9279
  );
9302
9280
  value3 += tracker.move(">");
9303
- exit3();
9281
+ exit4();
9304
9282
  state.stack = stack;
9305
9283
  return value3;
9306
9284
  }
9307
- exit3 = state.enter("link");
9308
- subexit = state.enter("label");
9285
+ const exit3 = state.enter("link");
9286
+ let subexit = state.enter("label");
9309
9287
  let value2 = tracker.move("[");
9310
9288
  value2 += tracker.move(
9311
9289
  state.containerPhrasing(node2, {
@@ -9375,7 +9353,9 @@ function linkReference(node2, _, state, info) {
9375
9353
  value2 += tracker.move(text5 + "][");
9376
9354
  subexit();
9377
9355
  const stack = state.stack;
9378
- state.stack = [];
9356
+ state.stack = stack.filter(function(d) {
9357
+ return d !== "phrasing";
9358
+ });
9379
9359
  subexit = state.enter("reference");
9380
9360
  const reference = state.safe(state.associationId(node2), {
9381
9361
  before: value2,
@@ -9541,41 +9521,16 @@ function paragraph(node2, _, state, info) {
9541
9521
  return value2;
9542
9522
  }
9543
9523
 
9544
- // node_modules/mdast-util-phrasing/lib/index.js
9545
- var phrasing = (
9546
- /** @type {(node?: unknown) => node is Exclude<PhrasingContent, Html>} */
9547
- convert([
9548
- "break",
9549
- "delete",
9550
- "emphasis",
9551
- // To do: next major: removed since footnotes were added to GFM.
9552
- "footnote",
9553
- "footnoteReference",
9554
- "image",
9555
- "imageReference",
9556
- "inlineCode",
9557
- // Enabled by `mdast-util-math`:
9558
- "inlineMath",
9559
- "link",
9560
- "linkReference",
9561
- // Enabled by `mdast-util-mdx`:
9562
- "mdxJsxTextElement",
9563
- // Enabled by `mdast-util-mdx`:
9564
- "mdxTextExpression",
9565
- "strong",
9566
- "text",
9567
- // Enabled by `mdast-util-directive`:
9568
- "textDirective"
9569
- ])
9570
- );
9571
-
9572
9524
  // node_modules/mdast-util-to-markdown/lib/handle/root.js
9573
9525
  function root(node2, _, state, info) {
9574
9526
  const hasPhrasing = node2.children.some(function(d) {
9575
9527
  return phrasing(d);
9576
9528
  });
9577
- const container = hasPhrasing ? state.containerPhrasing : state.containerFlow;
9578
- return container.call(state, node2, info);
9529
+ if (!hasPhrasing) return state.containerFlow(node2, info);
9530
+ const exit3 = state.enter("phrasing");
9531
+ const value2 = state.containerPhrasing(node2, info);
9532
+ exit3();
9533
+ return value2;
9579
9534
  }
9580
9535
 
9581
9536
  // node_modules/mdast-util-to-markdown/lib/util/check-strong.js
@@ -9590,48 +9545,35 @@ function checkStrong(state) {
9590
9545
  }
9591
9546
 
9592
9547
  // node_modules/mdast-util-to-markdown/lib/handle/strong.js
9593
- strong.peek = strongPeek;
9548
+ strong.attention = attention2;
9549
+ strong.peek = peek2;
9594
9550
  function strong(node2, _, state, info) {
9595
- const marker = checkStrong(state);
9596
- const exit3 = state.enter("strong");
9597
- const tracker = state.createTracker(info);
9598
- const before = tracker.move(marker + marker);
9599
- let between = tracker.move(
9600
- state.containerPhrasing(node2, {
9601
- after: marker,
9602
- before,
9603
- ...tracker.current()
9604
- })
9605
- );
9606
- const betweenHead = between.charCodeAt(0);
9607
- const open = encodeInfo(
9608
- info.before.charCodeAt(info.before.length - 1),
9609
- betweenHead,
9610
- marker
9611
- );
9612
- if (open.inside) {
9613
- between = encodeCharacterReference(betweenHead) + between.slice(1);
9614
- }
9615
- const betweenTail = between.charCodeAt(between.length - 1);
9616
- const close2 = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
9617
- if (close2.inside) {
9618
- between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
9619
- }
9620
- const after = tracker.move(marker + marker);
9551
+ const exit3 = state.enter("phrasing");
9552
+ const value2 = state.containerPhrasing({ type: "root", children: [node2] }, info);
9621
9553
  exit3();
9622
- state.attentionEncodeSurroundingInfo = {
9623
- after: close2.outside,
9624
- before: open.outside
9554
+ return value2;
9555
+ }
9556
+ function attention2(_, state) {
9557
+ const marker = checkStrong(state);
9558
+ return {
9559
+ construct: "strong",
9560
+ markers: marker === "*" ? ["*", "_"] : ["_", "*"],
9561
+ sizes: [2]
9625
9562
  };
9626
- return before + between + after;
9627
9563
  }
9628
- function strongPeek(_, _1, state) {
9564
+ function peek2(_, _1, state) {
9629
9565
  return state.options.strong || "*";
9630
9566
  }
9631
9567
 
9632
9568
  // node_modules/mdast-util-to-markdown/lib/handle/text.js
9633
- function text(node2, _, state, info) {
9634
- return state.safe(node2.value, info);
9569
+ function text(node2, parent, state, info) {
9570
+ const siblings = parent ? parent.children : [];
9571
+ const index2 = siblings.indexOf(node2);
9572
+ return state.safe(node2.value, {
9573
+ ...info,
9574
+ afterNode: siblings[index2 + 1],
9575
+ beforeNode: siblings[index2 - 1]
9576
+ });
9635
9577
  }
9636
9578
 
9637
9579
  // node_modules/mdast-util-to-markdown/lib/util/check-rule-repetition.js
@@ -9675,6 +9617,73 @@ var handle = {
9675
9617
  thematicBreak
9676
9618
  };
9677
9619
 
9620
+ // node_modules/micromark-util-html-tag-name/index.js
9621
+ var htmlBlockNames = [
9622
+ "address",
9623
+ "article",
9624
+ "aside",
9625
+ "base",
9626
+ "basefont",
9627
+ "blockquote",
9628
+ "body",
9629
+ "caption",
9630
+ "center",
9631
+ "col",
9632
+ "colgroup",
9633
+ "dd",
9634
+ "details",
9635
+ "dialog",
9636
+ "dir",
9637
+ "div",
9638
+ "dl",
9639
+ "dt",
9640
+ "fieldset",
9641
+ "figcaption",
9642
+ "figure",
9643
+ "footer",
9644
+ "form",
9645
+ "frame",
9646
+ "frameset",
9647
+ "h1",
9648
+ "h2",
9649
+ "h3",
9650
+ "h4",
9651
+ "h5",
9652
+ "h6",
9653
+ "head",
9654
+ "header",
9655
+ "hr",
9656
+ "html",
9657
+ "iframe",
9658
+ "legend",
9659
+ "li",
9660
+ "link",
9661
+ "main",
9662
+ "menu",
9663
+ "menuitem",
9664
+ "nav",
9665
+ "noframes",
9666
+ "ol",
9667
+ "optgroup",
9668
+ "option",
9669
+ "p",
9670
+ "param",
9671
+ "search",
9672
+ "section",
9673
+ "summary",
9674
+ "table",
9675
+ "tbody",
9676
+ "td",
9677
+ "tfoot",
9678
+ "th",
9679
+ "thead",
9680
+ "title",
9681
+ "tr",
9682
+ "track",
9683
+ "ul"
9684
+ ];
9685
+ var htmlRawNames = ["pre", "script", "style", "textarea"];
9686
+
9678
9687
  // node_modules/character-entities/index.js
9679
9688
  var characterEntities = {
9680
9689
  AElig: "\xC6",
@@ -11846,6 +11855,16 @@ function decode($0, $1, $2) {
11846
11855
  return decodeNamedCharacterReference($2) || $0;
11847
11856
  }
11848
11857
 
11858
+ // node_modules/micromark-util-classify-character/index.js
11859
+ function classifyCharacter(code3) {
11860
+ if (code3 === null || markdownLineEndingOrSpace(code3) || unicodeWhitespace(code3)) {
11861
+ return 1;
11862
+ }
11863
+ if (unicodePunctuation(code3)) {
11864
+ return 2;
11865
+ }
11866
+ }
11867
+
11849
11868
  // node_modules/mdast-util-gfm-table/lib/index.js
11850
11869
  function gfmTableFromMarkdown() {
11851
11870
  return {
@@ -12525,31 +12544,24 @@ function resolveAll(constructs2, events, context) {
12525
12544
  }
12526
12545
 
12527
12546
  // node_modules/micromark-core-commonmark/lib/attention.js
12528
- var attention = {
12547
+ var attention3 = {
12529
12548
  name: "attention",
12530
12549
  resolveAll: resolveAllAttention,
12531
12550
  tokenize: tokenizeAttention
12532
12551
  };
12533
12552
  function resolveAllAttention(events, context) {
12534
12553
  let index2 = -1;
12535
- let open;
12536
- let group;
12537
- let text5;
12538
- let openingSequence;
12539
- let closingSequence;
12540
- let use;
12541
12554
  let nextEvents;
12542
- let offset;
12543
12555
  while (++index2 < events.length) {
12544
12556
  if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) {
12545
- open = index2;
12557
+ let open = index2;
12546
12558
  while (open--) {
12547
12559
  if (events[open][0] === "exit" && events[open][1].type === "attentionSequence" && events[open][1]._open && // If the markers are the same:
12548
12560
  context.sliceSerialize(events[open][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
12549
12561
  if ((events[open][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open][1].end.offset - events[open][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) {
12550
12562
  continue;
12551
12563
  }
12552
- use = events[open][1].end.offset - events[open][1].start.offset > 1 && events[index2][1].end.offset - events[index2][1].start.offset > 1 ? 2 : 1;
12564
+ const use = events[open][1].end.offset - events[open][1].start.offset > 1 && events[index2][1].end.offset - events[index2][1].start.offset > 1 ? 2 : 1;
12553
12565
  const start = {
12554
12566
  ...events[open][1].end
12555
12567
  };
@@ -12558,21 +12570,21 @@ function resolveAllAttention(events, context) {
12558
12570
  };
12559
12571
  movePoint(start, -use);
12560
12572
  movePoint(end, use);
12561
- openingSequence = {
12573
+ const openingSequence = {
12562
12574
  type: use > 1 ? "strongSequence" : "emphasisSequence",
12563
12575
  start,
12564
12576
  end: {
12565
12577
  ...events[open][1].end
12566
12578
  }
12567
12579
  };
12568
- closingSequence = {
12580
+ const closingSequence = {
12569
12581
  type: use > 1 ? "strongSequence" : "emphasisSequence",
12570
12582
  start: {
12571
12583
  ...events[index2][1].start
12572
12584
  },
12573
12585
  end
12574
12586
  };
12575
- text5 = {
12587
+ const text5 = {
12576
12588
  type: use > 1 ? "strongText" : "emphasisText",
12577
12589
  start: {
12578
12590
  ...events[open][1].end
@@ -12581,7 +12593,7 @@ function resolveAllAttention(events, context) {
12581
12593
  ...events[index2][1].start
12582
12594
  }
12583
12595
  };
12584
- group = {
12596
+ const group = {
12585
12597
  type: use > 1 ? "strong" : "emphasis",
12586
12598
  start: {
12587
12599
  ...openingSequence.start
@@ -12603,11 +12615,10 @@ function resolveAllAttention(events, context) {
12603
12615
  nextEvents = push(nextEvents, [["enter", group, context], ["enter", openingSequence, context], ["exit", openingSequence, context], ["enter", text5, context]]);
12604
12616
  nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open + 1, index2), context));
12605
12617
  nextEvents = push(nextEvents, [["exit", text5, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
12618
+ let offset = 0;
12606
12619
  if (events[index2][1].end.offset - events[index2][1].start.offset) {
12607
12620
  offset = 2;
12608
12621
  nextEvents = push(nextEvents, [["enter", events[index2][1], context], ["exit", events[index2][1], context]]);
12609
- } else {
12610
- offset = 0;
12611
12622
  }
12612
12623
  splice(events, open - 1, index2 - open + 3, nextEvents);
12613
12624
  index2 = open + nextEvents.length - offset - 2;
@@ -12642,8 +12653,8 @@ function tokenizeAttention(effects, ok3) {
12642
12653
  }
12643
12654
  const token = effects.exit("attentionSequence");
12644
12655
  const after = classifyCharacter(code3);
12645
- const open = !after || after === 2 && before || attentionMarkers2.includes(code3);
12646
- const close2 = !before || before === 2 && after || attentionMarkers2.includes(previous3);
12656
+ const open = !after || after === 2 && before || attentionMarkers2.includes(code3) && code3 !== 42 && code3 !== 95;
12657
+ const close2 = !before || before === 2 && after || attentionMarkers2.includes(previous3) && previous3 !== 42 && previous3 !== 95;
12647
12658
  token._open = Boolean(marker === 42 ? open : open && (before || !close2));
12648
12659
  token._close = Boolean(marker === 42 ? close2 : close2 && (after || !open));
12649
12660
  return ok3(code3);
@@ -12758,7 +12769,7 @@ function tokenizeAutolink(effects, ok3, nok) {
12758
12769
 
12759
12770
  // node_modules/micromark-factory-space/index.js
12760
12771
  function factorySpace(effects, ok3, type, max) {
12761
- const limit = max ? max - 1 : Number.POSITIVE_INFINITY;
12772
+ const limit = max ? max - 1 : Infinity;
12762
12773
  let size = 0;
12763
12774
  return start;
12764
12775
  function start(code3) {
@@ -12777,6 +12788,29 @@ function factorySpace(effects, ok3, type, max) {
12777
12788
  return ok3(code3);
12778
12789
  }
12779
12790
  }
12791
+ function factorySpaceMinMax(effects, ok3, nok, type, min, max) {
12792
+ let size = 0;
12793
+ return start;
12794
+ function start(code3) {
12795
+ if (max > 0 && markdownSpace(code3)) {
12796
+ effects.enter(type);
12797
+ return prefix(code3);
12798
+ }
12799
+ return after(code3);
12800
+ }
12801
+ function prefix(code3) {
12802
+ if (markdownSpace(code3) && size < max) {
12803
+ effects.consume(code3);
12804
+ size++;
12805
+ return prefix;
12806
+ }
12807
+ effects.exit(type);
12808
+ return after(code3);
12809
+ }
12810
+ function after(code3) {
12811
+ return size >= min ? ok3(code3) : nok(code3);
12812
+ }
12813
+ }
12780
12814
 
12781
12815
  // node_modules/micromark-core-commonmark/lib/blank-line.js
12782
12816
  var blankLine = {
@@ -12942,16 +12976,34 @@ function tokenizeCharacterReference(effects, ok3, nok) {
12942
12976
  }
12943
12977
  }
12944
12978
 
12945
- // node_modules/micromark-core-commonmark/lib/code-fenced.js
12979
+ // node_modules/micromark-core-commonmark/lib/partial-non-lazy-continuation.js
12946
12980
  var nonLazyContinuation = {
12947
12981
  partial: true,
12948
12982
  tokenize: tokenizeNonLazyContinuation
12949
12983
  };
12950
- var codeFenced = {
12951
- concrete: true,
12952
- name: "codeFenced",
12953
- tokenize: tokenizeCodeFenced
12954
- };
12984
+ function tokenizeNonLazyContinuation(effects, ok3, nok) {
12985
+ const self = this;
12986
+ return start;
12987
+ function start(code3) {
12988
+ if (code3 === null) {
12989
+ return nok(code3);
12990
+ }
12991
+ effects.enter("lineEnding");
12992
+ effects.consume(code3);
12993
+ effects.exit("lineEnding");
12994
+ return after;
12995
+ }
12996
+ function after(code3) {
12997
+ return self.parser.lazy[self.now().line] ? nok(code3) : ok3(code3);
12998
+ }
12999
+ }
13000
+
13001
+ // node_modules/micromark-core-commonmark/lib/code-fenced.js
13002
+ var codeFenced = {
13003
+ concrete: true,
13004
+ name: "codeFenced",
13005
+ tokenize: tokenizeCodeFenced
13006
+ };
12955
13007
  function tokenizeCodeFenced(effects, ok3, nok) {
12956
13008
  const self = this;
12957
13009
  const closeStart = {
@@ -13108,22 +13160,6 @@ function tokenizeCodeFenced(effects, ok3, nok) {
13108
13160
  }
13109
13161
  }
13110
13162
  }
13111
- function tokenizeNonLazyContinuation(effects, ok3, nok) {
13112
- const self = this;
13113
- return start;
13114
- function start(code3) {
13115
- if (code3 === null) {
13116
- return nok(code3);
13117
- }
13118
- effects.enter("lineEnding");
13119
- effects.consume(code3);
13120
- effects.exit("lineEnding");
13121
- return lineStart;
13122
- }
13123
- function lineStart(code3) {
13124
- return self.parser.lazy[self.now().line] ? nok(code3) : ok3(code3);
13125
- }
13126
- }
13127
13163
 
13128
13164
  // node_modules/micromark-core-commonmark/lib/code-indented.js
13129
13165
  var codeIndented = {
@@ -13135,15 +13171,10 @@ var furtherStart = {
13135
13171
  tokenize: tokenizeFurtherStart
13136
13172
  };
13137
13173
  function tokenizeCodeIndented(effects, ok3, nok) {
13138
- const self = this;
13139
13174
  return start;
13140
13175
  function start(code3) {
13141
13176
  effects.enter("codeIndented");
13142
- return factorySpace(effects, afterPrefix, "linePrefix", 4 + 1)(code3);
13143
- }
13144
- function afterPrefix(code3) {
13145
- const tail = self.events[self.events.length - 1];
13146
- return tail && tail[1].type === "linePrefix" && tail[2].sliceSerialize(tail[1], true).length >= 4 ? atBreak(code3) : nok(code3);
13177
+ return factorySpaceMinMax(effects, atBreak, nok, "linePrefix", 4, 4)(code3);
13147
13178
  }
13148
13179
  function atBreak(code3) {
13149
13180
  if (code3 === null) {
@@ -13181,11 +13212,10 @@ function tokenizeFurtherStart(effects, ok3, nok) {
13181
13212
  effects.exit("lineEnding");
13182
13213
  return furtherStart2;
13183
13214
  }
13184
- return factorySpace(effects, afterPrefix, "linePrefix", 4 + 1)(code3);
13215
+ return factorySpaceMinMax(effects, ok3, onNotEnoughPrefix, "linePrefix", 4, 4)(code3);
13185
13216
  }
13186
- function afterPrefix(code3) {
13187
- const tail = self.events[self.events.length - 1];
13188
- return tail && tail[1].type === "linePrefix" && tail[2].sliceSerialize(tail[1], true).length >= 4 ? ok3(code3) : markdownLineEnding(code3) ? furtherStart2(code3) : nok(code3);
13217
+ function onNotEnoughPrefix(code3) {
13218
+ return markdownLineEnding(code3) ? furtherStart2(code3) : nok(code3);
13189
13219
  }
13190
13220
  }
13191
13221
 
@@ -14071,8 +14101,6 @@ var headingAtx = {
14071
14101
  function resolveHeadingAtx(events, context) {
14072
14102
  let contentEnd = events.length - 2;
14073
14103
  let contentStart = 3;
14074
- let content3;
14075
- let text5;
14076
14104
  if (events[contentStart][1].type === "whitespace") {
14077
14105
  contentStart += 2;
14078
14106
  }
@@ -14083,12 +14111,12 @@ function resolveHeadingAtx(events, context) {
14083
14111
  contentEnd -= contentStart + 1 === contentEnd ? 2 : 4;
14084
14112
  }
14085
14113
  if (contentEnd > contentStart) {
14086
- content3 = {
14114
+ const content3 = {
14087
14115
  type: "atxHeadingText",
14088
14116
  start: events[contentStart][1].start,
14089
14117
  end: events[contentEnd][1].end
14090
14118
  };
14091
- text5 = {
14119
+ const text5 = {
14092
14120
  type: "chunkText",
14093
14121
  start: events[contentStart][1].start,
14094
14122
  end: events[contentEnd][1].end,
@@ -14153,73 +14181,6 @@ function tokenizeHeadingAtx(effects, ok3, nok) {
14153
14181
  }
14154
14182
  }
14155
14183
 
14156
- // node_modules/micromark-util-html-tag-name/index.js
14157
- var htmlBlockNames = [
14158
- "address",
14159
- "article",
14160
- "aside",
14161
- "base",
14162
- "basefont",
14163
- "blockquote",
14164
- "body",
14165
- "caption",
14166
- "center",
14167
- "col",
14168
- "colgroup",
14169
- "dd",
14170
- "details",
14171
- "dialog",
14172
- "dir",
14173
- "div",
14174
- "dl",
14175
- "dt",
14176
- "fieldset",
14177
- "figcaption",
14178
- "figure",
14179
- "footer",
14180
- "form",
14181
- "frame",
14182
- "frameset",
14183
- "h1",
14184
- "h2",
14185
- "h3",
14186
- "h4",
14187
- "h5",
14188
- "h6",
14189
- "head",
14190
- "header",
14191
- "hr",
14192
- "html",
14193
- "iframe",
14194
- "legend",
14195
- "li",
14196
- "link",
14197
- "main",
14198
- "menu",
14199
- "menuitem",
14200
- "nav",
14201
- "noframes",
14202
- "ol",
14203
- "optgroup",
14204
- "option",
14205
- "p",
14206
- "param",
14207
- "search",
14208
- "section",
14209
- "summary",
14210
- "table",
14211
- "tbody",
14212
- "td",
14213
- "tfoot",
14214
- "th",
14215
- "thead",
14216
- "title",
14217
- "tr",
14218
- "track",
14219
- "ul"
14220
- ];
14221
- var htmlRawNames = ["pre", "script", "style", "textarea"];
14222
-
14223
14184
  // node_modules/micromark-core-commonmark/lib/html-flow.js
14224
14185
  var htmlFlow = {
14225
14186
  concrete: true,
@@ -14231,10 +14192,6 @@ var blankLineBefore = {
14231
14192
  partial: true,
14232
14193
  tokenize: tokenizeBlankLineBefore
14233
14194
  };
14234
- var nonLazyContinuationStart = {
14235
- partial: true,
14236
- tokenize: tokenizeNonLazyContinuationStart
14237
- };
14238
14195
  function resolveToHtmlFlow(events) {
14239
14196
  let index2 = events.length;
14240
14197
  while (index2--) {
@@ -14496,7 +14453,7 @@ function tokenizeHtmlFlow(effects, ok3, nok) {
14496
14453
  return continuation;
14497
14454
  }
14498
14455
  function continuationStart(code3) {
14499
- return effects.check(nonLazyContinuationStart, continuationStartNonLazy, continuationAfter)(code3);
14456
+ return effects.check(nonLazyContinuation, continuationStartNonLazy, continuationAfter)(code3);
14500
14457
  }
14501
14458
  function continuationStartNonLazy(code3) {
14502
14459
  effects.enter("lineEnding");
@@ -14573,22 +14530,6 @@ function tokenizeHtmlFlow(effects, ok3, nok) {
14573
14530
  return ok3(code3);
14574
14531
  }
14575
14532
  }
14576
- function tokenizeNonLazyContinuationStart(effects, ok3, nok) {
14577
- const self = this;
14578
- return start;
14579
- function start(code3) {
14580
- if (markdownLineEnding(code3)) {
14581
- effects.enter("lineEnding");
14582
- effects.consume(code3);
14583
- effects.exit("lineEnding");
14584
- return after;
14585
- }
14586
- return nok(code3);
14587
- }
14588
- function after(code3) {
14589
- return self.parser.lazy[self.now().line] ? nok(code3) : ok3(code3);
14590
- }
14591
- }
14592
14533
  function tokenizeBlankLineBefore(effects, ok3, nok) {
14593
14534
  return start;
14594
14535
  function start(code3) {
@@ -14941,12 +14882,11 @@ function resolveAllLabelEnd(events) {
14941
14882
  function resolveToLabelEnd(events, context) {
14942
14883
  let index2 = events.length;
14943
14884
  let offset = 0;
14944
- let token;
14945
14885
  let open;
14946
14886
  let close2;
14947
14887
  let media;
14948
14888
  while (index2--) {
14949
- token = events[index2][1];
14889
+ const token = events[index2][1];
14950
14890
  if (open) {
14951
14891
  if (token.type === "link" || token.type === "labelLink" && token._inactive) {
14952
14892
  break;
@@ -15005,14 +14945,14 @@ function resolveToLabelEnd(events, context) {
15005
14945
  }
15006
14946
  function tokenizeLabelEnd(effects, ok3, nok) {
15007
14947
  const self = this;
15008
- let index2 = self.events.length;
14948
+ const labelStarts = self._labelStarts;
15009
14949
  let labelStart;
15010
14950
  let defined;
15011
- while (index2--) {
15012
- if ((self.events[index2][1].type === "labelImage" || self.events[index2][1].type === "labelLink") && !self.events[index2][1]._balanced) {
15013
- labelStart = self.events[index2][1];
15014
- break;
14951
+ if (labelStarts) {
14952
+ while (labelStarts.length > 0 && labelStarts[labelStarts.length - 1]._balanced) {
14953
+ labelStarts.pop();
15015
14954
  }
14955
+ labelStart = labelStarts[labelStarts.length - 1];
15016
14956
  }
15017
14957
  return start;
15018
14958
  function start(code3) {
@@ -15046,6 +14986,7 @@ function tokenizeLabelEnd(effects, ok3, nok) {
15046
14986
  return effects.attempt(referenceCollapsedConstruct, labelEndOk, labelEndNok)(code3);
15047
14987
  }
15048
14988
  function labelEndOk(code3) {
14989
+ labelStarts.pop();
15049
14990
  return ok3(code3);
15050
14991
  }
15051
14992
  function labelEndNok(code3) {
@@ -15139,6 +15080,7 @@ var labelStartImage = {
15139
15080
  };
15140
15081
  function tokenizeLabelStartImage(effects, ok3, nok) {
15141
15082
  const self = this;
15083
+ let labelImage;
15142
15084
  return start;
15143
15085
  function start(code3) {
15144
15086
  effects.enter("labelImage");
@@ -15152,13 +15094,18 @@ function tokenizeLabelStartImage(effects, ok3, nok) {
15152
15094
  effects.enter("labelMarker");
15153
15095
  effects.consume(code3);
15154
15096
  effects.exit("labelMarker");
15155
- effects.exit("labelImage");
15097
+ labelImage = effects.exit("labelImage");
15156
15098
  return after;
15157
15099
  }
15158
15100
  return nok(code3);
15159
15101
  }
15160
15102
  function after(code3) {
15161
- return code3 === 94 && "_hiddenFootnoteSupport" in self.parser.constructs ? nok(code3) : ok3(code3);
15103
+ if (code3 === 94 && "_hiddenFootnoteSupport" in self.parser.constructs) {
15104
+ return nok(code3);
15105
+ }
15106
+ self._labelStarts = self._labelStarts || [];
15107
+ self._labelStarts.push(labelImage);
15108
+ return ok3(code3);
15162
15109
  }
15163
15110
  }
15164
15111
 
@@ -15170,17 +15117,23 @@ var labelStartLink = {
15170
15117
  };
15171
15118
  function tokenizeLabelStartLink(effects, ok3, nok) {
15172
15119
  const self = this;
15120
+ let labelLink;
15173
15121
  return start;
15174
15122
  function start(code3) {
15175
15123
  effects.enter("labelLink");
15176
15124
  effects.enter("labelMarker");
15177
15125
  effects.consume(code3);
15178
15126
  effects.exit("labelMarker");
15179
- effects.exit("labelLink");
15127
+ labelLink = effects.exit("labelLink");
15180
15128
  return after;
15181
15129
  }
15182
15130
  function after(code3) {
15183
- return code3 === 94 && "_hiddenFootnoteSupport" in self.parser.constructs ? nok(code3) : ok3(code3);
15131
+ if (code3 === 94 && "_hiddenFootnoteSupport" in self.parser.constructs) {
15132
+ return nok(code3);
15133
+ }
15134
+ self._labelStarts = self._labelStarts || [];
15135
+ self._labelStarts.push(labelLink);
15136
+ return ok3(code3);
15184
15137
  }
15185
15138
  }
15186
15139
 
@@ -15368,6 +15321,104 @@ function tokenizeListItemPrefixWhitespace(effects, ok3, nok) {
15368
15321
  }
15369
15322
  }
15370
15323
 
15324
+ // node_modules/micromark-util-edit-map/index.js
15325
+ var EditMap = class {
15326
+ /**
15327
+ * Create a new edit map.
15328
+ *
15329
+ * @returns
15330
+ * New instance.
15331
+ */
15332
+ constructor() {
15333
+ this.index = /* @__PURE__ */ new Map();
15334
+ this.map = [];
15335
+ }
15336
+ /**
15337
+ * Create an edit: a remove and/or add at a certain place.
15338
+ *
15339
+ * @param {number} index
15340
+ * Index at which to apply the edit.
15341
+ * @param {number} remove
15342
+ * Count of items to remove at the index.
15343
+ * @param {Array<Event>} add
15344
+ * Items to add at the index.
15345
+ * @returns {undefined}
15346
+ * Nothing.
15347
+ */
15348
+ add(index2, remove, add) {
15349
+ addImplementation(this, index2, remove, add, false);
15350
+ }
15351
+ /**
15352
+ * Create an edit: but insert `add` before existing additions, instead of
15353
+ * after them.
15354
+ *
15355
+ * @param {number} index
15356
+ * Index at which to apply the edit.
15357
+ * @param {number} remove
15358
+ * Count of items to remove at the index.
15359
+ * @param {Array<Event>} add
15360
+ * Items to add at the index.
15361
+ * @returns {undefined}
15362
+ * Nothing.
15363
+ */
15364
+ addBefore(index2, remove, add) {
15365
+ addImplementation(this, index2, remove, add, true);
15366
+ }
15367
+ /**
15368
+ * Done, change the events.
15369
+ *
15370
+ * @param {Array<Event>} events
15371
+ * List of events to apply the edits to.
15372
+ * @returns {undefined}
15373
+ * Nothing.
15374
+ */
15375
+ consume(events) {
15376
+ this.map.sort(function(a, b) {
15377
+ return a[0] - b[0];
15378
+ });
15379
+ if (this.map.length === 0) {
15380
+ return;
15381
+ }
15382
+ let index2 = this.map.length;
15383
+ const vecs = [];
15384
+ while (index2 > 0) {
15385
+ index2 -= 1;
15386
+ vecs.push(events.slice(this.map[index2][0] + this.map[index2][1]), this.map[index2][2]);
15387
+ events.length = this.map[index2][0];
15388
+ }
15389
+ vecs.push(events.slice());
15390
+ events.length = 0;
15391
+ let slice = vecs.pop();
15392
+ while (slice) {
15393
+ for (const element of slice) {
15394
+ events.push(element);
15395
+ }
15396
+ slice = vecs.pop();
15397
+ }
15398
+ this.map.length = 0;
15399
+ this.index.clear();
15400
+ }
15401
+ };
15402
+ function addImplementation(editMap, at, remove, add, before) {
15403
+ if (remove === 0 && add.length === 0) {
15404
+ return;
15405
+ }
15406
+ const existing = editMap.index.get(at);
15407
+ if (existing) {
15408
+ existing[1] += remove;
15409
+ if (before) {
15410
+ add.push(...existing[2]);
15411
+ existing[2] = add;
15412
+ } else {
15413
+ existing[2].push(...add);
15414
+ }
15415
+ return;
15416
+ }
15417
+ const change = [at, remove, add];
15418
+ editMap.map.push(change);
15419
+ editMap.index.set(at, change);
15420
+ }
15421
+
15371
15422
  // node_modules/micromark-core-commonmark/lib/setext-underline.js
15372
15423
  var setextUnderline = {
15373
15424
  name: "setextUnderline",
@@ -15375,6 +15426,7 @@ var setextUnderline = {
15375
15426
  tokenize: tokenizeSetextUnderline
15376
15427
  };
15377
15428
  function resolveToSetextUnderline(events, context) {
15429
+ const editMap = new EditMap();
15378
15430
  let index2 = events.length;
15379
15431
  let content3;
15380
15432
  let text5;
@@ -15390,7 +15442,7 @@ function resolveToSetextUnderline(events, context) {
15390
15442
  }
15391
15443
  } else {
15392
15444
  if (events[index2][1].type === "content") {
15393
- events.splice(index2, 1);
15445
+ editMap.add(index2, 1, []);
15394
15446
  }
15395
15447
  if (!definition3 && events[index2][1].type === "definition") {
15396
15448
  definition3 = index2;
@@ -15408,15 +15460,16 @@ function resolveToSetextUnderline(events, context) {
15408
15460
  };
15409
15461
  events[text5][1].type = "setextHeadingText";
15410
15462
  if (definition3) {
15411
- events.splice(text5, 0, ["enter", heading2, context]);
15412
- events.splice(definition3 + 1, 0, ["exit", events[content3][1], context]);
15463
+ editMap.add(text5, 0, [["enter", heading2, context]]);
15464
+ editMap.add(definition3 + 1, 0, [["exit", events[content3][1], context]]);
15413
15465
  events[content3][1].end = {
15414
15466
  ...events[definition3][1].end
15415
15467
  };
15416
15468
  } else {
15417
15469
  events[content3][1] = heading2;
15418
15470
  }
15419
- events.push(["exit", heading2, context]);
15471
+ editMap.add(events.length, 0, [["exit", heading2, context]]);
15472
+ editMap.consume(events);
15420
15473
  return events;
15421
15474
  }
15422
15475
  function tokenizeSetextUnderline(effects, ok3, nok) {
@@ -15830,23 +15883,28 @@ function gfmStrikethrough(options) {
15830
15883
  }
15831
15884
 
15832
15885
  // node_modules/micromark-extension-gfm-table/lib/edit-map.js
15833
- var EditMap = class {
15886
+ var EditMap2 = class {
15834
15887
  /**
15835
15888
  * Create a new edit map.
15836
15889
  */
15837
15890
  constructor() {
15838
15891
  this.map = [];
15892
+ this.index = /* @__PURE__ */ new Map();
15839
15893
  }
15840
15894
  /**
15841
15895
  * Create an edit: a remove and/or add at a certain place.
15842
15896
  *
15843
15897
  * @param {number} index
15898
+ * Index at which to apply the edit.
15844
15899
  * @param {number} remove
15900
+ * Count of items to remove at the index.
15845
15901
  * @param {Array<Event>} add
15902
+ * Items to add at the index.
15846
15903
  * @returns {undefined}
15904
+ * Nothing.
15847
15905
  */
15848
15906
  add(index2, remove, add) {
15849
- addImplementation(this, index2, remove, add);
15907
+ addImplementation2(this, index2, remove, add);
15850
15908
  }
15851
15909
  // To do: add this when moving to `micromark`.
15852
15910
  // /**
@@ -15864,7 +15922,9 @@ var EditMap = class {
15864
15922
  * Done, change the events.
15865
15923
  *
15866
15924
  * @param {Array<Event>} events
15925
+ * List of events to apply the edits to.
15867
15926
  * @returns {undefined}
15927
+ * Nothing.
15868
15928
  */
15869
15929
  consume(events) {
15870
15930
  this.map.sort(function(a, b) {
@@ -15890,22 +15950,22 @@ var EditMap = class {
15890
15950
  slice = vecs.pop();
15891
15951
  }
15892
15952
  this.map.length = 0;
15953
+ this.index.clear();
15893
15954
  }
15894
15955
  };
15895
- function addImplementation(editMap, at, remove, add) {
15896
- let index2 = 0;
15956
+ function addImplementation2(editMap, at, remove, add) {
15897
15957
  if (remove === 0 && add.length === 0) {
15898
15958
  return;
15899
15959
  }
15900
- while (index2 < editMap.map.length) {
15901
- if (editMap.map[index2][0] === at) {
15902
- editMap.map[index2][1] += remove;
15903
- editMap.map[index2][2].push(...add);
15904
- return;
15905
- }
15906
- index2 += 1;
15960
+ const existing = editMap.index.get(at);
15961
+ if (existing) {
15962
+ existing[1] += remove;
15963
+ existing[2].push(...add);
15964
+ return;
15907
15965
  }
15908
- editMap.map.push([at, remove, add]);
15966
+ const change = [at, remove, add];
15967
+ editMap.map.push(change);
15968
+ editMap.index.set(at, change);
15909
15969
  }
15910
15970
 
15911
15971
  // node_modules/micromark-extension-gfm-table/lib/infer.js
@@ -15956,10 +16016,15 @@ function tokenizeTable(effects, ok3, nok) {
15956
16016
  function start(code3) {
15957
16017
  let index2 = self.events.length - 1;
15958
16018
  while (index2 > -1) {
15959
- const type = self.events[index2][1].type;
16019
+ const {
16020
+ type
16021
+ } = self.events[index2][1];
15960
16022
  if (type === "lineEnding" || // Note: markdown-rs uses `whitespace` instead of `linePrefix`
15961
- type === "linePrefix") index2--;
15962
- else break;
16023
+ type === "linePrefix") {
16024
+ index2--;
16025
+ } else {
16026
+ break;
16027
+ }
15963
16028
  }
15964
16029
  const tail = index2 > -1 ? self.events[index2][1].type : null;
15965
16030
  const next = tail === "tableHead" || tail === "tableRow" ? bodyRowStart : headRowBefore;
@@ -16173,7 +16238,7 @@ function resolveTable(events, context) {
16173
16238
  let currentTable;
16174
16239
  let currentBody;
16175
16240
  let currentCell;
16176
- const map3 = new EditMap();
16241
+ const map3 = new EditMap2();
16177
16242
  while (++index2 < events.length) {
16178
16243
  const event = events[index2];
16179
16244
  const token = event[1];
@@ -16520,8 +16585,10 @@ function initializeDocument(effects) {
16520
16585
  };
16521
16586
  index2++;
16522
16587
  }
16523
- splice(self.events, indexBeforeFlow + 1, 0, self.events.slice(indexBeforeExits));
16524
- self.events.length = index2;
16588
+ const editMap = new EditMap();
16589
+ editMap.add(indexBeforeFlow + 1, 0, self.events.slice(indexBeforeExits));
16590
+ editMap.add(indexBeforeExits, index2 - indexBeforeExits, []);
16591
+ editMap.consume(self.events);
16525
16592
  return checkNewContainers(code3);
16526
16593
  }
16527
16594
  return start(code3);
@@ -16540,7 +16607,9 @@ function initializeDocument(effects) {
16540
16607
  return effects.check(containerConstruct, thereIsANewContainer, thereIsNoNewContainer)(code3);
16541
16608
  }
16542
16609
  function thereIsANewContainer(code3) {
16543
- if (childFlow) closeFlow();
16610
+ if (childFlow) {
16611
+ closeFlow();
16612
+ }
16544
16613
  exitContainers(continued);
16545
16614
  return documentContinued(code3);
16546
16615
  }
@@ -16560,7 +16629,9 @@ function initializeDocument(effects) {
16560
16629
  }
16561
16630
  function flowStart(code3) {
16562
16631
  if (code3 === null) {
16563
- if (childFlow) closeFlow();
16632
+ if (childFlow) {
16633
+ closeFlow();
16634
+ }
16564
16635
  exitContainers(0);
16565
16636
  effects.consume(code3);
16566
16637
  return;
@@ -16592,9 +16663,13 @@ function initializeDocument(effects) {
16592
16663
  }
16593
16664
  function writeToChild(token, endOfFile) {
16594
16665
  const stream = self.sliceStream(token);
16595
- if (endOfFile) stream.push(null);
16666
+ if (endOfFile) {
16667
+ stream.push(null);
16668
+ }
16596
16669
  token.previous = childToken;
16597
- if (childToken) childToken.next = token;
16670
+ if (childToken) {
16671
+ childToken.next = token;
16672
+ }
16598
16673
  childToken = token;
16599
16674
  childFlow.defineSkip(token.start);
16600
16675
  childFlow.write(stream);
@@ -16631,8 +16706,10 @@ function initializeDocument(effects) {
16631
16706
  };
16632
16707
  index2++;
16633
16708
  }
16634
- splice(self.events, indexBeforeFlow + 1, 0, self.events.slice(indexBeforeExits));
16635
- self.events.length = index2;
16709
+ const editMap = new EditMap();
16710
+ editMap.add(indexBeforeFlow + 1, 0, self.events.slice(indexBeforeExits));
16711
+ editMap.add(indexBeforeExits, index2 - indexBeforeExits, []);
16712
+ editMap.consume(self.events);
16636
16713
  }
16637
16714
  }
16638
16715
  function exitContainers(size) {
@@ -16771,6 +16848,7 @@ function createResolver(extraResolver) {
16771
16848
  }
16772
16849
  }
16773
16850
  function resolveAllLineSuffixes(events, context) {
16851
+ const editMap = new EditMap();
16774
16852
  let eventIndex = 0;
16775
16853
  while (++eventIndex <= events.length) {
16776
16854
  if ((eventIndex === events.length || events[eventIndex][1].type === "lineEnding") && events[eventIndex - 1][1].type === "data") {
@@ -16788,7 +16866,9 @@ function resolveAllLineSuffixes(events, context) {
16788
16866
  size++;
16789
16867
  bufferIndex--;
16790
16868
  }
16791
- if (bufferIndex) break;
16869
+ if (bufferIndex) {
16870
+ break;
16871
+ }
16792
16872
  bufferIndex = -1;
16793
16873
  } else if (chunk === -2) {
16794
16874
  tabs = true;
@@ -16822,13 +16902,13 @@ function resolveAllLineSuffixes(events, context) {
16822
16902
  if (data.start.offset === data.end.offset) {
16823
16903
  Object.assign(data, token);
16824
16904
  } else {
16825
- events.splice(eventIndex, 0, ["enter", token, context], ["exit", token, context]);
16826
- eventIndex += 2;
16905
+ editMap.add(eventIndex, 0, [["enter", token, context], ["exit", token, context]]);
16827
16906
  }
16828
16907
  }
16829
16908
  eventIndex++;
16830
16909
  }
16831
16910
  }
16911
+ editMap.consume(events);
16832
16912
  return events;
16833
16913
  }
16834
16914
 
@@ -16889,16 +16969,16 @@ var text4 = {
16889
16969
  [-3]: lineEnding,
16890
16970
  [33]: labelStartImage,
16891
16971
  [38]: characterReference,
16892
- [42]: attention,
16972
+ [42]: attention3,
16893
16973
  [60]: [autolink, htmlText],
16894
16974
  [91]: labelStartLink,
16895
16975
  [92]: [hardBreakEscape, characterEscape],
16896
16976
  [93]: labelEnd,
16897
- [95]: attention,
16977
+ [95]: attention3,
16898
16978
  [96]: codeText
16899
16979
  };
16900
16980
  var insideSpan = {
16901
- null: [attention, resolver]
16981
+ null: [attention3, resolver]
16902
16982
  };
16903
16983
  var attentionMarkers = {
16904
16984
  null: [42, 95]
@@ -16986,11 +17066,10 @@ function createTokenizer(parser, initialize, from) {
16986
17066
  accountForPotentialSkip();
16987
17067
  }
16988
17068
  function main() {
16989
- let chunkIndex;
16990
17069
  while (point3._index < chunks.length) {
16991
17070
  const chunk = chunks[point3._index];
16992
17071
  if (typeof chunk === "string") {
16993
- chunkIndex = point3._index;
17072
+ const chunkIndex = point3._index;
16994
17073
  if (point3._bufferIndex < 0) {
16995
17074
  point3._bufferIndex = 0;
16996
17075
  }
@@ -17198,30 +17277,34 @@ function serializeChunks(chunks, expandTabs) {
17198
17277
  let value2;
17199
17278
  if (typeof chunk === "string") {
17200
17279
  value2 = chunk;
17201
- } else switch (chunk) {
17202
- case -5: {
17203
- value2 = "\r";
17204
- break;
17205
- }
17206
- case -4: {
17207
- value2 = "\n";
17208
- break;
17209
- }
17210
- case -3: {
17211
- value2 = "\r\n";
17212
- break;
17213
- }
17214
- case -2: {
17215
- value2 = expandTabs ? " " : " ";
17216
- break;
17217
- }
17218
- case -1: {
17219
- if (!expandTabs && atTab) continue;
17220
- value2 = " ";
17221
- break;
17222
- }
17223
- default: {
17224
- value2 = String.fromCharCode(chunk);
17280
+ } else {
17281
+ switch (chunk) {
17282
+ case -5: {
17283
+ value2 = "\r";
17284
+ break;
17285
+ }
17286
+ case -4: {
17287
+ value2 = "\n";
17288
+ break;
17289
+ }
17290
+ case -3: {
17291
+ value2 = "\r\n";
17292
+ break;
17293
+ }
17294
+ case -2: {
17295
+ value2 = expandTabs ? " " : " ";
17296
+ break;
17297
+ }
17298
+ case -1: {
17299
+ if (!expandTabs && atTab) {
17300
+ continue;
17301
+ }
17302
+ value2 = " ";
17303
+ break;
17304
+ }
17305
+ default: {
17306
+ value2 = String.fromCharCode(chunk);
17307
+ }
17225
17308
  }
17226
17309
  }
17227
17310
  atTab = chunk === -2;
@@ -17272,14 +17355,9 @@ function preprocess() {
17272
17355
  let atCarriageReturn;
17273
17356
  return preprocessor;
17274
17357
  function preprocessor(value2, encoding, end) {
17275
- const chunks = [];
17276
- let match;
17277
- let next;
17278
- let startPosition;
17279
- let endPosition;
17280
- let code3;
17281
17358
  value2 = buffer + (typeof value2 === "string" ? value2.toString() : new TextDecoder(encoding || void 0).decode(value2));
17282
- startPosition = 0;
17359
+ const chunks = [];
17360
+ let startPosition = 0;
17283
17361
  buffer = "";
17284
17362
  if (start) {
17285
17363
  if (value2.charCodeAt(0) === 65279) {
@@ -17289,9 +17367,9 @@ function preprocess() {
17289
17367
  }
17290
17368
  while (startPosition < value2.length) {
17291
17369
  search.lastIndex = startPosition;
17292
- match = search.exec(value2);
17293
- endPosition = match && match.index !== void 0 ? match.index : value2.length;
17294
- code3 = value2.charCodeAt(endPosition);
17370
+ const match = search.exec(value2);
17371
+ const endPosition = match && match.index !== void 0 ? match.index : value2.length;
17372
+ const code3 = value2.charCodeAt(endPosition);
17295
17373
  if (!match) {
17296
17374
  buffer = value2.slice(startPosition);
17297
17375
  break;
@@ -17315,9 +17393,11 @@ function preprocess() {
17315
17393
  break;
17316
17394
  }
17317
17395
  case 9: {
17318
- next = Math.ceil(column / 4) * 4;
17396
+ const next = Math.ceil(column / 4) * 4;
17319
17397
  chunks.push(-2);
17320
- while (column++ < next) chunks.push(-1);
17398
+ while (column++ < next) {
17399
+ chunks.push(-1);
17400
+ }
17321
17401
  break;
17322
17402
  }
17323
17403
  case 10: {
@@ -17334,8 +17414,12 @@ function preprocess() {
17334
17414
  startPosition = endPosition + 1;
17335
17415
  }
17336
17416
  if (end) {
17337
- if (atCarriageReturn) chunks.push(-5);
17338
- if (buffer) chunks.push(buffer);
17417
+ if (atCarriageReturn) {
17418
+ chunks.push(-5);
17419
+ }
17420
+ if (buffer) {
17421
+ chunks.push(buffer);
17422
+ }
17339
17423
  chunks.push(null);
17340
17424
  }
17341
17425
  return chunks;
@@ -17379,6 +17463,8 @@ function fromMarkdown(value2, encoding, options) {
17379
17463
  }
17380
17464
  function compiler(options) {
17381
17465
  const config = {
17466
+ afterExit: [],
17467
+ beforeEnter: [],
17382
17468
  transforms: [],
17383
17469
  canContainEols: ["emphasis", "fragment", "heading", "paragraph", "strong"],
17384
17470
  enter: {
@@ -17482,7 +17568,8 @@ function compiler(options) {
17482
17568
  function compile(events) {
17483
17569
  let tree = {
17484
17570
  type: "root",
17485
- children: []
17571
+ children: [],
17572
+ position: void 0
17486
17573
  };
17487
17574
  const context = {
17488
17575
  stack: [tree],
@@ -17495,24 +17582,40 @@ function compiler(options) {
17495
17582
  data
17496
17583
  };
17497
17584
  const listStack = [];
17585
+ const prepared = [];
17498
17586
  let index2 = -1;
17499
17587
  while (++index2 < events.length) {
17588
+ prepared.push(events[index2]);
17500
17589
  if (events[index2][1].type === "listOrdered" || events[index2][1].type === "listUnordered") {
17501
17590
  if (events[index2][0] === "enter") {
17502
- listStack.push(index2);
17591
+ listStack.push(prepared.length - 1);
17503
17592
  } else {
17504
17593
  const tail = listStack.pop();
17505
- index2 = prepareList(events, tail, index2);
17594
+ prepareList(prepared, tail);
17506
17595
  }
17507
17596
  }
17508
17597
  }
17598
+ events = prepared;
17509
17599
  index2 = -1;
17510
17600
  while (++index2 < events.length) {
17511
17601
  const handler2 = config[events[index2][0]];
17602
+ if (events[index2][0] === "enter" && config.beforeEnter.length > 0) {
17603
+ callListeners(config.beforeEnter, {
17604
+ ...context,
17605
+ sliceSerialize: events[index2][2].sliceSerialize
17606
+ }, events[index2][1]);
17607
+ }
17512
17608
  if (own3.call(handler2, events[index2][1].type)) {
17513
- handler2[events[index2][1].type].call(Object.assign({
17609
+ handler2[events[index2][1].type].call({
17610
+ ...context,
17514
17611
  sliceSerialize: events[index2][2].sliceSerialize
17515
- }, context), events[index2][1]);
17612
+ }, events[index2][1]);
17613
+ }
17614
+ if (events[index2][0] === "exit" && config.afterExit.length > 0) {
17615
+ callListeners(config.afterExit, {
17616
+ ...context,
17617
+ sliceSerialize: events[index2][2].sliceSerialize
17618
+ }, events[index2][1]);
17516
17619
  }
17517
17620
  }
17518
17621
  if (context.tokenStack.length > 0) {
@@ -17538,7 +17641,14 @@ function compiler(options) {
17538
17641
  }
17539
17642
  return tree;
17540
17643
  }
17541
- function prepareList(events, start, length) {
17644
+ function callListeners(listeners, context, token) {
17645
+ let index2 = -1;
17646
+ while (++index2 < listeners.length) {
17647
+ listeners[index2].call(context, token);
17648
+ }
17649
+ }
17650
+ function prepareList(events, start) {
17651
+ const end = events.length - 1;
17542
17652
  let index2 = start - 1;
17543
17653
  let containerBalance = -1;
17544
17654
  let listSpread = false;
@@ -17546,7 +17656,8 @@ function compiler(options) {
17546
17656
  let lineIndex;
17547
17657
  let firstBlankLineIndex;
17548
17658
  let atMarker;
17549
- while (++index2 <= length) {
17659
+ const insertions = [];
17660
+ while (++index2 <= end) {
17550
17661
  const event = events[index2];
17551
17662
  switch (event[1].type) {
17552
17663
  case "listUnordered":
@@ -17603,9 +17714,10 @@ function compiler(options) {
17603
17714
  listItem3._spread = true;
17604
17715
  }
17605
17716
  listItem3.end = Object.assign({}, lineIndex ? events[lineIndex][1].start : event[1].end);
17606
- events.splice(lineIndex || index2, 0, ["exit", listItem3, event[2]]);
17607
- index2++;
17608
- length++;
17717
+ insertions.push({
17718
+ at: lineIndex || index2,
17719
+ event: ["exit", listItem3, event[2]]
17720
+ });
17609
17721
  }
17610
17722
  if (event[1].type === "listItemPrefix") {
17611
17723
  const item = {
@@ -17616,16 +17728,25 @@ function compiler(options) {
17616
17728
  end: void 0
17617
17729
  };
17618
17730
  listItem3 = item;
17619
- events.splice(index2, 0, ["enter", item, event[2]]);
17620
- index2++;
17621
- length++;
17731
+ insertions.push({
17732
+ at: index2,
17733
+ event: ["enter", item, event[2]]
17734
+ });
17622
17735
  firstBlankLineIndex = void 0;
17623
17736
  atMarker = true;
17624
17737
  }
17625
17738
  }
17626
17739
  }
17740
+ const listEvents = events.splice(start);
17741
+ let insertion = 0;
17742
+ index2 = -1;
17743
+ while (++index2 < listEvents.length) {
17744
+ while (insertion < insertions.length && insertions[insertion].at === start + index2) {
17745
+ events.push(insertions[insertion++].event);
17746
+ }
17747
+ events.push(listEvents[index2]);
17748
+ }
17627
17749
  events[start][1]._spread = listSpread;
17628
- return length;
17629
17750
  }
17630
17751
  function opener2(create2, and) {
17631
17752
  return open;
@@ -17667,7 +17788,8 @@ function compiler(options) {
17667
17788
  start: token.start,
17668
17789
  end: token.end
17669
17790
  }) + "): it\u2019s not open");
17670
- } else if (open[0].type !== token.type) {
17791
+ }
17792
+ if (open[0].type !== token.type) {
17671
17793
  if (onExitError) {
17672
17794
  onExitError.call(this, token, open[0]);
17673
17795
  } else {
@@ -17903,7 +18025,8 @@ function compiler(options) {
17903
18025
  function blockQuote2() {
17904
18026
  return {
17905
18027
  type: "blockquote",
17906
- children: []
18028
+ children: [],
18029
+ position: void 0
17907
18030
  };
17908
18031
  }
17909
18032
  function codeFlow() {
@@ -17911,13 +18034,15 @@ function compiler(options) {
17911
18034
  type: "code",
17912
18035
  lang: null,
17913
18036
  meta: null,
17914
- value: ""
18037
+ value: "",
18038
+ position: void 0
17915
18039
  };
17916
18040
  }
17917
18041
  function codeText2() {
17918
18042
  return {
17919
18043
  type: "inlineCode",
17920
- value: ""
18044
+ value: "",
18045
+ position: void 0
17921
18046
  };
17922
18047
  }
17923
18048
  function definition3() {
@@ -17926,13 +18051,15 @@ function compiler(options) {
17926
18051
  identifier: "",
17927
18052
  label: null,
17928
18053
  title: null,
17929
- url: ""
18054
+ url: "",
18055
+ position: void 0
17930
18056
  };
17931
18057
  }
17932
18058
  function emphasis2() {
17933
18059
  return {
17934
18060
  type: "emphasis",
17935
- children: []
18061
+ children: [],
18062
+ position: void 0
17936
18063
  };
17937
18064
  }
17938
18065
  function heading2() {
@@ -17940,18 +18067,21 @@ function compiler(options) {
17940
18067
  type: "heading",
17941
18068
  // @ts-expect-error `depth` will be set later.
17942
18069
  depth: 0,
17943
- children: []
18070
+ children: [],
18071
+ position: void 0
17944
18072
  };
17945
18073
  }
17946
18074
  function hardBreak2() {
17947
18075
  return {
17948
- type: "break"
18076
+ type: "break",
18077
+ position: void 0
17949
18078
  };
17950
18079
  }
17951
18080
  function html2() {
17952
18081
  return {
17953
18082
  type: "html",
17954
- value: ""
18083
+ value: "",
18084
+ position: void 0
17955
18085
  };
17956
18086
  }
17957
18087
  function image2() {
@@ -17959,7 +18089,8 @@ function compiler(options) {
17959
18089
  type: "image",
17960
18090
  title: null,
17961
18091
  url: "",
17962
- alt: null
18092
+ alt: null,
18093
+ position: void 0
17963
18094
  };
17964
18095
  }
17965
18096
  function link2() {
@@ -17967,7 +18098,8 @@ function compiler(options) {
17967
18098
  type: "link",
17968
18099
  title: null,
17969
18100
  url: "",
17970
- children: []
18101
+ children: [],
18102
+ position: void 0
17971
18103
  };
17972
18104
  }
17973
18105
  function list3(token) {
@@ -17976,7 +18108,8 @@ function compiler(options) {
17976
18108
  ordered: token.type === "listOrdered",
17977
18109
  start: null,
17978
18110
  spread: token._spread,
17979
- children: []
18111
+ children: [],
18112
+ position: void 0
17980
18113
  };
17981
18114
  }
17982
18115
  function listItem2(token) {
@@ -17984,30 +18117,35 @@ function compiler(options) {
17984
18117
  type: "listItem",
17985
18118
  spread: token._spread,
17986
18119
  checked: null,
17987
- children: []
18120
+ children: [],
18121
+ position: void 0
17988
18122
  };
17989
18123
  }
17990
18124
  function paragraph2() {
17991
18125
  return {
17992
18126
  type: "paragraph",
17993
- children: []
18127
+ children: [],
18128
+ position: void 0
17994
18129
  };
17995
18130
  }
17996
18131
  function strong2() {
17997
18132
  return {
17998
18133
  type: "strong",
17999
- children: []
18134
+ children: [],
18135
+ position: void 0
18000
18136
  };
18001
18137
  }
18002
18138
  function text5() {
18003
18139
  return {
18004
18140
  type: "text",
18005
- value: ""
18141
+ value: "",
18142
+ position: void 0
18006
18143
  };
18007
18144
  }
18008
18145
  function thematicBreak3() {
18009
18146
  return {
18010
- type: "thematicBreak"
18147
+ type: "thematicBreak",
18148
+ position: void 0
18011
18149
  };
18012
18150
  }
18013
18151
  }
@@ -18048,6 +18186,14 @@ function extension(combined, extension2) {
18048
18186
  }
18049
18187
  break;
18050
18188
  }
18189
+ case "afterExit":
18190
+ case "beforeEnter": {
18191
+ const right = extension2[key];
18192
+ if (right) {
18193
+ combined[key].push(right);
18194
+ }
18195
+ break;
18196
+ }
18051
18197
  case "enter":
18052
18198
  case "exit": {
18053
18199
  const right = extension2[key];
@@ -18069,12 +18215,11 @@ function defaultOnError(left, right) {
18069
18215
  start: right.start,
18070
18216
  end: right.end
18071
18217
  }) + ") is open");
18072
- } else {
18073
- throw new Error("Cannot close document, a token (`" + right.type + "`, " + stringifyPosition({
18074
- start: right.start,
18075
- end: right.end
18076
- }) + ") is still open");
18077
18218
  }
18219
+ throw new Error("Cannot close document, a token (`" + right.type + "`, " + stringifyPosition({
18220
+ start: right.start,
18221
+ end: right.end
18222
+ }) + ") is still open");
18078
18223
  }
18079
18224
 
18080
18225
  // node_modules/remark-parse/lib/index.js
@@ -19556,11 +19701,36 @@ function renderUnknownInline(node2, options) {
19556
19701
  return out;
19557
19702
  }
19558
19703
 
19704
+ // src/slug.ts
19705
+ function slugify(text5) {
19706
+ const slug = text5.toLowerCase().replace(/[^\p{L}\p{N}_ -]+/gu, "").replace(/ /g, "-");
19707
+ return slug;
19708
+ }
19709
+ function createHeadingSlugger() {
19710
+ const occurrences = /* @__PURE__ */ new Map();
19711
+ return {
19712
+ slug(text5) {
19713
+ const base = slugify(text5);
19714
+ let result = base;
19715
+ if (base !== "") {
19716
+ while (occurrences.has(result)) {
19717
+ const next = (occurrences.get(base) ?? 0) + 1;
19718
+ occurrences.set(base, next);
19719
+ result = `${base}-${next}`;
19720
+ }
19721
+ occurrences.set(result, 0);
19722
+ }
19723
+ return result;
19724
+ }
19725
+ };
19726
+ }
19727
+
19559
19728
  // src/types.ts
19560
19729
  function resolveOptions(options) {
19561
19730
  return {
19562
19731
  headingShift: options?.headingShift ?? 0,
19563
19732
  minHeadingLevel: options?.minHeadingLevel ?? 2,
19733
+ headingAnchors: options?.headingAnchors ?? false,
19564
19734
  resolveImage: options?.resolveImage,
19565
19735
  codeLanguage: options?.codeLanguage ?? "drop",
19566
19736
  unsupported: options?.unsupported ?? "html",
@@ -19635,20 +19805,51 @@ function renderCaption(caption) {
19635
19805
  return `<figcaption class="wp-element-caption">${escapeText(caption)}</figcaption>`;
19636
19806
  }
19637
19807
 
19808
+ // src/attributes.ts
19809
+ function serializeBlockAttributes(attributes) {
19810
+ let out = "";
19811
+ if (Object.keys(attributes).length > 0) {
19812
+ const json = JSON.stringify(attributes).replace(/--/g, "\\u002d\\u002d").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/ /g, "\\u00a0");
19813
+ out = ` ${json}`;
19814
+ }
19815
+ return out;
19816
+ }
19817
+
19638
19818
  // src/blocks/heading.ts
19639
19819
  function renderHeading(node2, ctx) {
19640
- const { headingShift, minHeadingLevel } = ctx.options;
19820
+ const { headingShift, minHeadingLevel, headingAnchors } = ctx.options;
19641
19821
  const shifted = node2.depth + headingShift;
19642
19822
  const level = Math.min(6, Math.max(minHeadingLevel, shifted));
19643
19823
  const inner = ctx.renderInline(node2.children);
19644
- const attrs = level === 2 ? "" : ` {"level":${level}}`;
19645
- const open = `<!-- wp:heading${attrs} -->`;
19646
- const tag = `<h${level} class="wp-block-heading">${inner}</h${level}>`;
19824
+ const anchor = headingAnchors ? ctx.slugger.slug(headingText(node2.children)) : "";
19825
+ const attributes = {};
19826
+ if (level !== 2) {
19827
+ attributes.level = level;
19828
+ }
19829
+ if (anchor !== "") {
19830
+ attributes.anchor = anchor;
19831
+ }
19832
+ const idAttr = anchor !== "" ? ` id="${anchor}"` : "";
19833
+ const open = `<!-- wp:heading${serializeBlockAttributes(attributes)} -->`;
19834
+ const tag = `<h${level}${idAttr} class="wp-block-heading">${inner}</h${level}>`;
19647
19835
  const close2 = "<!-- /wp:heading -->";
19648
19836
  return `${open}
19649
19837
  ${tag}
19650
19838
  ${close2}`;
19651
19839
  }
19840
+ function headingText(nodes) {
19841
+ let text5 = "";
19842
+ for (const node2 of nodes) {
19843
+ const value2 = node2.value;
19844
+ const children = node2.children;
19845
+ if (typeof value2 === "string") {
19846
+ text5 += value2;
19847
+ } else if (children != null) {
19848
+ text5 += headingText(children);
19849
+ }
19850
+ }
19851
+ return text5;
19852
+ }
19652
19853
 
19653
19854
  // src/blocks/list.ts
19654
19855
  function renderList(node2, ctx) {
@@ -19785,6 +19986,7 @@ function resolveReferences(tree) {
19785
19986
  function createContext(options) {
19786
19987
  const context = {
19787
19988
  options,
19989
+ slugger: createHeadingSlugger(),
19788
19990
  renderInline(nodes) {
19789
19991
  return renderInline(nodes, options);
19790
19992
  },
@@ -19905,4 +20107,4 @@ export {
19905
20107
  markdownToBlocks,
19906
20108
  parseMarkdownDocument
19907
20109
  };
19908
- //# sourceMappingURL=chunk-7B766ZGD.js.map
20110
+ //# sourceMappingURL=chunk-FWYKR6IX.js.map