@markdoc/markdoc 0.1.8 → 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/README.md CHANGED
@@ -53,7 +53,14 @@ return Markdoc.renderers.react(content, React);
53
53
  Check out [our docs](https://markdoc.dev/docs) for more guidance on how to use Markdoc.
54
54
 
55
55
  ### TypeScript
56
- This is the minimal `tsconfig.json` in order to use Markdoc in your TypeScript project
56
+
57
+ When using TypeScript, install Markdoc with:
58
+
59
+ ```sh
60
+ npm install @markdoc/markdoc @types/react @types/markdown-it
61
+ ```
62
+
63
+ Additionally, this is the minimal `tsconfig.json` required to use Markdoc in your TypeScript project:
57
64
 
58
65
  ```json
59
66
  {
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;
@@ -7031,7 +7041,10 @@ function* formatFunction(f) {
7031
7041
  function* trimStart(g) {
7032
7042
  let n;
7033
7043
  do {
7034
- n = g.next().value.trimStart();
7044
+ const { value, done } = g.next();
7045
+ if (done)
7046
+ return;
7047
+ n = value.trimStart();
7035
7048
  } while (!n.length);
7036
7049
  yield n;
7037
7050
  yield* g;
@@ -7120,7 +7133,7 @@ function* formatNode(n, o = {}) {
7120
7133
  yield* formatAnnotations(n);
7121
7134
  yield NL;
7122
7135
  yield indent;
7123
- yield* formatChildren(n, no);
7136
+ yield n.attributes.content;
7124
7137
  yield indent;
7125
7138
  yield "```";
7126
7139
  yield NL;