@markdoc/markdoc 0.1.6 → 0.1.7

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
@@ -6963,7 +6963,7 @@ var SEP = ", ";
6963
6963
  var NL = "\n";
6964
6964
  var OL = "1. ";
6965
6965
  var UL = "- ";
6966
- var MAX_TAG_HEAD_LENGTH = 80;
6966
+ var MAX_TAG_OPENING_WIDTH = 80;
6967
6967
  var max = (a, b) => Math.max(a, b);
6968
6968
  var increment = (o, n = 2) => ({
6969
6969
  ...o,
@@ -6994,7 +6994,7 @@ function formatScalar(v) {
6994
6994
  }
6995
6995
  function formatAnnotationValue(a) {
6996
6996
  if (a.name === "primary")
6997
- return a.value;
6997
+ return formatScalar(a.value);
6998
6998
  if (a.name === "id" && typeof a.value === "string")
6999
6999
  return "#" + a.value;
7000
7000
  if (a.type === "class")
@@ -7134,20 +7134,14 @@ function* formatNode(n, o = {}) {
7134
7134
  const open = OPEN + SPACE;
7135
7135
  const tag = [open + n.tag, ...formatAttributes(n)];
7136
7136
  const inlineTag = tag.join(SPACE);
7137
- if (inlineTag.length + open.length * 2 > MAX_TAG_HEAD_LENGTH) {
7138
- yield tag.join(NL + SPACE.repeat(open.length) + indent);
7139
- } else {
7140
- yield inlineTag;
7141
- }
7142
- yield SPACE + (n.children.length ? "" : "/") + CLOSE;
7137
+ const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
7138
+ yield (isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
7143
7139
  if (n.children.length) {
7144
7140
  yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
7145
7141
  if (!n.inline) {
7146
7142
  yield indent;
7147
7143
  }
7148
- yield OPEN + SPACE + "/";
7149
- yield n.tag;
7150
- yield SPACE + CLOSE;
7144
+ yield OPEN + SPACE + "/" + n.tag + SPACE + CLOSE;
7151
7145
  }
7152
7146
  if (!n.inline) {
7153
7147
  yield NL;
@@ -7206,16 +7200,26 @@ function* formatNode(n, o = {}) {
7206
7200
  case "table": {
7207
7201
  const table3 = [...formatChildren(n, increment(no))];
7208
7202
  if (o.parent && o.parent.type === "tag" && o.parent.tag === "table") {
7209
- for (const row of table3) {
7210
- yield NL;
7211
- for (const d of row) {
7212
- yield indent + UL + d.trim();
7213
- yield NL;
7214
- }
7215
- if (row !== table3[table3.length - 1]) {
7216
- yield indent + "---";
7203
+ for (let i = 0; i < table3.length; i++) {
7204
+ const row = table3[i];
7205
+ if (typeof row === "string") {
7206
+ if (row.trim().length) {
7207
+ yield NL;
7208
+ yield row;
7209
+ }
7210
+ } else {
7211
+ if (i !== 0) {
7212
+ yield NL;
7213
+ yield indent + "---";
7214
+ }
7215
+ for (let j = 0; j < row.length; j++) {
7216
+ const d = row[j];
7217
+ yield NL;
7218
+ yield indent + UL + d.trim();
7219
+ }
7217
7220
  }
7218
7221
  }
7222
+ yield NL;
7219
7223
  } else {
7220
7224
  yield NL;
7221
7225
  const [head, ...rows] = table3;
@@ -7298,7 +7302,7 @@ function format(v, options) {
7298
7302
  let doc = "";
7299
7303
  for (const s2 of formatValue(v, options))
7300
7304
  doc += s2;
7301
- return doc;
7305
+ return doc.trimStart();
7302
7306
  }
7303
7307
 
7304
7308
  // src/tags/conditional.ts
@@ -7802,7 +7806,7 @@ var hardbreak = {
7802
7806
  render: "br"
7803
7807
  };
7804
7808
  var softbreak = {
7805
- transform(_node, _config) {
7809
+ transform() {
7806
7810
  return " ";
7807
7811
  }
7808
7812
  };
@@ -8301,13 +8305,13 @@ function validate(node2, config) {
8301
8305
  errors.push({
8302
8306
  id: "attribute-value-invalid",
8303
8307
  level: errorLevel || "error",
8304
- message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}`
8308
+ message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}. Got '${value}' instead.`
8305
8309
  });
8306
8310
  if (matches instanceof RegExp && !matches.test(value))
8307
8311
  errors.push({
8308
8312
  id: "attribute-value-invalid",
8309
8313
  level: errorLevel || "error",
8310
- message: `Attribute '${key}' must match ${matches}`
8314
+ message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
8311
8315
  });
8312
8316
  }
8313
8317
  for (const [key, { required }] of Object.entries(attributes))