@markdoc/markdoc 0.1.6 → 0.1.7
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 +27 -23
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +27 -23
- package/dist/index.mjs.map +2 -2
- package/dist/src/formatter.d.ts +1 -0
- package/dist/src/formatter.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/formatter.test.ts +74 -3
- package/src/formatter.ts +42 -24
- package/src/schema.ts +1 -1
- package/src/validator.test.ts +46 -18
- package/src/validator.ts +2 -2
package/dist/index.mjs
CHANGED
|
@@ -6939,7 +6939,7 @@ var SEP = ", ";
|
|
|
6939
6939
|
var NL = "\n";
|
|
6940
6940
|
var OL = "1. ";
|
|
6941
6941
|
var UL = "- ";
|
|
6942
|
-
var
|
|
6942
|
+
var MAX_TAG_OPENING_WIDTH = 80;
|
|
6943
6943
|
var max = (a, b) => Math.max(a, b);
|
|
6944
6944
|
var increment = (o, n = 2) => ({
|
|
6945
6945
|
...o,
|
|
@@ -6970,7 +6970,7 @@ function formatScalar(v) {
|
|
|
6970
6970
|
}
|
|
6971
6971
|
function formatAnnotationValue(a) {
|
|
6972
6972
|
if (a.name === "primary")
|
|
6973
|
-
return a.value;
|
|
6973
|
+
return formatScalar(a.value);
|
|
6974
6974
|
if (a.name === "id" && typeof a.value === "string")
|
|
6975
6975
|
return "#" + a.value;
|
|
6976
6976
|
if (a.type === "class")
|
|
@@ -7110,20 +7110,14 @@ function* formatNode(n, o = {}) {
|
|
|
7110
7110
|
const open = OPEN + SPACE;
|
|
7111
7111
|
const tag = [open + n.tag, ...formatAttributes(n)];
|
|
7112
7112
|
const inlineTag = tag.join(SPACE);
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
} else {
|
|
7116
|
-
yield inlineTag;
|
|
7117
|
-
}
|
|
7118
|
-
yield SPACE + (n.children.length ? "" : "/") + CLOSE;
|
|
7113
|
+
const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
|
|
7114
|
+
yield (isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
|
|
7119
7115
|
if (n.children.length) {
|
|
7120
7116
|
yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
|
|
7121
7117
|
if (!n.inline) {
|
|
7122
7118
|
yield indent;
|
|
7123
7119
|
}
|
|
7124
|
-
yield OPEN + SPACE + "/";
|
|
7125
|
-
yield n.tag;
|
|
7126
|
-
yield SPACE + CLOSE;
|
|
7120
|
+
yield OPEN + SPACE + "/" + n.tag + SPACE + CLOSE;
|
|
7127
7121
|
}
|
|
7128
7122
|
if (!n.inline) {
|
|
7129
7123
|
yield NL;
|
|
@@ -7182,16 +7176,26 @@ function* formatNode(n, o = {}) {
|
|
|
7182
7176
|
case "table": {
|
|
7183
7177
|
const table3 = [...formatChildren(n, increment(no))];
|
|
7184
7178
|
if (o.parent && o.parent.type === "tag" && o.parent.tag === "table") {
|
|
7185
|
-
for (
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7179
|
+
for (let i = 0; i < table3.length; i++) {
|
|
7180
|
+
const row = table3[i];
|
|
7181
|
+
if (typeof row === "string") {
|
|
7182
|
+
if (row.trim().length) {
|
|
7183
|
+
yield NL;
|
|
7184
|
+
yield row;
|
|
7185
|
+
}
|
|
7186
|
+
} else {
|
|
7187
|
+
if (i !== 0) {
|
|
7188
|
+
yield NL;
|
|
7189
|
+
yield indent + "---";
|
|
7190
|
+
}
|
|
7191
|
+
for (let j = 0; j < row.length; j++) {
|
|
7192
|
+
const d = row[j];
|
|
7193
|
+
yield NL;
|
|
7194
|
+
yield indent + UL + d.trim();
|
|
7195
|
+
}
|
|
7193
7196
|
}
|
|
7194
7197
|
}
|
|
7198
|
+
yield NL;
|
|
7195
7199
|
} else {
|
|
7196
7200
|
yield NL;
|
|
7197
7201
|
const [head, ...rows] = table3;
|
|
@@ -7274,7 +7278,7 @@ function format(v, options) {
|
|
|
7274
7278
|
let doc = "";
|
|
7275
7279
|
for (const s2 of formatValue(v, options))
|
|
7276
7280
|
doc += s2;
|
|
7277
|
-
return doc;
|
|
7281
|
+
return doc.trimStart();
|
|
7278
7282
|
}
|
|
7279
7283
|
|
|
7280
7284
|
// src/tags/conditional.ts
|
|
@@ -7778,7 +7782,7 @@ var hardbreak = {
|
|
|
7778
7782
|
render: "br"
|
|
7779
7783
|
};
|
|
7780
7784
|
var softbreak = {
|
|
7781
|
-
transform(
|
|
7785
|
+
transform() {
|
|
7782
7786
|
return " ";
|
|
7783
7787
|
}
|
|
7784
7788
|
};
|
|
@@ -8277,13 +8281,13 @@ function validate(node2, config) {
|
|
|
8277
8281
|
errors.push({
|
|
8278
8282
|
id: "attribute-value-invalid",
|
|
8279
8283
|
level: errorLevel || "error",
|
|
8280
|
-
message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}
|
|
8284
|
+
message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}. Got '${value}' instead.`
|
|
8281
8285
|
});
|
|
8282
8286
|
if (matches instanceof RegExp && !matches.test(value))
|
|
8283
8287
|
errors.push({
|
|
8284
8288
|
id: "attribute-value-invalid",
|
|
8285
8289
|
level: errorLevel || "error",
|
|
8286
|
-
message: `Attribute '${key}' must match ${matches}
|
|
8290
|
+
message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
|
|
8287
8291
|
});
|
|
8288
8292
|
}
|
|
8289
8293
|
for (const [key, { required }] of Object.entries(attributes))
|