@markdoc/markdoc 0.4.0 → 0.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.
package/dist/index.mjs CHANGED
@@ -7165,7 +7165,7 @@ function* formatNode(n, o = {}) {
7165
7165
  yield* formatValue(n.attributes.alt, no);
7166
7166
  yield "]";
7167
7167
  yield "(";
7168
- yield* typeof n.attributes.src === "string" ? escapeMarkdownCharacters(n.attributes.src, /[()]/) : formatValue(n.attributes.src, no);
7168
+ yield* typeof n.attributes.src === "string" ? escapeMarkdownCharacters(n.attributes.src, /[()]/g) : formatValue(n.attributes.src, no);
7169
7169
  if (n.attributes.title) {
7170
7170
  yield SPACE + `"${n.attributes.title}"`;
7171
7171
  }
@@ -7217,6 +7217,7 @@ function* formatNode(n, o = {}) {
7217
7217
  const innerFence = n.attributes.content.match(/`{3,}/g) || [];
7218
7218
  const innerFenceLength = innerFence.map((s2) => s2.length).reduce(max, 0);
7219
7219
  const boundary = "`".repeat(innerFenceLength ? innerFenceLength + 1 : 3);
7220
+ const needsNlBeforeEndBoundary = !n.attributes.content.endsWith(NL);
7220
7221
  yield boundary;
7221
7222
  if (n.attributes.language)
7222
7223
  yield n.attributes.language;
@@ -7226,6 +7227,9 @@ function* formatNode(n, o = {}) {
7226
7227
  yield NL;
7227
7228
  yield indent;
7228
7229
  yield n.attributes.content.split(NL).join(NL + indent);
7230
+ if (needsNlBeforeEndBoundary) {
7231
+ yield NL;
7232
+ }
7229
7233
  yield boundary;
7230
7234
  yield NL;
7231
7235
  break;
@@ -7256,7 +7260,18 @@ function* formatNode(n, o = {}) {
7256
7260
  case "list": {
7257
7261
  const isLoose = n.children.some((n2) => n2.children.some((c) => c.type === "paragraph"));
7258
7262
  for (let i = 0; i < n.children.length; i++) {
7259
- const prefix = n.attributes.ordered ? `${i === 0 ? n.attributes.start ?? "1" : "1"}${n.attributes.marker ?? OL}` : n.attributes.marker ?? UL;
7263
+ const prefix = (() => {
7264
+ if (!n.attributes.ordered)
7265
+ return n.attributes.marker ?? UL;
7266
+ let number = "1";
7267
+ const startNumber = n.attributes.start ?? 1;
7268
+ if (i === 0)
7269
+ number = startNumber.toString();
7270
+ if (o.orderedListMode === "increment") {
7271
+ number = (parseInt(startNumber) + i).toString();
7272
+ }
7273
+ return `${number}${n.attributes.marker ?? OL}`;
7274
+ })();
7260
7275
  let d = format(n.children[i], increment(no, prefix.length + 1));
7261
7276
  if (!isLoose || i === n.children.length - 1) {
7262
7277
  d = d.trim();
@@ -8012,7 +8027,7 @@ function render(node2) {
8012
8027
  function tagName(name, components) {
8013
8028
  return typeof name !== "string" ? name : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
8014
8029
  }
8015
- function dynamic(node2, React, { components = {} } = {}) {
8030
+ function dynamic(node2, React, { components = {}, resolveTagName = tagName } = {}) {
8016
8031
  function deepRender2(value) {
8017
8032
  if (value == null || typeof value !== "object")
8018
8033
  return value;
@@ -8039,7 +8054,7 @@ function dynamic(node2, React, { components = {} } = {}) {
8039
8054
  } = node3;
8040
8055
  if (className)
8041
8056
  attrs.className = className;
8042
- return React.createElement(tagName(name, components), Object.keys(attrs).length == 0 ? null : deepRender2(attrs), ...children.map(render3));
8057
+ return React.createElement(resolveTagName(name, components), Object.keys(attrs).length == 0 ? null : deepRender2(attrs), ...children.map(render3));
8043
8058
  }
8044
8059
  return render3(node2);
8045
8060
  }
@@ -8080,10 +8095,13 @@ function render2(node2) {
8080
8095
  ${Object.keys(attrs).length == 0 ? "null" : deepRender(attrs)},
8081
8096
  ${renderArray(children)})`;
8082
8097
  }
8083
- function reactStatic(node2) {
8098
+ function reactStatic(node2, { resolveTagName = tagName2 } = {}) {
8099
+ if (resolveTagName.name !== "tagName") {
8100
+ throw new Error("resolveTagName must be named tagName");
8101
+ }
8084
8102
  return `
8085
8103
  (({components = {}} = {}) => {
8086
- ${tagName2}
8104
+ ${resolveTagName}
8087
8105
  return ${render2(node2)};
8088
8106
  })
8089
8107
  `;
@@ -8667,6 +8685,7 @@ Markdoc.truthy = truthy;
8667
8685
  Markdoc.format = format;
8668
8686
  export {
8669
8687
  ast_default as Ast,
8688
+ Node,
8670
8689
  Tag,
8671
8690
  Tokenizer,
8672
8691
  createElement,