@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 +14 -4
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +14 -4
- package/dist/index.mjs.map +2 -2
- package/dist/src/formatter.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 +16 -5
- package/src/formatter.ts +16 -5
- package/src/utils.ts +6 -0
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
|
}
|
|
@@ -6971,15 +6975,15 @@ function formatScalar(v) {
|
|
|
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.
|
|
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;
|