@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 +8 -1
- package/dist/index.js +19 -6
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +19 -6
- 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 +2 -2
- package/src/formatter.test.ts +50 -1
- package/src/formatter.ts +22 -8
- 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;
|
|
@@ -7007,7 +7017,10 @@ function* formatFunction(f) {
|
|
|
7007
7017
|
function* trimStart(g) {
|
|
7008
7018
|
let n;
|
|
7009
7019
|
do {
|
|
7010
|
-
|
|
7020
|
+
const { value, done } = g.next();
|
|
7021
|
+
if (done)
|
|
7022
|
+
return;
|
|
7023
|
+
n = value.trimStart();
|
|
7011
7024
|
} while (!n.length);
|
|
7012
7025
|
yield n;
|
|
7013
7026
|
yield* g;
|
|
@@ -7096,7 +7109,7 @@ function* formatNode(n, o = {}) {
|
|
|
7096
7109
|
yield* formatAnnotations(n);
|
|
7097
7110
|
yield NL;
|
|
7098
7111
|
yield indent;
|
|
7099
|
-
yield
|
|
7112
|
+
yield n.attributes.content;
|
|
7100
7113
|
yield indent;
|
|
7101
7114
|
yield "```";
|
|
7102
7115
|
yield NL;
|