@markdoc/markdoc 0.1.9 → 0.1.10

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
@@ -6741,6 +6741,10 @@ var STATES;
6741
6741
  })(STATES || (STATES = {}));
6742
6742
  var OPEN = "{%";
6743
6743
  var CLOSE = "%}";
6744
+ var IDENTIFIER_REGEX = /^[a-zA-Z0-9_-]+$/;
6745
+ function isIdentifier(s2) {
6746
+ return IDENTIFIER_REGEX.test(s2);
6747
+ }
6744
6748
  function isPromise(a) {
6745
6749
  return a && typeof a === "object" && typeof a.then === "function";
6746
6750
  }
@@ -6995,15 +6999,15 @@ function formatScalar(v) {
6995
6999
  function formatAnnotationValue(a) {
6996
7000
  if (a.name === "primary")
6997
7001
  return formatScalar(a.value);
6998
- if (a.name === "id" && typeof a.value === "string")
7002
+ if (a.name === "id" && typeof a.value === "string" && isIdentifier(a.value))
6999
7003
  return "#" + a.value;
7000
- if (a.type === "class")
7004
+ if (a.type === "class" && isIdentifier(a.name))
7001
7005
  return "." + a.name;
7002
7006
  return `${a.name}=${formatScalar(a.value)}`;
7003
7007
  }
7004
7008
  function* formatAttributes(n) {
7005
7009
  for (const [key, value] of Object.entries(n.attributes)) {
7006
- if (key === "class" && !ast_default.isAst(value))
7010
+ if (key === "class" && typeof value === "object" && !ast_default.isAst(value))
7007
7011
  for (const name of Object.keys(value)) {
7008
7012
  yield formatAnnotationValue({ type: "class", name, value });
7009
7013
  }
@@ -7020,7 +7024,13 @@ function* formatAnnotations(n) {
7020
7024
  }
7021
7025
  function* formatVariable(v) {
7022
7026
  yield "$";
7023
- yield v.path.join(".");
7027
+ yield v.path.map((p, i) => {
7028
+ if (i === 0)
7029
+ return p;
7030
+ if (isIdentifier(String(p)))
7031
+ return "." + p;
7032
+ return `["${p}"]`;
7033
+ }).join("");
7024
7034
  }
7025
7035
  function* formatFunction(f) {
7026
7036
  yield f.name;