stream-markdown-parser 0.0.33 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -601,7 +601,7 @@ var require_markdown_it_task_checkbox = /* @__PURE__ */ __commonJS({ "../../node
601
601
  }) });
602
602
 
603
603
  //#endregion
604
- //#region ../../node_modules/.pnpm/markdown-it-ts@0.0.2-beta.8/node_modules/markdown-it-ts/dist/chunk-Bp6m_JJh.js
604
+ //#region ../../node_modules/.pnpm/markdown-it-ts@0.0.2-beta.9/node_modules/markdown-it-ts/dist/chunk-Bp6m_JJh.js
605
605
  var import_markdown_it_task_checkbox = /* @__PURE__ */ __toESM(require_markdown_it_task_checkbox(), 1);
606
606
  var __defProp = Object.defineProperty;
607
607
  var __export = (all) => {
@@ -2187,7 +2187,7 @@ var require_punycode = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/pu
2187
2187
  }) });
2188
2188
 
2189
2189
  //#endregion
2190
- //#region ../../node_modules/.pnpm/markdown-it-ts@0.0.2-beta.8/node_modules/markdown-it-ts/dist/index.js
2190
+ //#region ../../node_modules/.pnpm/markdown-it-ts@0.0.2-beta.9/node_modules/markdown-it-ts/dist/index.js
2191
2191
  var import_punycode = /* @__PURE__ */ __toESM(require_punycode(), 1);
2192
2192
  var utils_exports = /* @__PURE__ */ __export({
2193
2193
  arrayReplaceAt: () => arrayReplaceAt,
@@ -5708,12 +5708,10 @@ var Renderer = class {
5708
5708
  rules;
5709
5709
  baseOptions;
5710
5710
  normalizedBase;
5711
- bufferPool;
5712
5711
  constructor(options = {}) {
5713
5712
  this.baseOptions = { ...options };
5714
5713
  this.normalizedBase = this.buildNormalizedBase();
5715
5714
  this.rules = { ...defaultRules };
5716
- this.bufferPool = [];
5717
5715
  }
5718
5716
  set(options) {
5719
5717
  this.baseOptions = {
@@ -5723,65 +5721,54 @@ var Renderer = class {
5723
5721
  this.normalizedBase = this.buildNormalizedBase();
5724
5722
  return this;
5725
5723
  }
5726
- render(tokens, options = {}, env = {}) {
5724
+ render(tokens, options, env) {
5727
5725
  if (!Array.isArray(tokens)) throw new TypeError("render expects token array as first argument");
5728
5726
  const merged = this.mergeOptions(options);
5729
- const chunks = this.acquireBuffer();
5727
+ const envRef = env ?? {};
5728
+ let output = "";
5730
5729
  for (let i = 0; i < tokens.length; i++) {
5731
5730
  const token = tokens[i];
5732
5731
  if (token.type === "inline") {
5733
- this.pushInlineTokens(token.children || [], merged, env, chunks);
5732
+ output += this.renderInlineTokens(token.children || [], merged, envRef);
5734
5733
  continue;
5735
5734
  }
5736
5735
  const rule = this.rules[token.type];
5737
- if (rule) chunks.push(ensureSyncResult(rule(tokens, i, merged, env, this), token.type));
5738
- else chunks.push(this.renderToken(tokens, i, merged));
5736
+ if (rule) output += ensureSyncResult(rule(tokens, i, merged, envRef, this), token.type);
5737
+ else output += this.renderToken(tokens, i, merged);
5739
5738
  }
5740
- const output = chunks.join("");
5741
- this.releaseBuffer(chunks);
5742
5739
  return output;
5743
5740
  }
5744
- async renderAsync(tokens, options = {}, env = {}) {
5741
+ async renderAsync(tokens, options, env) {
5745
5742
  if (!Array.isArray(tokens)) throw new TypeError("render expects token array as first argument");
5746
5743
  const merged = this.mergeOptions(options);
5747
- const chunks = this.acquireBuffer();
5744
+ const envRef = env ?? {};
5745
+ let output = "";
5748
5746
  for (let i = 0; i < tokens.length; i++) {
5749
5747
  const token = tokens[i];
5750
5748
  if (token.type === "inline") {
5751
- await this.pushInlineTokensAsync(token.children || [], merged, env, chunks);
5749
+ output += await this.renderInlineTokensAsync(token.children || [], merged, envRef);
5752
5750
  continue;
5753
5751
  }
5754
5752
  const rule = this.rules[token.type];
5755
- if (rule) chunks.push(await resolveResult(rule(tokens, i, merged, env, this)));
5756
- else chunks.push(this.renderToken(tokens, i, merged));
5753
+ if (rule) output += await resolveResult(rule(tokens, i, merged, envRef, this));
5754
+ else output += this.renderToken(tokens, i, merged);
5757
5755
  }
5758
- const output = chunks.join("");
5759
- this.releaseBuffer(chunks);
5760
5756
  return output;
5761
5757
  }
5762
- renderInline(tokens, options = {}, env = {}) {
5758
+ renderInline(tokens, options, env) {
5763
5759
  const merged = this.mergeOptions(options);
5764
- const chunks = this.acquireBuffer();
5765
- this.pushInlineTokens(tokens, merged, env, chunks);
5766
- const output = chunks.join("");
5767
- this.releaseBuffer(chunks);
5768
- return output;
5760
+ const envRef = env ?? {};
5761
+ return this.renderInlineTokens(tokens, merged, envRef);
5769
5762
  }
5770
- async renderInlineAsync(tokens, options = {}, env = {}) {
5763
+ async renderInlineAsync(tokens, options, env) {
5771
5764
  const merged = this.mergeOptions(options);
5772
- const chunks = this.acquireBuffer();
5773
- await this.pushInlineTokensAsync(tokens, merged, env, chunks);
5774
- const output = chunks.join("");
5775
- this.releaseBuffer(chunks);
5776
- return output;
5765
+ const envRef = env ?? {};
5766
+ return this.renderInlineTokensAsync(tokens, merged, envRef);
5777
5767
  }
5778
- renderInlineAsText(tokens, options = {}, env = {}) {
5768
+ renderInlineAsText(tokens, options, env) {
5779
5769
  const merged = this.mergeOptions(options);
5780
- const chunks = this.acquireBuffer();
5781
- this.renderInlineAsTextInternal(tokens, merged, env, chunks);
5782
- const output = chunks.join("");
5783
- this.releaseBuffer(chunks);
5784
- return output;
5770
+ const envRef = env ?? {};
5771
+ return this.renderInlineAsTextInternal(tokens, merged, envRef);
5785
5772
  }
5786
5773
  renderAttrs(token) {
5787
5774
  if (!token.attrs || token.attrs.length === 0) return "";
@@ -5841,56 +5828,53 @@ var Renderer = class {
5841
5828
  ...this.baseOptions
5842
5829
  });
5843
5830
  }
5844
- pushInlineTokens(tokens, options, env, buffer) {
5831
+ renderInlineTokens(tokens, options, env) {
5832
+ if (!tokens || tokens.length === 0) return "";
5833
+ let output = "";
5845
5834
  for (let i = 0; i < tokens.length; i++) {
5846
5835
  const token = tokens[i];
5847
5836
  const rule = this.rules[token.type];
5848
- if (rule) buffer.push(ensureSyncResult(rule(tokens, i, options, env, this), token.type));
5849
- else buffer.push(this.renderToken(tokens, i, options));
5837
+ if (rule) output += ensureSyncResult(rule(tokens, i, options, env, this), token.type);
5838
+ else output += this.renderToken(tokens, i, options);
5850
5839
  }
5840
+ return output;
5851
5841
  }
5852
- async pushInlineTokensAsync(tokens, options, env, buffer) {
5842
+ async renderInlineTokensAsync(tokens, options, env) {
5843
+ if (!tokens || tokens.length === 0) return "";
5844
+ let output = "";
5853
5845
  for (let i = 0; i < tokens.length; i++) {
5854
5846
  const token = tokens[i];
5855
5847
  const rule = this.rules[token.type];
5856
- if (rule) buffer.push(await resolveResult(rule(tokens, i, options, env, this)));
5857
- else buffer.push(this.renderToken(tokens, i, options));
5848
+ if (rule) output += await resolveResult(rule(tokens, i, options, env, this));
5849
+ else output += this.renderToken(tokens, i, options);
5858
5850
  }
5851
+ return output;
5859
5852
  }
5860
- renderInlineAsTextInternal(tokens, options, env, buffer) {
5853
+ renderInlineAsTextInternal(tokens, options, env) {
5854
+ if (!tokens || tokens.length === 0) return "";
5855
+ let output = "";
5861
5856
  for (let i = 0; i < tokens.length; i++) {
5862
5857
  const token = tokens[i];
5863
5858
  switch (token.type) {
5864
5859
  case "text":
5865
5860
  case "text_special":
5866
- buffer.push(token.content);
5861
+ output += token.content;
5867
5862
  break;
5868
5863
  case "image":
5869
- this.renderInlineAsTextInternal(token.children || [], options, env, buffer);
5864
+ output += this.renderInlineAsTextInternal(token.children || [], options, env);
5870
5865
  break;
5871
5866
  case "html_inline":
5872
5867
  case "html_block":
5873
- buffer.push(token.content);
5868
+ output += token.content;
5874
5869
  break;
5875
5870
  case "softbreak":
5876
5871
  case "hardbreak":
5877
- buffer.push("\n");
5872
+ output += "\n";
5878
5873
  break;
5879
5874
  default: break;
5880
5875
  }
5881
5876
  }
5882
- }
5883
- acquireBuffer() {
5884
- const buf = this.bufferPool.pop();
5885
- if (buf) {
5886
- buf.length = 0;
5887
- return buf;
5888
- }
5889
- return [];
5890
- }
5891
- releaseBuffer(buffer) {
5892
- buffer.length = 0;
5893
- this.bufferPool.push(buffer);
5877
+ return output;
5894
5878
  }
5895
5879
  };
5896
5880
  var renderer_default = Renderer;
@@ -7273,7 +7257,6 @@ function fixLinkToken(tokens) {
7273
7257
  i -= replacerTokens.length - 1;
7274
7258
  continue;
7275
7259
  } else if (curToken.content?.startsWith("](") && tokens[i - 1].type === "strong_close" && tokens[i - 4]?.type === "text" && tokens[i - 4]?.content?.includes("**[")) {
7276
- i++;
7277
7260
  const replacerTokens = [];
7278
7261
  const beforeText = tokens[i - 4].content.split("**[")[0];
7279
7262
  if (beforeText) replacerTokens.push(textToken(beforeText));
@@ -7787,7 +7770,14 @@ const WORDS_RE = /\b(?:sin|cos|tan|log|ln|exp|sqrt|frac|sum|lim|int|prod)\b/;
7787
7770
  const DATE_TIME_RE = /\b\d{4}\/\d{1,2}\/\d{1,2}(?:[ T]\d{1,2}:\d{2}(?::\d{2})?)?\b/;
7788
7771
  function isMathLike(s) {
7789
7772
  if (!s) return false;
7790
- const norm = s.replace(/\u0008/g, "\\b");
7773
+ const norm = s.replace(/[\u0008\v\f]/g, (ch) => {
7774
+ switch (ch) {
7775
+ case "\b": return "\\b";
7776
+ case "\v": return "\\v";
7777
+ case "\f": return "\\f";
7778
+ default: return ch;
7779
+ }
7780
+ });
7791
7781
  const stripped = norm.trim();
7792
7782
  if (DATE_TIME_RE.test(stripped)) return false;
7793
7783
  if (stripped.includes("**")) return false;
@@ -8040,7 +8030,7 @@ function applyMath(md, mathOpts) {
8040
8030
  }
8041
8031
  foundAny = true;
8042
8032
  if (!silent) {
8043
- const before = src.slice(0, index);
8033
+ const before = src.slice(s.pos - s.pending.length, index);
8044
8034
  let toPushBefore = src.slice(0, searchPos) ? src.slice(preMathPos, index) : before;
8045
8035
  const isStrongPrefix = countUnescapedStrong(toPushBefore) % 2 === 1;
8046
8036
  if (index !== s.pos && isStrongPrefix) toPushBefore = s.pending + src.slice(s.pos, index);
@@ -8446,6 +8436,10 @@ function parseHtmlInlineCodeToken(token, tokens, i) {
8446
8436
  const m = html.match(/>([\s\S]*?)<\s*\/\s*[\w-]+>/);
8447
8437
  return m ? m[1] : "";
8448
8438
  }
8439
+ if (tag === "br") return [{
8440
+ type: "hardbreak",
8441
+ raw: code$1
8442
+ }, i + 1];
8449
8443
  if (tag === "a") {
8450
8444
  let loading = false;
8451
8445
  if (!nextToken || nextToken?.type === "text" && (!nnextToken || nnextToken.type !== "html_inline") || !nextToken) loading = true;
@@ -8599,11 +8593,13 @@ function parseLinkToken(tokens, startIndex, options) {
8599
8593
  //#endregion
8600
8594
  //#region src/parser/inline-parsers/math-inline-parser.ts
8601
8595
  function parseMathInlineToken(token) {
8596
+ const content = token.content ?? "";
8597
+ const raw = token.raw === "$$" ? `$${content}$` : token.raw || "";
8602
8598
  return {
8603
8599
  type: "math_inline",
8604
- content: String(token.content ?? ""),
8600
+ content,
8605
8601
  loading: !!token.loading,
8606
- raw: token.raw
8602
+ raw
8607
8603
  };
8608
8604
  }
8609
8605
 
@@ -9561,31 +9557,6 @@ function normalizeSingleLinkResult(raw, nodes) {
9561
9557
  return nodes;
9562
9558
  }
9563
9559
 
9564
- //#endregion
9565
- //#region src/parser/node-parsers/blockquote-parser.ts
9566
- function parseBlockquote(tokens, index, options) {
9567
- const blockquoteChildren = [];
9568
- let j = index + 1;
9569
- while (j < tokens.length && tokens[j].type !== "blockquote_close") if (tokens[j].type === "paragraph_open") {
9570
- const contentToken = tokens[j + 1];
9571
- blockquoteChildren.push({
9572
- type: "paragraph",
9573
- children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, { requireClosingStrong: options?.requireClosingStrong }),
9574
- raw: String(contentToken.content ?? "")
9575
- });
9576
- j += 3;
9577
- } else if (tokens[j].type === "bullet_list_open" || tokens[j].type === "ordered_list_open") {
9578
- const [listNode, newIndex] = parseList(tokens, j);
9579
- blockquoteChildren.push(listNode);
9580
- j = newIndex;
9581
- } else j++;
9582
- return [{
9583
- type: "blockquote",
9584
- children: blockquoteChildren,
9585
- raw: blockquoteChildren.map((child) => child.raw).join("\n")
9586
- }, j + 1];
9587
- }
9588
-
9589
9560
  //#endregion
9590
9561
  //#region src/parser/node-parsers/code-block-parser.ts
9591
9562
  function parseCodeBlock(token) {
@@ -9687,14 +9658,70 @@ function parseHeading(tokens, index, options) {
9687
9658
  };
9688
9659
  }
9689
9660
 
9661
+ //#endregion
9662
+ //#region src/parser/node-parsers/html-block-parser.ts
9663
+ const VOID_TAGS = new Set([
9664
+ "area",
9665
+ "base",
9666
+ "br",
9667
+ "col",
9668
+ "embed",
9669
+ "hr",
9670
+ "img",
9671
+ "input",
9672
+ "link",
9673
+ "meta",
9674
+ "param",
9675
+ "source",
9676
+ "track",
9677
+ "wbr"
9678
+ ]);
9679
+ const CLOSE_TAG_RE_CACHE = /* @__PURE__ */ new Map();
9680
+ function parseHtmlBlock(token) {
9681
+ const raw = String(token.content ?? "");
9682
+ if (/^\s*<!--/.test(raw) || /^\s*<!/.test(raw) || /^\s*<\?/.test(raw)) return {
9683
+ type: "html_block",
9684
+ content: raw,
9685
+ raw,
9686
+ tag: "",
9687
+ loading: false
9688
+ };
9689
+ const tag = (raw.match(/^\s*<([A-Z][\w:-]*)/i)?.[1] || "").toLowerCase();
9690
+ if (!tag) return {
9691
+ type: "html_block",
9692
+ content: raw,
9693
+ raw,
9694
+ tag: "",
9695
+ loading: false
9696
+ };
9697
+ const selfClosing = /^\s*<[^>]*\/\s*>/.test(raw);
9698
+ const isVoid = VOID_TAGS.has(tag);
9699
+ let closeRe = CLOSE_TAG_RE_CACHE.get(tag);
9700
+ if (!closeRe) {
9701
+ closeRe = new RegExp(`<\\/\\s*${tag}\\b`, "i");
9702
+ CLOSE_TAG_RE_CACHE.set(tag, closeRe);
9703
+ }
9704
+ const hasClosing = closeRe.test(raw);
9705
+ const loading = !(isVoid || selfClosing || hasClosing);
9706
+ return {
9707
+ type: "html_block",
9708
+ content: loading ? `${raw.replace(/<[^>]*$/, "")}\n</${tag}>` : raw,
9709
+ raw,
9710
+ tag,
9711
+ loading
9712
+ };
9713
+ }
9714
+
9690
9715
  //#endregion
9691
9716
  //#region src/parser/node-parsers/math-block-parser.ts
9692
9717
  function parseMathBlock(token) {
9718
+ const content = String(token.content ?? "");
9719
+ const raw = token.raw === "$$" ? `$$${content}$$` : String(token.raw ?? "");
9693
9720
  return {
9694
9721
  type: "math_block",
9695
- content: String(token.content ?? ""),
9722
+ content,
9696
9723
  loading: !!token.loading,
9697
- raw: String(token.raw ?? "")
9724
+ raw
9698
9725
  };
9699
9726
  }
9700
9727
 
@@ -9775,6 +9802,57 @@ function parseThematicBreak() {
9775
9802
  };
9776
9803
  }
9777
9804
 
9805
+ //#endregion
9806
+ //#region src/parser/node-parsers/block-token-parser.ts
9807
+ function parseBasicBlockToken(tokens, index, options) {
9808
+ const token = tokens[index];
9809
+ switch (token.type) {
9810
+ case "heading_open": return [parseHeading(tokens, index, options), index + 3];
9811
+ case "code_block": return [parseCodeBlock(token), index + 1];
9812
+ case "fence": return [parseFenceToken(token), index + 1];
9813
+ case "math_block": return [parseMathBlock(token), index + 1];
9814
+ case "html_block": return [parseHtmlBlock(token), index + 1];
9815
+ case "table_open": {
9816
+ const [tableNode, newIndex] = parseTable(tokens, index, options);
9817
+ return [tableNode, newIndex];
9818
+ }
9819
+ case "dl_open": {
9820
+ const [definitionListNode, newIndex] = parseDefinitionList(tokens, index, options);
9821
+ return [definitionListNode, newIndex];
9822
+ }
9823
+ case "footnote_open": {
9824
+ const [footnoteNode, newIndex] = parseFootnote(tokens, index, options);
9825
+ return [footnoteNode, newIndex];
9826
+ }
9827
+ case "hr": return [parseThematicBreak(), index + 1];
9828
+ default: break;
9829
+ }
9830
+ return null;
9831
+ }
9832
+ function parseCommonBlockToken(tokens, index, options, handlers) {
9833
+ const basicResult = parseBasicBlockToken(tokens, index, options);
9834
+ if (basicResult) return basicResult;
9835
+ switch (tokens[index].type) {
9836
+ case "container_warning_open":
9837
+ case "container_info_open":
9838
+ case "container_note_open":
9839
+ case "container_tip_open":
9840
+ case "container_danger_open":
9841
+ case "container_caution_open":
9842
+ case "container_error_open":
9843
+ if (handlers?.parseContainer) return handlers.parseContainer(tokens, index, options);
9844
+ break;
9845
+ case "container_open":
9846
+ if (handlers?.matchAdmonition) {
9847
+ const result = handlers.matchAdmonition(tokens, index, options);
9848
+ if (result) return result;
9849
+ }
9850
+ break;
9851
+ default: break;
9852
+ }
9853
+ return null;
9854
+ }
9855
+
9778
9856
  //#endregion
9779
9857
  //#region src/parser/node-parsers/list-parser.ts
9780
9858
  function parseList(tokens, index, options) {
@@ -9799,49 +9877,20 @@ function parseList(tokens, index, options) {
9799
9877
  });
9800
9878
  k += 3;
9801
9879
  } else if (tokens[k].type === "blockquote_open") {
9802
- const [blockquoteNode, newIndex] = parseBlockquote(tokens, k);
9880
+ const [blockquoteNode, newIndex] = parseBlockquote(tokens, k, options);
9803
9881
  itemChildren.push(blockquoteNode);
9804
9882
  k = newIndex;
9805
9883
  } else if (tokens[k].type === "bullet_list_open" || tokens[k].type === "ordered_list_open") {
9806
- const [nestedListNode, newIndex] = parseNestedList(tokens, k, options);
9884
+ const [nestedListNode, newIndex] = parseList(tokens, k, options);
9807
9885
  itemChildren.push(nestedListNode);
9808
9886
  k = newIndex;
9809
- } else if (tokens[k].type === "code_block") {
9810
- itemChildren.push(parseCodeBlock(tokens[k]));
9811
- k += 1;
9812
- } else if (tokens[k].type === "fence") {
9813
- itemChildren.push(parseFenceToken(tokens[k]));
9814
- k += 1;
9815
- } else if (tokens[k].type === "math_block") {
9816
- itemChildren.push(parseMathBlock(tokens[k]));
9817
- k += 1;
9818
- } else if (tokens[k].type === "table_open") {
9819
- const [tableNode, newIndex] = parseTable(tokens, k);
9820
- itemChildren.push(tableNode);
9821
- k = newIndex;
9822
- } else if (tokens[k].type === "dl_open") {
9823
- const [defListNode, newIndex] = parseDefinitionList(tokens, k);
9824
- itemChildren.push(defListNode);
9825
- k = newIndex;
9826
- } else if (tokens[k].type === "footnote_open") {
9827
- const [footnoteNode, newIndex] = parseFootnote(tokens, k);
9828
- itemChildren.push(footnoteNode);
9829
- k = newIndex;
9830
- } else if (tokens[k].type === "heading_open") {
9831
- const headingNode = parseHeading(tokens, k);
9832
- itemChildren.push(headingNode);
9833
- k += 3;
9834
- } else if (tokens[k].type === "hr") {
9835
- itemChildren.push(parseThematicBreak());
9836
- k += 1;
9837
- } else if (tokens[k].type === "container_open") {
9838
- const match = /^::: ?(warning|info|note|tip|danger|caution) ?(.*)$/.exec(String(tokens[k].info ?? ""));
9839
- if (match) {
9840
- const [admonitionNode, newIndex] = parseAdmonition(tokens, k, match);
9841
- itemChildren.push(admonitionNode);
9842
- k = newIndex;
9887
+ } else {
9888
+ const handled = parseCommonBlockToken(tokens, k, options, containerTokenHandlers);
9889
+ if (handled) {
9890
+ itemChildren.push(handled[0]);
9891
+ k = handled[1];
9843
9892
  } else k += 1;
9844
- } else k += 1;
9893
+ }
9845
9894
  listItems.push({
9846
9895
  type: "list_item",
9847
9896
  children: itemChildren,
@@ -9865,59 +9914,6 @@ function parseList(tokens, index, options) {
9865
9914
  raw: listItems.map((item) => item.raw).join("\n")
9866
9915
  }, j + 1];
9867
9916
  }
9868
- function parseNestedList(tokens, index, options) {
9869
- const nestedToken = tokens[index];
9870
- const nestedItems = [];
9871
- let j = index + 1;
9872
- while (j < tokens.length && tokens[j].type !== "bullet_list_close" && tokens[j].type !== "ordered_list_close") if (tokens[j].type === "list_item_open") {
9873
- const itemChildren = [];
9874
- let k = j + 1;
9875
- while (k < tokens.length && tokens[k].type !== "list_item_close") if (tokens[k].type === "paragraph_open") {
9876
- const contentToken = tokens[k + 1];
9877
- const preToken = tokens[k - 1];
9878
- itemChildren.push({
9879
- type: "paragraph",
9880
- children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), preToken, { requireClosingStrong: options?.requireClosingStrong }),
9881
- raw: String(contentToken.content ?? "")
9882
- });
9883
- k += 3;
9884
- } else if (tokens[k].type === "bullet_list_open" || tokens[k].type === "ordered_list_open") {
9885
- const [deeperNestedListNode, newIndex] = parseNestedList(tokens, k, options);
9886
- itemChildren.push(deeperNestedListNode);
9887
- k = newIndex;
9888
- } else if (tokens[k].type === "code_block") {
9889
- itemChildren.push(parseCodeBlock(tokens[k]));
9890
- k += 1;
9891
- } else if (tokens[k].type === "fence") {
9892
- itemChildren.push(parseFenceToken(tokens[k]));
9893
- k += 1;
9894
- } else if (tokens[k].type === "math_block") {
9895
- itemChildren.push(parseMathBlock(tokens[k]));
9896
- k += 1;
9897
- } else k += 1;
9898
- nestedItems.push({
9899
- type: "list_item",
9900
- children: itemChildren,
9901
- raw: itemChildren.map((child) => child.raw).join("")
9902
- });
9903
- j = k + 1;
9904
- } else j += 1;
9905
- return [{
9906
- type: "list",
9907
- ordered: nestedToken.type === "ordered_list_open",
9908
- start: (() => {
9909
- if (nestedToken.attrs && nestedToken.attrs.length) {
9910
- const found = nestedToken.attrs.find((a) => a[0] === "start");
9911
- if (found) {
9912
- const parsed = Number(found[1]);
9913
- return Number.isFinite(parsed) && parsed !== 0 ? parsed : 1;
9914
- }
9915
- }
9916
- })(),
9917
- items: nestedItems,
9918
- raw: nestedItems.map((item) => item.raw).join("\n")
9919
- }, j + 1];
9920
- }
9921
9917
 
9922
9918
  //#endregion
9923
9919
  //#region src/parser/node-parsers/admonition-parser.ts
@@ -9938,7 +9934,17 @@ function parseAdmonition(tokens, index, match, options) {
9938
9934
  const [listNode, newIndex] = parseList(tokens, j, options);
9939
9935
  admonitionChildren.push(listNode);
9940
9936
  j = newIndex;
9941
- } else j++;
9937
+ } else if (tokens[j].type === "blockquote_open") {
9938
+ const [blockquoteNode, newIndex] = parseBlockquote(tokens, j, options);
9939
+ admonitionChildren.push(blockquoteNode);
9940
+ j = newIndex;
9941
+ } else {
9942
+ const handled = parseBasicBlockToken(tokens, j, options);
9943
+ if (handled) {
9944
+ admonitionChildren.push(handled[0]);
9945
+ j = handled[1];
9946
+ } else j++;
9947
+ }
9942
9948
  return [{
9943
9949
  type: "admonition",
9944
9950
  kind,
@@ -9998,7 +10004,17 @@ function parseContainer(tokens, index, options) {
9998
10004
  const [listNode, newIndex] = parseList(tokens, j, options);
9999
10005
  children.push(listNode);
10000
10006
  j = newIndex;
10001
- } else j++;
10007
+ } else if (tokens[j].type === "blockquote_open") {
10008
+ const [blockquoteNode, newIndex] = parseBlockquote(tokens, j, options);
10009
+ children.push(blockquoteNode);
10010
+ j = newIndex;
10011
+ } else {
10012
+ const handled = parseBasicBlockToken(tokens, j, options);
10013
+ if (handled) {
10014
+ children.push(handled[0]);
10015
+ j = handled[1];
10016
+ } else j++;
10017
+ }
10002
10018
  return [{
10003
10019
  type: "admonition",
10004
10020
  kind,
@@ -10008,6 +10024,66 @@ function parseContainer(tokens, index, options) {
10008
10024
  }, j + 1];
10009
10025
  }
10010
10026
 
10027
+ //#endregion
10028
+ //#region src/parser/node-parsers/container-token-handlers.ts
10029
+ const CONTAINER_REGEX = /^::: ?(warning|info|note|tip|danger|caution|error) ?(.*)$/;
10030
+ function handleContainerOpen(tokens, index, options) {
10031
+ const token = tokens[index];
10032
+ if (token.type !== "container_open") return null;
10033
+ const match = CONTAINER_REGEX.exec(String(token.info ?? ""));
10034
+ if (!match) return null;
10035
+ return parseAdmonition(tokens, index, match, options);
10036
+ }
10037
+ const containerTokenHandlers = {
10038
+ parseContainer: (tokens, index, options) => parseContainer(tokens, index, options),
10039
+ matchAdmonition: handleContainerOpen
10040
+ };
10041
+
10042
+ //#endregion
10043
+ //#region src/parser/node-parsers/blockquote-parser.ts
10044
+ function parseBlockquote(tokens, index, options) {
10045
+ const blockquoteChildren = [];
10046
+ let j = index + 1;
10047
+ while (j < tokens.length && tokens[j].type !== "blockquote_close") switch (tokens[j].type) {
10048
+ case "paragraph_open": {
10049
+ const contentToken = tokens[j + 1];
10050
+ blockquoteChildren.push({
10051
+ type: "paragraph",
10052
+ children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, { requireClosingStrong: options?.requireClosingStrong }),
10053
+ raw: String(contentToken.content ?? "")
10054
+ });
10055
+ j += 3;
10056
+ break;
10057
+ }
10058
+ case "bullet_list_open":
10059
+ case "ordered_list_open": {
10060
+ const [listNode, newIndex] = parseList(tokens, j, options);
10061
+ blockquoteChildren.push(listNode);
10062
+ j = newIndex;
10063
+ break;
10064
+ }
10065
+ case "blockquote_open": {
10066
+ const [nestedBlockquote, newIndex] = parseBlockquote(tokens, j, options);
10067
+ blockquoteChildren.push(nestedBlockquote);
10068
+ j = newIndex;
10069
+ break;
10070
+ }
10071
+ default: {
10072
+ const handled = parseCommonBlockToken(tokens, j, options, containerTokenHandlers);
10073
+ if (handled) {
10074
+ blockquoteChildren.push(handled[0]);
10075
+ j = handled[1];
10076
+ } else j++;
10077
+ break;
10078
+ }
10079
+ }
10080
+ return [{
10081
+ type: "blockquote",
10082
+ children: blockquoteChildren,
10083
+ raw: blockquoteChildren.map((child) => child.raw).join("\n")
10084
+ }, j + 1];
10085
+ }
10086
+
10011
10087
  //#endregion
10012
10088
  //#region src/parser/node-parsers/hardbreak-parser.ts
10013
10089
  function parseHardBreak() {
@@ -10017,60 +10093,6 @@ function parseHardBreak() {
10017
10093
  };
10018
10094
  }
10019
10095
 
10020
- //#endregion
10021
- //#region src/parser/node-parsers/html-block-parser.ts
10022
- const VOID_TAGS = new Set([
10023
- "area",
10024
- "base",
10025
- "br",
10026
- "col",
10027
- "embed",
10028
- "hr",
10029
- "img",
10030
- "input",
10031
- "link",
10032
- "meta",
10033
- "param",
10034
- "source",
10035
- "track",
10036
- "wbr"
10037
- ]);
10038
- const CLOSE_TAG_RE_CACHE = /* @__PURE__ */ new Map();
10039
- function parseHtmlBlock(token) {
10040
- const raw = String(token.content ?? "");
10041
- if (/^\s*<!--/.test(raw) || /^\s*<!/.test(raw) || /^\s*<\?/.test(raw)) return {
10042
- type: "html_block",
10043
- content: raw,
10044
- raw,
10045
- tag: "",
10046
- loading: false
10047
- };
10048
- const tag = (raw.match(/^\s*<([A-Z][\w:-]*)/i)?.[1] || "").toLowerCase();
10049
- if (!tag) return {
10050
- type: "html_block",
10051
- content: raw,
10052
- raw,
10053
- tag: "",
10054
- loading: false
10055
- };
10056
- const selfClosing = /^\s*<[^>]*\/\s*>/.test(raw);
10057
- const isVoid = VOID_TAGS.has(tag);
10058
- let closeRe = CLOSE_TAG_RE_CACHE.get(tag);
10059
- if (!closeRe) {
10060
- closeRe = new RegExp(`<\\/\\s*${tag}\\b`, "i");
10061
- CLOSE_TAG_RE_CACHE.set(tag, closeRe);
10062
- }
10063
- const hasClosing = closeRe.test(raw);
10064
- const loading = !(isVoid || selfClosing || hasClosing);
10065
- return {
10066
- type: "html_block",
10067
- content: loading ? `${raw.replace(/<[^>]*$/, "")}\n</${tag}>` : raw,
10068
- raw,
10069
- tag,
10070
- loading
10071
- };
10072
- }
10073
-
10074
10096
  //#endregion
10075
10097
  //#region src/parser/node-parsers/paragraph-parser.ts
10076
10098
  function parseParagraph(tokens, index, options) {
@@ -10113,40 +10135,18 @@ function processTokens(tokens, options) {
10113
10135
  const result = [];
10114
10136
  let i = 0;
10115
10137
  while (i < tokens.length) {
10138
+ const handled = parseCommonBlockToken(tokens, i, options, containerTokenHandlers);
10139
+ if (handled) {
10140
+ result.push(handled[0]);
10141
+ i = handled[1];
10142
+ continue;
10143
+ }
10116
10144
  const token = tokens[i];
10117
10145
  switch (token.type) {
10118
- case "container_warning_open":
10119
- case "container_info_open":
10120
- case "container_note_open":
10121
- case "container_tip_open":
10122
- case "container_danger_open":
10123
- case "container_caution_open":
10124
- case "container_error_open": {
10125
- const [warningNode, newIndex] = parseContainer(tokens, i, options);
10126
- result.push(warningNode);
10127
- i = newIndex;
10128
- break;
10129
- }
10130
- case "heading_open":
10131
- result.push(parseHeading(tokens, i, options));
10132
- i += 3;
10133
- break;
10134
10146
  case "paragraph_open":
10135
10147
  result.push(parseParagraph(tokens, i, options));
10136
10148
  i += 3;
10137
10149
  break;
10138
- case "html_block":
10139
- result.push(parseHtmlBlock(token));
10140
- i += 1;
10141
- break;
10142
- case "code_block":
10143
- result.push(parseCodeBlock(tokens[i]));
10144
- i += 1;
10145
- break;
10146
- case "fence":
10147
- result.push(parseFenceToken(tokens[i]));
10148
- i += 1;
10149
- break;
10150
10150
  case "bullet_list_open":
10151
10151
  case "ordered_list_open": {
10152
10152
  const [listNode, newIndex] = parseList(tokens, i, options);
@@ -10154,34 +10154,12 @@ function processTokens(tokens, options) {
10154
10154
  i = newIndex;
10155
10155
  break;
10156
10156
  }
10157
- case "hr":
10158
- result.push(parseThematicBreak());
10159
- i += 1;
10160
- break;
10161
10157
  case "blockquote_open": {
10162
10158
  const [blockquoteNode, newIndex] = parseBlockquote(tokens, i, options);
10163
10159
  result.push(blockquoteNode);
10164
10160
  i = newIndex;
10165
10161
  break;
10166
10162
  }
10167
- case "table_open": {
10168
- const [tableNode, newIndex] = parseTable(tokens, i, options);
10169
- result.push(tableNode);
10170
- i = newIndex;
10171
- break;
10172
- }
10173
- case "dl_open": {
10174
- const [definitionListNode, newIndex] = parseDefinitionList(tokens, i, options);
10175
- result.push(definitionListNode);
10176
- i = newIndex;
10177
- break;
10178
- }
10179
- case "footnote_open": {
10180
- const [footnoteNode, newIndex] = parseFootnote(tokens, i, options);
10181
- result.push(footnoteNode);
10182
- i = newIndex;
10183
- break;
10184
- }
10185
10163
  case "footnote_anchor": {
10186
10164
  const meta = token.meta ?? {};
10187
10165
  const id = String(meta.label ?? token.content ?? "");
@@ -10193,23 +10171,10 @@ function processTokens(tokens, options) {
10193
10171
  i++;
10194
10172
  break;
10195
10173
  }
10196
- case "container_open": {
10197
- const match = /^::: ?(warning|info|note|tip|danger|caution|error) ?(.*)$/.exec(String(token.info ?? ""));
10198
- if (match) {
10199
- const [admonitionNode, newIndex] = parseAdmonition(tokens, i, match, options);
10200
- result.push(admonitionNode);
10201
- i = newIndex;
10202
- } else i += 1;
10203
- break;
10204
- }
10205
10174
  case "hardbreak":
10206
10175
  result.push(parseHardBreak());
10207
10176
  i++;
10208
10177
  break;
10209
- case "math_block":
10210
- result.push(parseMathBlock(tokens[i]));
10211
- i += 1;
10212
- break;
10213
10178
  case "inline":
10214
10179
  result.push(...parseInlineTokens(token.children || [], String(token.content ?? ""), void 0, { requireClosingStrong: options?.requireClosingStrong }));
10215
10180
  i += 1;