@markdoc/markdoc 0.3.5 → 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
@@ -141,6 +141,9 @@ var require_tag = __commonJS({
141
141
  var peg$c15 = "-";
142
142
  var peg$c16 = '"';
143
143
  var peg$c17 = "\\";
144
+ var peg$c18 = "n";
145
+ var peg$c19 = "r";
146
+ var peg$c20 = "t";
144
147
  var peg$r0 = /^[$@]/;
145
148
  var peg$r1 = /^[0-9]/;
146
149
  var peg$r2 = /^[^\0-\x1F"\\]/;
@@ -267,7 +270,16 @@ var require_tag = __commonJS({
267
270
  var peg$f28 = function(value) {
268
271
  return value.join("");
269
272
  };
270
- var peg$f29 = function(sequence) {
273
+ var peg$f29 = function() {
274
+ return "\n";
275
+ };
276
+ var peg$f30 = function() {
277
+ return "\r";
278
+ };
279
+ var peg$f31 = function() {
280
+ return " ";
281
+ };
282
+ var peg$f32 = function(sequence) {
271
283
  return sequence;
272
284
  };
273
285
  var peg$currPos = 0;
@@ -1525,7 +1537,7 @@ var require_tag = __commonJS({
1525
1537
  return s0;
1526
1538
  }
1527
1539
  function peg$parseValueStringEscapes() {
1528
- var s0, s1, s2;
1540
+ var s0, s1, s2, s3;
1529
1541
  var rule$expects = function(expected2) {
1530
1542
  if (peg$silentFails === 0)
1531
1543
  peg$expect(expected2);
@@ -1551,10 +1563,52 @@ var require_tag = __commonJS({
1551
1563
  } else {
1552
1564
  s2 = peg$FAILED;
1553
1565
  }
1566
+ if (s2 === peg$FAILED) {
1567
+ s2 = peg$currPos;
1568
+ if (input.charCodeAt(peg$currPos) === 110) {
1569
+ s3 = peg$c18;
1570
+ peg$currPos++;
1571
+ } else {
1572
+ s3 = peg$FAILED;
1573
+ }
1574
+ if (s3 !== peg$FAILED) {
1575
+ peg$savedPos = s2;
1576
+ s3 = peg$f29();
1577
+ }
1578
+ s2 = s3;
1579
+ if (s2 === peg$FAILED) {
1580
+ s2 = peg$currPos;
1581
+ if (input.charCodeAt(peg$currPos) === 114) {
1582
+ s3 = peg$c19;
1583
+ peg$currPos++;
1584
+ } else {
1585
+ s3 = peg$FAILED;
1586
+ }
1587
+ if (s3 !== peg$FAILED) {
1588
+ peg$savedPos = s2;
1589
+ s3 = peg$f30();
1590
+ }
1591
+ s2 = s3;
1592
+ if (s2 === peg$FAILED) {
1593
+ s2 = peg$currPos;
1594
+ if (input.charCodeAt(peg$currPos) === 116) {
1595
+ s3 = peg$c20;
1596
+ peg$currPos++;
1597
+ } else {
1598
+ s3 = peg$FAILED;
1599
+ }
1600
+ if (s3 !== peg$FAILED) {
1601
+ peg$savedPos = s2;
1602
+ s3 = peg$f31();
1603
+ }
1604
+ s2 = s3;
1605
+ }
1606
+ }
1607
+ }
1554
1608
  }
1555
1609
  if (s2 !== peg$FAILED) {
1556
1610
  peg$savedPos = s0;
1557
- s0 = peg$f29(s2);
1611
+ s0 = peg$f32(s2);
1558
1612
  } else {
1559
1613
  peg$currPos = s0;
1560
1614
  s0 = peg$FAILED;
@@ -7111,7 +7165,7 @@ function* formatNode(n, o = {}) {
7111
7165
  yield* formatValue(n.attributes.alt, no);
7112
7166
  yield "]";
7113
7167
  yield "(";
7114
- 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);
7115
7169
  if (n.attributes.title) {
7116
7170
  yield SPACE + `"${n.attributes.title}"`;
7117
7171
  }
@@ -7163,6 +7217,7 @@ function* formatNode(n, o = {}) {
7163
7217
  const innerFence = n.attributes.content.match(/`{3,}/g) || [];
7164
7218
  const innerFenceLength = innerFence.map((s2) => s2.length).reduce(max, 0);
7165
7219
  const boundary = "`".repeat(innerFenceLength ? innerFenceLength + 1 : 3);
7220
+ const needsNlBeforeEndBoundary = !n.attributes.content.endsWith(NL);
7166
7221
  yield boundary;
7167
7222
  if (n.attributes.language)
7168
7223
  yield n.attributes.language;
@@ -7172,6 +7227,9 @@ function* formatNode(n, o = {}) {
7172
7227
  yield NL;
7173
7228
  yield indent;
7174
7229
  yield n.attributes.content.split(NL).join(NL + indent);
7230
+ if (needsNlBeforeEndBoundary) {
7231
+ yield NL;
7232
+ }
7175
7233
  yield boundary;
7176
7234
  yield NL;
7177
7235
  break;
@@ -7202,7 +7260,18 @@ function* formatNode(n, o = {}) {
7202
7260
  case "list": {
7203
7261
  const isLoose = n.children.some((n2) => n2.children.some((c) => c.type === "paragraph"));
7204
7262
  for (let i = 0; i < n.children.length; i++) {
7205
- 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
+ })();
7206
7275
  let d = format(n.children[i], increment(no, prefix.length + 1));
7207
7276
  if (!isLoose || i === n.children.length - 1) {
7208
7277
  d = d.trim();
@@ -7820,7 +7889,7 @@ var td = {
7820
7889
  var th = {
7821
7890
  render: "th",
7822
7891
  attributes: {
7823
- width: { type: Number },
7892
+ width: { type: String },
7824
7893
  align: { type: String },
7825
7894
  colspan: { type: Number, render: "colSpan" },
7826
7895
  rowspan: { type: Number, render: "rowSpan" }
@@ -7958,7 +8027,7 @@ function render(node2) {
7958
8027
  function tagName(name, components) {
7959
8028
  return typeof name !== "string" ? name : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
7960
8029
  }
7961
- function dynamic(node2, React, { components = {} } = {}) {
8030
+ function dynamic(node2, React, { components = {}, resolveTagName = tagName } = {}) {
7962
8031
  function deepRender2(value) {
7963
8032
  if (value == null || typeof value !== "object")
7964
8033
  return value;
@@ -7985,7 +8054,7 @@ function dynamic(node2, React, { components = {} } = {}) {
7985
8054
  } = node3;
7986
8055
  if (className)
7987
8056
  attrs.className = className;
7988
- 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));
7989
8058
  }
7990
8059
  return render3(node2);
7991
8060
  }
@@ -8026,10 +8095,13 @@ function render2(node2) {
8026
8095
  ${Object.keys(attrs).length == 0 ? "null" : deepRender(attrs)},
8027
8096
  ${renderArray(children)})`;
8028
8097
  }
8029
- function reactStatic(node2) {
8098
+ function reactStatic(node2, { resolveTagName = tagName2 } = {}) {
8099
+ if (resolveTagName.name !== "tagName") {
8100
+ throw new Error("resolveTagName must be named tagName");
8101
+ }
8030
8102
  return `
8031
8103
  (({components = {}} = {}) => {
8032
- ${tagName2}
8104
+ ${resolveTagName}
8033
8105
  return ${render2(node2)};
8034
8106
  })
8035
8107
  `;
@@ -8613,6 +8685,7 @@ Markdoc.truthy = truthy;
8613
8685
  Markdoc.format = format;
8614
8686
  export {
8615
8687
  ast_default as Ast,
8688
+ Node,
8616
8689
  Tag,
8617
8690
  Tokenizer,
8618
8691
  createElement,