@headwall/markdown-to-blocks 1.3.0 → 1.5.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.
@@ -7560,6 +7560,52 @@ var require_dist = __commonJS({
7560
7560
  }
7561
7561
  });
7562
7562
 
7563
+ // src/types.ts
7564
+ var CODE_LANGUAGE_MODES = ["drop", "class"];
7565
+ var UNSUPPORTED_MODES = ["html", "skip"];
7566
+ var URL_SCHEME_MODES = ["safe", "any"];
7567
+ function applyOptionDefaults(options) {
7568
+ return {
7569
+ headingShift: options?.headingShift ?? 0,
7570
+ minHeadingLevel: options?.minHeadingLevel ?? 2,
7571
+ headingAnchors: options?.headingAnchors ?? false,
7572
+ resolveImage: options?.resolveImage,
7573
+ codeLanguage: options?.codeLanguage ?? "drop",
7574
+ unsupported: options?.unsupported ?? "html",
7575
+ urlSchemes: options?.urlSchemes ?? "safe",
7576
+ gfm: options?.gfm ?? true
7577
+ };
7578
+ }
7579
+ function resolveOptions(options) {
7580
+ const resolved = applyOptionDefaults(options);
7581
+ const problems = validateOptions(resolved);
7582
+ if (problems.length > 0) {
7583
+ throw new RangeError(`invalid options:
7584
+ ${problems.join("\n ")}`);
7585
+ }
7586
+ return resolved;
7587
+ }
7588
+ function validateOptions(options) {
7589
+ const problems = [];
7590
+ if (!Number.isInteger(options.headingShift)) {
7591
+ problems.push(`headingShift must be an integer (got ${String(options.headingShift)})`);
7592
+ }
7593
+ const minLevel = options.minHeadingLevel;
7594
+ if (!Number.isInteger(minLevel) || minLevel < 1 || minLevel > 6) {
7595
+ problems.push(`minHeadingLevel must be an integer from 1 to 6 (got ${String(minLevel)})`);
7596
+ }
7597
+ if (!CODE_LANGUAGE_MODES.includes(options.codeLanguage)) {
7598
+ problems.push(`codeLanguage must be 'drop' or 'class' (got ${JSON.stringify(options.codeLanguage)})`);
7599
+ }
7600
+ if (!UNSUPPORTED_MODES.includes(options.unsupported)) {
7601
+ problems.push(`unsupported must be 'html' or 'skip' (got ${JSON.stringify(options.unsupported)})`);
7602
+ }
7603
+ if (!URL_SCHEME_MODES.includes(options.urlSchemes)) {
7604
+ problems.push(`urlSchemes must be 'safe' or 'any' (got ${JSON.stringify(options.urlSchemes)})`);
7605
+ }
7606
+ return problems;
7607
+ }
7608
+
7563
7609
  // node_modules/devlop/lib/default.js
7564
7610
  function ok() {
7565
7611
  }
@@ -8062,16 +8108,50 @@ var empty = [];
8062
8108
  var CONTINUE = true;
8063
8109
  var EXIT = false;
8064
8110
  var SKIP = "skip";
8065
- function visitParents(tree, test, visitor, reverse) {
8111
+ function visitParents(tree, testOrEnterOrVisitors, enterOrVisitorsOrReverse, reverse) {
8112
+ if (!tree || typeof tree !== "object") {
8113
+ throw new Error("Unexpected value `" + tree + "` for `tree`, expected node");
8114
+ }
8115
+ let preorder = true;
8066
8116
  let check;
8067
- if (typeof test === "function" && typeof visitor !== "function") {
8068
- reverse = visitor;
8069
- visitor = test;
8117
+ let visitors;
8118
+ let enter;
8119
+ let exit3;
8120
+ if (typeof enterOrVisitorsOrReverse === "function" || enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === "object") {
8121
+ check = /** @type {Test} */
8122
+ testOrEnterOrVisitors;
8123
+ visitors = enterOrVisitorsOrReverse;
8124
+ if (reverse) preorder = false;
8070
8125
  } else {
8071
- check = test;
8126
+ visitors = /** @type {Visitors | Visitor} */
8127
+ testOrEnterOrVisitors;
8128
+ if (enterOrVisitorsOrReverse) preorder = false;
8129
+ }
8130
+ if (typeof visitors === "function") {
8131
+ enter = visitors;
8132
+ } else if (visitors && typeof visitors === "object") {
8133
+ if (visitors.enter === null || visitors.enter === void 0) {
8134
+ } else if (typeof visitors.enter === "function") {
8135
+ enter = visitors.enter;
8136
+ } else {
8137
+ throw new Error(
8138
+ "Unexpected value `" + visitors.enter + "` for `visitors.enter`, expected optional visitor"
8139
+ );
8140
+ }
8141
+ if (typeof visitors.exit === "function") {
8142
+ exit3 = visitors.exit;
8143
+ } else {
8144
+ throw new Error(
8145
+ "Unexpected value `" + visitors.exit + "` for `visitors.exit`, expected visitor (pass a visitor directly if you only want an enter visitor)"
8146
+ );
8147
+ }
8148
+ } else {
8149
+ throw new Error(
8150
+ "Unexpected value `" + visitors + "` for `enter` or `visitors`, expected visitor or object with visitors"
8151
+ );
8072
8152
  }
8073
8153
  const is2 = convert(check);
8074
- const step = reverse ? -1 : 1;
8154
+ const step = preorder ? 1 : -1;
8075
8155
  factory(tree, void 0, [])();
8076
8156
  function factory(node2, index2, parents) {
8077
8157
  const value2 = (
@@ -8092,12 +8172,10 @@ function visitParents(tree, test, visitor, reverse) {
8092
8172
  }
8093
8173
  return visit2;
8094
8174
  function visit2() {
8175
+ const matches = !check || is2(node2, index2, parents[parents.length - 1] || void 0);
8095
8176
  let result = empty;
8096
- let subresult;
8097
- let offset;
8098
- let grandparents;
8099
- if (!test || is2(node2, index2, parents[parents.length - 1] || void 0)) {
8100
- result = toResult(visitor(node2, parents));
8177
+ if (enter && matches) {
8178
+ result = toResult(enter(node2, parents, index2));
8101
8179
  if (result[0] === EXIT) {
8102
8180
  return result;
8103
8181
  }
@@ -8108,11 +8186,11 @@ function visitParents(tree, test, visitor, reverse) {
8108
8186
  node2
8109
8187
  );
8110
8188
  if (nodeAsParent.children && result[0] !== SKIP) {
8111
- offset = (reverse ? nodeAsParent.children.length : -1) + step;
8112
- grandparents = parents.concat(nodeAsParent);
8189
+ let offset = (preorder ? -1 : nodeAsParent.children.length) + step;
8190
+ const grandparents = [...parents, nodeAsParent];
8113
8191
  while (offset > -1 && offset < nodeAsParent.children.length) {
8114
8192
  const child = nodeAsParent.children[offset];
8115
- subresult = factory(child, offset, grandparents)();
8193
+ const subresult = factory(child, offset, grandparents)();
8116
8194
  if (subresult[0] === EXIT) {
8117
8195
  return subresult;
8118
8196
  }
@@ -8120,6 +8198,17 @@ function visitParents(tree, test, visitor, reverse) {
8120
8198
  }
8121
8199
  }
8122
8200
  }
8201
+ if (exit3 && matches) {
8202
+ const exitResult = toResult(exit3(node2, parents, index2));
8203
+ if (exitResult[0] === SKIP) {
8204
+ throw new Error(
8205
+ "Unexpected value `" + exitResult[0] + "` from `exit`, expected `CONTINUE`, `EXIT`, index, or nothing"
8206
+ );
8207
+ }
8208
+ if (exitResult[0] === EXIT || typeof exitResult[1] === "number") {
8209
+ return exitResult;
8210
+ }
8211
+ }
8123
8212
  return result;
8124
8213
  }
8125
8214
  }
@@ -8989,24 +9078,37 @@ function encodeCharacterReference(code3) {
8989
9078
  }
8990
9079
 
8991
9080
  // node_modules/unist-util-visit/lib/index.js
8992
- function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
9081
+ function visit(tree, testOrEnterOrVisitors, enterOrVisitorsOrReverse, maybeReverse) {
9082
+ let check;
9083
+ let visitors;
8993
9084
  let reverse;
8994
- let test;
8995
- let visitor;
8996
- if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
8997
- test = void 0;
8998
- visitor = testOrVisitor;
8999
- reverse = visitorOrReverse;
9000
- } else {
9001
- test = testOrVisitor;
9002
- visitor = visitorOrReverse;
9085
+ if (typeof enterOrVisitorsOrReverse === "function" || enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === "object") {
9086
+ check = /** @type {Test} */
9087
+ testOrEnterOrVisitors;
9088
+ visitors = enterOrVisitorsOrReverse;
9003
9089
  reverse = maybeReverse;
9090
+ } else {
9091
+ visitors = /** @type {Visitor | Visitors} */
9092
+ testOrEnterOrVisitors;
9093
+ reverse = enterOrVisitorsOrReverse;
9004
9094
  }
9005
- visitParents(tree, test, overload, reverse);
9006
- function overload(node2, parents) {
9007
- const parent = parents[parents.length - 1];
9008
- const index2 = parent ? parent.children.indexOf(node2) : void 0;
9009
- return visitor(node2, index2, parent);
9095
+ if (typeof visitors === "function") {
9096
+ visitParents(tree, check, wrap(visitors), reverse);
9097
+ } else {
9098
+ visitParents(tree, check, wrapVisitors(visitors), reverse);
9099
+ }
9100
+ }
9101
+ function wrapVisitors(visitors) {
9102
+ if (!visitors || typeof visitors !== "object") return visitors;
9103
+ return {
9104
+ enter: typeof visitors.enter === "function" ? wrap(visitors.enter) : visitors.enter,
9105
+ exit: typeof visitors.exit === "function" ? wrap(visitors.exit) : visitors.exit
9106
+ };
9107
+ }
9108
+ function wrap(visitor) {
9109
+ return overload;
9110
+ function overload(node2, parents, index2) {
9111
+ return visitor(node2, index2, parents[parents.length - 1]);
9010
9112
  }
9011
9113
  }
9012
9114
 
@@ -18284,7 +18386,7 @@ function trough() {
18284
18386
  }
18285
18387
  values = output;
18286
18388
  if (fn) {
18287
- wrap(fn, next)(...output);
18389
+ wrap2(fn, next)(...output);
18288
18390
  } else {
18289
18391
  callback(null, ...output);
18290
18392
  }
@@ -18300,7 +18402,7 @@ function trough() {
18300
18402
  return pipeline;
18301
18403
  }
18302
18404
  }
18303
- function wrap(middleware, callback) {
18405
+ function wrap2(middleware, callback) {
18304
18406
  let called;
18305
18407
  return wrapped;
18306
18408
  function wrapped(...parameters) {
@@ -19630,6 +19732,44 @@ function escapeAttribute(value2) {
19630
19732
  return escaped;
19631
19733
  }
19632
19734
 
19735
+ // src/url.ts
19736
+ var LINK_SCHEMES = ["http", "https", "mailto", "tel"];
19737
+ var IMAGE_SCHEMES = ["http", "https"];
19738
+ function urlScheme(url) {
19739
+ const normalised = url.replace(/[\t\n\r]/g, "").replace(/^[\u0000- ]+|[\u0000- ]+$/g, "");
19740
+ const match = /^([a-z][a-z0-9+.-]*):/i.exec(normalised);
19741
+ return match?.[1] != null ? match[1].toLowerCase() : null;
19742
+ }
19743
+ function hasAllowedScheme(url, schemes) {
19744
+ const scheme = urlScheme(url);
19745
+ return scheme == null || schemes.includes(scheme);
19746
+ }
19747
+ function isSafeLinkUrl(url) {
19748
+ return hasAllowedScheme(url, LINK_SCHEMES);
19749
+ }
19750
+ function isSafeImageUrl(url) {
19751
+ return hasAllowedScheme(url, IMAGE_SCHEMES);
19752
+ }
19753
+
19754
+ // src/resolve-image.ts
19755
+ function resolveMarkdownImage(node2, options) {
19756
+ const alt = node2.alt ?? "";
19757
+ const resolved = options.resolveImage?.(node2.url, alt, node2.title ?? void 0);
19758
+ const id = resolved?.id;
19759
+ if (id != null && !(Number.isSafeInteger(id) && id > 0)) {
19760
+ throw new RangeError(
19761
+ `resolveImage returned an invalid id for ${JSON.stringify(node2.url)}: expected a positive integer, got ${JSON.stringify(id)}`
19762
+ );
19763
+ }
19764
+ const image2 = {
19765
+ ...resolved,
19766
+ url: resolved?.url ?? node2.url,
19767
+ alt: resolved?.alt ?? alt
19768
+ };
19769
+ const allowed = options.urlSchemes === "any" || isSafeImageUrl(image2.url);
19770
+ return allowed ? image2 : null;
19771
+ }
19772
+
19633
19773
  // src/inline.ts
19634
19774
  function renderInline(nodes, options) {
19635
19775
  const parts = [];
@@ -19666,7 +19806,7 @@ function renderInlineNode(node2, options) {
19666
19806
  out = renderInlineImage(node2, options);
19667
19807
  break;
19668
19808
  case "html":
19669
- out = node2.value;
19809
+ out = options.unsupported === "skip" ? "" : node2.value;
19670
19810
  break;
19671
19811
  default:
19672
19812
  out = renderUnknownInline(node2, options);
@@ -19675,19 +19815,24 @@ function renderInlineNode(node2, options) {
19675
19815
  return out;
19676
19816
  }
19677
19817
  function renderLink(node2, options) {
19678
- const href = escapeAttribute(node2.url);
19679
- const title = node2.title != null && node2.title !== "" ? ` title="${escapeAttribute(node2.title)}"` : "";
19680
19818
  const inner = renderInline(node2.children, options);
19681
- return `<a href="${href}"${title}>${inner}</a>`;
19819
+ let out = inner;
19820
+ if (options.urlSchemes === "any" || isSafeLinkUrl(node2.url)) {
19821
+ const href = escapeAttribute(node2.url);
19822
+ const title = node2.title != null && node2.title !== "" ? ` title="${escapeAttribute(node2.title)}"` : "";
19823
+ out = `<a href="${href}"${title}>${inner}</a>`;
19824
+ }
19825
+ return out;
19682
19826
  }
19683
19827
  function renderInlineImage(node2, options) {
19684
- const alt = node2.alt ?? "";
19685
- const resolved = options.resolveImage?.(node2.url, alt, node2.title ?? void 0);
19686
- const url = resolved?.url ?? node2.url;
19687
- const altText = resolved?.alt ?? alt;
19688
- const altAttr = ` alt="${escapeAttribute(altText)}"`;
19689
- const idClass = resolved?.id != null ? ` class="wp-image-${resolved.id}"` : "";
19690
- return `<img src="${escapeAttribute(url)}"${altAttr}${idClass}/>`;
19828
+ const image2 = resolveMarkdownImage(node2, options);
19829
+ let out = "";
19830
+ if (image2 != null) {
19831
+ const altAttr = ` alt="${escapeAttribute(image2.alt ?? "")}"`;
19832
+ const idClass = image2.id != null ? ` class="wp-image-${image2.id}"` : "";
19833
+ out = `<img src="${escapeAttribute(image2.url)}"${altAttr}${idClass}/>`;
19834
+ }
19835
+ return out;
19691
19836
  }
19692
19837
  function renderUnknownInline(node2, options) {
19693
19838
  let out = "";
@@ -19725,31 +19870,22 @@ function createHeadingSlugger() {
19725
19870
  };
19726
19871
  }
19727
19872
 
19728
- // src/types.ts
19729
- function resolveOptions(options) {
19730
- return {
19731
- headingShift: options?.headingShift ?? 0,
19732
- minHeadingLevel: options?.minHeadingLevel ?? 2,
19733
- headingAnchors: options?.headingAnchors ?? false,
19734
- resolveImage: options?.resolveImage,
19735
- codeLanguage: options?.codeLanguage ?? "drop",
19736
- unsupported: options?.unsupported ?? "html",
19737
- gfm: options?.gfm ?? true
19738
- };
19739
- }
19740
-
19741
19873
  // src/blocks/code.ts
19742
19874
  function renderCode(node2, ctx) {
19743
- const body = escapeCode(node2.value);
19875
+ const body = escapeShortcodesAndEmbeds(escapeCode(node2.value));
19744
19876
  let codeOpen = "<code>";
19745
19877
  if (ctx.options.codeLanguage === "class" && node2.lang) {
19746
- codeOpen = `<code class="language-${node2.lang}">`;
19878
+ codeOpen = `<code class="language-${escapeAttribute(node2.lang)}">`;
19747
19879
  }
19748
19880
  const inner = `<pre class="wp-block-code">${codeOpen}${body}</code></pre>`;
19749
19881
  return `<!-- wp:code -->
19750
19882
  ${inner}
19751
19883
  <!-- /wp:code -->`;
19752
19884
  }
19885
+ function escapeShortcodesAndEmbeds(html2) {
19886
+ const escaped = html2.replace(/\[/g, "&#91;").replace(/^(\s*https?:)\/\/([^\s<>"]+\s*)$/m, "$1&#47;&#47;$2");
19887
+ return escaped;
19888
+ }
19753
19889
 
19754
19890
  // src/blocks/html.ts
19755
19891
  function renderHtml(node2, ctx) {
@@ -19761,43 +19897,80 @@ ${node2.value}
19761
19897
  <!-- /wp:html -->`;
19762
19898
  }
19763
19899
 
19900
+ // src/attributes.ts
19901
+ function serializeBlockAttributes(attributes) {
19902
+ let out = "";
19903
+ if (Object.keys(attributes).length > 0) {
19904
+ const json = JSON.stringify(attributes).replace(/--/g, "\\u002d\\u002d").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/ /g, "\\u00a0");
19905
+ out = ` ${json}`;
19906
+ }
19907
+ return out;
19908
+ }
19909
+
19764
19910
  // src/blocks/image.ts
19765
- function renderImage(node2, ctx) {
19766
- const alt = node2.alt ?? "";
19767
- const resolved = ctx.options.resolveImage?.(
19768
- node2.url,
19769
- alt,
19770
- node2.title ?? void 0
19771
- );
19772
- return resolved != null && resolved.id != null ? renderLibraryImage(resolved, alt) : renderExternalImage(resolved, node2.url, alt);
19911
+ function renderImage(node2, ctx, link2) {
19912
+ const image2 = resolveMarkdownImage(node2, ctx.options);
19913
+ let out = null;
19914
+ if (image2 != null) {
19915
+ const caption = image2.caption ?? node2.title ?? void 0;
19916
+ const imageLink = link2 != null ? resolveImageLink(link2, image2.url, ctx) : null;
19917
+ out = image2.id != null ? renderLibraryImage(image2, image2.id, caption, imageLink) : renderExternalImage(image2, caption, imageLink);
19918
+ }
19919
+ return out;
19773
19920
  }
19774
- function renderLibraryImage(resolved, fallbackAlt) {
19775
- const id = resolved.id;
19776
- const altText = resolved.alt ?? fallbackAlt;
19777
- const sizeSlug = resolved.sizeSlug;
19921
+ function renderLibraryImage(image2, id, caption, link2) {
19922
+ const sizeSlug = image2.sizeSlug;
19778
19923
  const attrs = { id };
19779
19924
  if (sizeSlug != null) {
19780
19925
  attrs.sizeSlug = sizeSlug;
19781
19926
  }
19782
- attrs.linkDestination = "none";
19783
- const figureClass = sizeSlug != null ? `wp-block-image size-${sizeSlug}` : "wp-block-image";
19784
- const img = `<img src="${escapeAttribute(resolved.url)}" alt="${escapeAttribute(altText)}" class="wp-image-${id}"/>`;
19785
- const caption = renderCaption(resolved.caption);
19786
- const inner = `<figure class="${figureClass}">${img}${caption}</figure>`;
19787
- return `<!-- wp:image ${JSON.stringify(attrs)} -->
19927
+ attrs.linkDestination = link2?.destination ?? "none";
19928
+ const figureClass = sizeSlug != null ? `wp-block-image size-${escapeAttribute(sizeSlug)}` : "wp-block-image";
19929
+ const img = `<img src="${escapeAttribute(image2.url)}" alt="${escapeAttribute(image2.alt ?? "")}" class="wp-image-${id}"/>`;
19930
+ const inner = `<figure class="${figureClass}">${wrapInLink(img, link2)}${renderCaption(caption)}</figure>`;
19931
+ return `<!-- wp:image${serializeBlockAttributes(attrs)} -->
19788
19932
  ${inner}
19789
19933
  <!-- /wp:image -->`;
19790
19934
  }
19791
- function renderExternalImage(resolved, fallbackUrl, fallbackAlt) {
19792
- const url = resolved?.url ?? fallbackUrl;
19793
- const altText = resolved?.alt ?? fallbackAlt;
19794
- const img = `<img src="${escapeAttribute(url)}" alt="${escapeAttribute(altText)}"/>`;
19795
- const caption = renderCaption(resolved?.caption);
19796
- const inner = `<figure class="wp-block-image">${img}${caption}</figure>`;
19797
- return `<!-- wp:image -->
19935
+ function renderExternalImage(image2, caption, link2) {
19936
+ const img = `<img src="${escapeAttribute(image2.url)}" alt="${escapeAttribute(image2.alt ?? "")}"/>`;
19937
+ const attrs = {};
19938
+ if (link2 != null) {
19939
+ attrs.linkDestination = link2.destination;
19940
+ }
19941
+ const inner = `<figure class="wp-block-image">${wrapInLink(img, link2)}${renderCaption(caption)}</figure>`;
19942
+ return `<!-- wp:image${serializeBlockAttributes(attrs)} -->
19798
19943
  ${inner}
19799
19944
  <!-- /wp:image -->`;
19800
19945
  }
19946
+ function resolveImageLink(link2, imageUrl, ctx) {
19947
+ const allowed = ctx.options.urlSchemes === "any" || isSafeLinkUrl(link2.url);
19948
+ let imageLink = null;
19949
+ if (allowed) {
19950
+ imageLink = {
19951
+ href: link2.url,
19952
+ destination: isSameMediaFile(link2.url, imageUrl) ? "media" : "custom"
19953
+ };
19954
+ }
19955
+ return imageLink;
19956
+ }
19957
+ function wrapInLink(img, link2) {
19958
+ return link2 != null ? `<a href="${escapeAttribute(link2.href)}">${img}</a>` : img;
19959
+ }
19960
+ function isSameMediaFile(href, src) {
19961
+ const hrefFile = mediaFileKey(href);
19962
+ const srcFile = mediaFileKey(src);
19963
+ const hostsMatch = hrefFile.host == null || srcFile.host == null || hrefFile.host === srcFile.host;
19964
+ return hostsMatch && hrefFile.path !== "" && hrefFile.path === srcFile.path;
19965
+ }
19966
+ function mediaFileKey(url) {
19967
+ const withoutSuffix = url.replace(/[?#].*$/, "");
19968
+ const match = /^[a-z][a-z0-9+.-]*:\/\/([^/]*)(.*)$/i.exec(withoutSuffix);
19969
+ const host = match?.[1] != null ? match[1].toLowerCase() : null;
19970
+ const path2 = match != null ? match[2] ?? "" : withoutSuffix;
19971
+ const basePath = path2.replace(/-\d+x\d+(\.[a-z0-9]+)$/i, "$1").replace(/-scaled(\.[a-z0-9]+)$/i, "$1");
19972
+ return { host, path: basePath };
19973
+ }
19801
19974
  function renderCaption(caption) {
19802
19975
  if (caption == null || caption === "") {
19803
19976
  return "";
@@ -19805,16 +19978,6 @@ function renderCaption(caption) {
19805
19978
  return `<figcaption class="wp-element-caption">${escapeText(caption)}</figcaption>`;
19806
19979
  }
19807
19980
 
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
-
19818
19981
  // src/blocks/heading.ts
19819
19982
  function renderHeading(node2, ctx) {
19820
19983
  const { headingShift, minHeadingLevel, headingAnchors } = ctx.options;
@@ -19854,12 +20017,21 @@ function headingText(nodes) {
19854
20017
  // src/blocks/list.ts
19855
20018
  function renderList(node2, ctx) {
19856
20019
  const tag = node2.ordered ? "ol" : "ul";
19857
- const attrs = node2.ordered ? ' {"ordered":true}' : "";
20020
+ const attributes = {};
20021
+ let startAttr = "";
20022
+ if (node2.ordered) {
20023
+ attributes.ordered = true;
20024
+ if (node2.start != null && node2.start !== 1) {
20025
+ attributes.start = node2.start;
20026
+ startAttr = ` start="${node2.start}"`;
20027
+ }
20028
+ }
20029
+ const attrs = serializeBlockAttributes(attributes);
19858
20030
  const items = [];
19859
20031
  for (const child of node2.children) {
19860
20032
  items.push(renderListItem(child, ctx));
19861
20033
  }
19862
- const inner = `<${tag} class="wp-block-list">${items.join("\n\n")}</${tag}>`;
20034
+ const inner = `<${tag}${startAttr} class="wp-block-list">${items.join("\n\n")}</${tag}>`;
19863
20035
  return `<!-- wp:list${attrs} -->
19864
20036
  ${inner}
19865
20037
  <!-- /wp:list -->`;
@@ -19890,8 +20062,12 @@ ${li}
19890
20062
 
19891
20063
  // src/blocks/paragraph.ts
19892
20064
  function renderParagraph(node2, ctx) {
19893
- if (node2.children.length === 1 && node2.children[0]?.type === "image") {
19894
- return renderImage(node2.children[0], ctx);
20065
+ const only = node2.children.length === 1 ? node2.children[0] : void 0;
20066
+ if (only?.type === "image") {
20067
+ return renderImage(only, ctx);
20068
+ }
20069
+ if (only?.type === "link" && only.children.length === 1 && only.children[0]?.type === "image") {
20070
+ return renderImage(only.children[0], ctx, only);
19895
20071
  }
19896
20072
  const inner = ctx.renderInline(node2.children);
19897
20073
  if (inner.trim() === "") {
@@ -19947,14 +20123,35 @@ function renderRow(row, cellTag, ctx) {
19947
20123
  }
19948
20124
 
19949
20125
  // src/convert.ts
20126
+ var MAX_NESTING_DEPTH = 200;
19950
20127
  function parseMarkdown(markdown, options) {
19951
20128
  const base = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]);
19952
20129
  const processor = options.gfm ? base.use(remarkGfm) : base;
19953
20130
  const tree = processor.parse(markdown);
19954
20131
  const root2 = processor.runSync(tree);
20132
+ const depth = maxDepth(root2);
20133
+ if (depth > MAX_NESTING_DEPTH) {
20134
+ throw new RangeError(
20135
+ `Markdown nests ${depth} levels deep; the limit is ${MAX_NESTING_DEPTH}`
20136
+ );
20137
+ }
19955
20138
  resolveReferences(root2);
19956
20139
  return root2;
19957
20140
  }
20141
+ function maxDepth(root2) {
20142
+ let deepest = 0;
20143
+ const pending = [{ node: root2, depth: 0 }];
20144
+ let entry = pending.pop();
20145
+ while (entry != null) {
20146
+ deepest = Math.max(deepest, entry.depth);
20147
+ const children = entry.node.children ?? [];
20148
+ for (const child of children) {
20149
+ pending.push({ node: child, depth: entry.depth + 1 });
20150
+ }
20151
+ entry = pending.pop();
20152
+ }
20153
+ return deepest;
20154
+ }
19958
20155
  function resolveReferences(tree) {
19959
20156
  const definitions = /* @__PURE__ */ new Map();
19960
20157
  visit(tree, "definition", (node2) => {
@@ -19962,25 +20159,23 @@ function resolveReferences(tree) {
19962
20159
  });
19963
20160
  visit(tree, "linkReference", (node2) => {
19964
20161
  const def = definitions.get(node2.identifier);
19965
- if (def == null) {
19966
- return;
20162
+ if (def != null) {
20163
+ const link2 = node2;
20164
+ link2.type = "link";
20165
+ link2.url = def.url;
20166
+ link2.title = def.title ?? null;
19967
20167
  }
19968
- const link2 = node2;
19969
- link2.type = "link";
19970
- link2.url = def.url;
19971
- link2.title = def.title ?? null;
19972
20168
  });
19973
20169
  visit(tree, "imageReference", (node2) => {
19974
20170
  const def = definitions.get(node2.identifier);
19975
- if (def == null) {
19976
- return;
20171
+ if (def != null) {
20172
+ const alt = node2.alt ?? "";
20173
+ const image2 = node2;
20174
+ image2.type = "image";
20175
+ image2.url = def.url;
20176
+ image2.title = def.title ?? null;
20177
+ image2.alt = alt;
19977
20178
  }
19978
- const alt = node2.alt ?? "";
19979
- const image2 = node2;
19980
- image2.type = "image";
19981
- image2.url = def.url;
19982
- image2.title = def.title ?? null;
19983
- image2.alt = alt;
19984
20179
  });
19985
20180
  }
19986
20181
  function createContext(options) {
@@ -20103,8 +20298,10 @@ function parseFrontmatter(value2) {
20103
20298
  }
20104
20299
 
20105
20300
  export {
20301
+ applyOptionDefaults,
20302
+ validateOptions,
20106
20303
  markdownToBlockList,
20107
20304
  markdownToBlocks,
20108
20305
  parseMarkdownDocument
20109
20306
  };
20110
- //# sourceMappingURL=chunk-FWYKR6IX.js.map
20307
+ //# sourceMappingURL=chunk-VRPK6PTA.js.map