@markdoc/markdoc 0.1.9 → 0.1.11

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
@@ -6717,6 +6717,10 @@ var STATES;
6717
6717
  })(STATES || (STATES = {}));
6718
6718
  var OPEN = "{%";
6719
6719
  var CLOSE = "%}";
6720
+ var IDENTIFIER_REGEX = /^[a-zA-Z0-9_-]+$/;
6721
+ function isIdentifier(s2) {
6722
+ return IDENTIFIER_REGEX.test(s2);
6723
+ }
6720
6724
  function isPromise(a) {
6721
6725
  return a && typeof a === "object" && typeof a.then === "function";
6722
6726
  }
@@ -6964,22 +6968,22 @@ function formatScalar(v) {
6964
6968
  return "[" + v.map(formatScalar).join(SEP) + "]";
6965
6969
  }
6966
6970
  if (typeof v === "object") {
6967
- return "{" + Object.entries(v).map(([key, value]) => `${key}: ${formatScalar(value)}`).join(SEP) + "}";
6971
+ return "{" + Object.entries(v).map(([key, value]) => `${isIdentifier(key) ? key : `"${key}"`}: ${formatScalar(value)}`).join(SEP) + "}";
6968
6972
  }
6969
6973
  return JSON.stringify(v);
6970
6974
  }
6971
6975
  function formatAnnotationValue(a) {
6972
6976
  if (a.name === "primary")
6973
6977
  return formatScalar(a.value);
6974
- if (a.name === "id" && typeof a.value === "string")
6978
+ if (a.name === "id" && typeof a.value === "string" && isIdentifier(a.value))
6975
6979
  return "#" + a.value;
6976
- if (a.type === "class")
6980
+ if (a.type === "class" && isIdentifier(a.name))
6977
6981
  return "." + a.name;
6978
6982
  return `${a.name}=${formatScalar(a.value)}`;
6979
6983
  }
6980
6984
  function* formatAttributes(n) {
6981
6985
  for (const [key, value] of Object.entries(n.attributes)) {
6982
- if (key === "class" && !ast_default.isAst(value))
6986
+ if (key === "class" && typeof value === "object" && !ast_default.isAst(value))
6983
6987
  for (const name of Object.keys(value)) {
6984
6988
  yield formatAnnotationValue({ type: "class", name, value });
6985
6989
  }
@@ -6996,7 +7000,13 @@ function* formatAnnotations(n) {
6996
7000
  }
6997
7001
  function* formatVariable(v) {
6998
7002
  yield "$";
6999
- yield v.path.join(".");
7003
+ yield v.path.map((p, i) => {
7004
+ if (i === 0)
7005
+ return p;
7006
+ if (isIdentifier(String(p)))
7007
+ return "." + p;
7008
+ return `["${p}"]`;
7009
+ }).join("");
7000
7010
  }
7001
7011
  function* formatFunction(f) {
7002
7012
  yield f.name;
@@ -7232,10 +7242,11 @@ function* formatNode(n, o = {}) {
7232
7242
  yield* formatChildren(n, no);
7233
7243
  break;
7234
7244
  }
7235
- case "error": {
7236
- console.error(n);
7245
+ case "comment": {
7246
+ yield "<!-- " + n.attributes.content + " -->\n";
7237
7247
  break;
7238
7248
  }
7249
+ case "error":
7239
7250
  case "node":
7240
7251
  break;
7241
7252
  }