@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.js +18 -7
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +18 -7
- package/dist/index.mjs.map +2 -2
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/formatter.test.ts +47 -8
- package/src/formatter.ts +23 -8
- package/src/types.ts +1 -0
- package/src/utils.ts +6 -0
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
|
}
|
|
@@ -6988,22 +6992,22 @@ function formatScalar(v) {
|
|
|
6988
6992
|
return "[" + v.map(formatScalar).join(SEP) + "]";
|
|
6989
6993
|
}
|
|
6990
6994
|
if (typeof v === "object") {
|
|
6991
|
-
return "{" + Object.entries(v).map(([key, value]) => `${key}: ${formatScalar(value)}`).join(SEP) + "}";
|
|
6995
|
+
return "{" + Object.entries(v).map(([key, value]) => `${isIdentifier(key) ? key : `"${key}"`}: ${formatScalar(value)}`).join(SEP) + "}";
|
|
6992
6996
|
}
|
|
6993
6997
|
return JSON.stringify(v);
|
|
6994
6998
|
}
|
|
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.
|
|
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;
|
|
@@ -7256,10 +7266,11 @@ function* formatNode(n, o = {}) {
|
|
|
7256
7266
|
yield* formatChildren(n, no);
|
|
7257
7267
|
break;
|
|
7258
7268
|
}
|
|
7259
|
-
case "
|
|
7260
|
-
|
|
7269
|
+
case "comment": {
|
|
7270
|
+
yield "<!-- " + n.attributes.content + " -->\n";
|
|
7261
7271
|
break;
|
|
7262
7272
|
}
|
|
7273
|
+
case "error":
|
|
7263
7274
|
case "node":
|
|
7264
7275
|
break;
|
|
7265
7276
|
}
|