@markdoc/markdoc 0.1.12 → 0.1.13
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 +38 -24
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +38 -24
- package/dist/index.mjs.map +3 -3
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/renderers/html.d.ts.map +1 -1
- package/dist/src/schema-types/id.d.ts +5 -0
- package/dist/src/schema-types/id.d.ts.map +1 -0
- package/dist/src/tags/partial.d.ts.map +1 -1
- package/dist/src/tags/table.d.ts.map +1 -1
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/types.d.ts +1 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/formatter.test.ts +41 -1
- package/src/formatter.ts +10 -15
- package/src/parser.ts +2 -1
- package/src/renderers/html.test.ts +7 -0
- package/src/renderers/html.ts +2 -1
- package/src/schema-types/id.ts +15 -0
- package/src/tags/partial.ts +1 -0
- package/src/tags/table.ts +1 -0
- package/src/transformer.ts +2 -1
- package/src/types.ts +1 -0
- package/src/validator.test.ts +67 -0
- package/src/validator.ts +9 -6
package/dist/index.js
CHANGED
|
@@ -6702,6 +6702,21 @@ var Class = class {
|
|
|
6702
6702
|
}
|
|
6703
6703
|
};
|
|
6704
6704
|
|
|
6705
|
+
// src/schema-types/id.ts
|
|
6706
|
+
var Id = class {
|
|
6707
|
+
validate(value) {
|
|
6708
|
+
if (typeof value === "string" && value.match(/^[a-zA-Z]/))
|
|
6709
|
+
return [];
|
|
6710
|
+
return [
|
|
6711
|
+
{
|
|
6712
|
+
id: "attribute-value-invalid",
|
|
6713
|
+
level: "error",
|
|
6714
|
+
message: "The 'id' attribute must start with a letter"
|
|
6715
|
+
}
|
|
6716
|
+
];
|
|
6717
|
+
}
|
|
6718
|
+
};
|
|
6719
|
+
|
|
6705
6720
|
// src/utils.ts
|
|
6706
6721
|
var import_tag = __toModule(require_tag());
|
|
6707
6722
|
|
|
@@ -6848,7 +6863,7 @@ function parseTags(content, firstLine = 0) {
|
|
|
6848
6863
|
// src/transformer.ts
|
|
6849
6864
|
var globalAttributes = {
|
|
6850
6865
|
class: { type: Class, render: true },
|
|
6851
|
-
id: { type:
|
|
6866
|
+
id: { type: Id, render: true }
|
|
6852
6867
|
};
|
|
6853
6868
|
var transformer_default = {
|
|
6854
6869
|
findSchema(node2, { nodes = {}, tags = {} } = {}) {
|
|
@@ -7065,20 +7080,20 @@ function* formatNode(n, o = {}) {
|
|
|
7065
7080
|
yield indent;
|
|
7066
7081
|
yield "#".repeat(n.attributes.level || 1);
|
|
7067
7082
|
yield SPACE;
|
|
7068
|
-
yield* formatChildren(n, no);
|
|
7083
|
+
yield* trimStart(formatChildren(n, no));
|
|
7069
7084
|
yield* formatAnnotations(n);
|
|
7070
7085
|
yield NL;
|
|
7071
7086
|
break;
|
|
7072
7087
|
}
|
|
7073
7088
|
case "paragraph": {
|
|
7074
7089
|
yield NL;
|
|
7075
|
-
yield indent;
|
|
7076
7090
|
yield* formatChildren(n, no);
|
|
7077
7091
|
yield* formatAnnotations(n);
|
|
7078
7092
|
yield NL;
|
|
7079
7093
|
break;
|
|
7080
7094
|
}
|
|
7081
7095
|
case "inline": {
|
|
7096
|
+
yield indent;
|
|
7082
7097
|
yield* formatChildren(n, no);
|
|
7083
7098
|
break;
|
|
7084
7099
|
}
|
|
@@ -7133,7 +7148,8 @@ function* formatNode(n, o = {}) {
|
|
|
7133
7148
|
yield NL;
|
|
7134
7149
|
yield indent;
|
|
7135
7150
|
yield "```";
|
|
7136
|
-
|
|
7151
|
+
if (n.attributes.language)
|
|
7152
|
+
yield n.attributes.language;
|
|
7137
7153
|
if (n.annotations.length)
|
|
7138
7154
|
yield SPACE;
|
|
7139
7155
|
yield* formatAnnotations(n);
|
|
@@ -7153,7 +7169,7 @@ function* formatNode(n, o = {}) {
|
|
|
7153
7169
|
const tag = [open + n.tag, ...formatAttributes(n)];
|
|
7154
7170
|
const inlineTag = tag.join(SPACE);
|
|
7155
7171
|
const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
|
|
7156
|
-
yield (isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
|
|
7172
|
+
yield (!n.inline && isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
|
|
7157
7173
|
if (n.children.length) {
|
|
7158
7174
|
yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
|
|
7159
7175
|
if (!n.inline) {
|
|
@@ -7168,18 +7184,16 @@ function* formatNode(n, o = {}) {
|
|
|
7168
7184
|
}
|
|
7169
7185
|
case "list": {
|
|
7170
7186
|
const prefix = n.attributes.ordered ? OL : UL;
|
|
7171
|
-
yield NL;
|
|
7172
7187
|
for (const child of n.children) {
|
|
7173
7188
|
const d = format(child, increment(no, prefix.length)).trim();
|
|
7174
|
-
yield indent + prefix + d;
|
|
7175
|
-
yield NL;
|
|
7189
|
+
yield NL + indent + prefix + d;
|
|
7176
7190
|
}
|
|
7191
|
+
yield NL;
|
|
7177
7192
|
break;
|
|
7178
7193
|
}
|
|
7179
7194
|
case "item": {
|
|
7180
7195
|
for (let i = 0; i < n.children.length; i++) {
|
|
7181
|
-
|
|
7182
|
-
yield* formatValue(child, no);
|
|
7196
|
+
yield* formatValue(n.children[i], no);
|
|
7183
7197
|
if (i === 0)
|
|
7184
7198
|
yield* formatAnnotations(n);
|
|
7185
7199
|
}
|
|
@@ -7234,10 +7248,8 @@ function* formatNode(n, o = {}) {
|
|
|
7234
7248
|
yield NL;
|
|
7235
7249
|
yield indent + "---";
|
|
7236
7250
|
}
|
|
7237
|
-
for (
|
|
7238
|
-
|
|
7239
|
-
yield NL;
|
|
7240
|
-
yield indent + UL + d.trim();
|
|
7251
|
+
for (const d of row) {
|
|
7252
|
+
yield NL + indent + UL + d;
|
|
7241
7253
|
}
|
|
7242
7254
|
}
|
|
7243
7255
|
}
|
|
@@ -7268,7 +7280,7 @@ function* formatNode(n, o = {}) {
|
|
|
7268
7280
|
}
|
|
7269
7281
|
case "td":
|
|
7270
7282
|
case "th": {
|
|
7271
|
-
yield [...formatChildren(n, no), ...formatAnnotations(n)].join("");
|
|
7283
|
+
yield [...formatChildren(n, no), ...formatAnnotations(n)].join("").trim();
|
|
7272
7284
|
break;
|
|
7273
7285
|
}
|
|
7274
7286
|
case "tbody": {
|
|
@@ -7495,7 +7507,7 @@ function handleAttrs(token, type) {
|
|
|
7495
7507
|
return { content: (token.meta || {}).variable || token.content };
|
|
7496
7508
|
case "fence": {
|
|
7497
7509
|
const [language] = token.info.split(" ", 1);
|
|
7498
|
-
return language === "" ? { content: token.content } : { content: token.content, language };
|
|
7510
|
+
return language === "" || language === OPEN ? { content: token.content } : { content: token.content, language };
|
|
7499
7511
|
}
|
|
7500
7512
|
case "td":
|
|
7501
7513
|
case "th": {
|
|
@@ -7865,7 +7877,7 @@ var voidElements = new Set([
|
|
|
7865
7877
|
"wbr"
|
|
7866
7878
|
]);
|
|
7867
7879
|
function render(node2) {
|
|
7868
|
-
if (typeof node2 === "string")
|
|
7880
|
+
if (typeof node2 === "string" || typeof node2 === "number")
|
|
7869
7881
|
return escapeHtml(node2);
|
|
7870
7882
|
if (Array.isArray(node2))
|
|
7871
7883
|
return node2.map(render).join("");
|
|
@@ -7986,6 +7998,7 @@ var PartialFile = class {
|
|
|
7986
7998
|
}
|
|
7987
7999
|
};
|
|
7988
8000
|
var partial = {
|
|
8001
|
+
inline: false,
|
|
7989
8002
|
selfClosing: true,
|
|
7990
8003
|
attributes: {
|
|
7991
8004
|
file: { type: PartialFile, render: false, required: true },
|
|
@@ -8012,7 +8025,8 @@ var partial = {
|
|
|
8012
8025
|
|
|
8013
8026
|
// src/tags/table.ts
|
|
8014
8027
|
var table2 = {
|
|
8015
|
-
children: ["table"]
|
|
8028
|
+
children: ["table"],
|
|
8029
|
+
inline: false
|
|
8016
8030
|
};
|
|
8017
8031
|
|
|
8018
8032
|
// src/tags/index.ts
|
|
@@ -8306,6 +8320,12 @@ function validator(node2, config) {
|
|
|
8306
8320
|
});
|
|
8307
8321
|
return errors;
|
|
8308
8322
|
}
|
|
8323
|
+
if (schema.inline != void 0 && node2.inline !== schema.inline)
|
|
8324
|
+
errors.push({
|
|
8325
|
+
id: "tag-placement-invalid",
|
|
8326
|
+
level: "critical",
|
|
8327
|
+
message: `'${node2.tag}' tag should be ${schema.inline ? "inline" : "block"}`
|
|
8328
|
+
});
|
|
8309
8329
|
if (schema.selfClosing && node2.children.length > 0)
|
|
8310
8330
|
errors.push({
|
|
8311
8331
|
id: "tag-selfclosing-has-children",
|
|
@@ -8351,12 +8371,6 @@ function validator(node2, config) {
|
|
|
8351
8371
|
continue;
|
|
8352
8372
|
}
|
|
8353
8373
|
value = value;
|
|
8354
|
-
if (key === "id" && value.match(/^[0-9]/))
|
|
8355
|
-
errors.push({
|
|
8356
|
-
id: "attribute-value-invalid",
|
|
8357
|
-
level: "error",
|
|
8358
|
-
message: "The id attribute must not start with a number"
|
|
8359
|
-
});
|
|
8360
8374
|
if (type) {
|
|
8361
8375
|
const valid = validateType(type, value, config);
|
|
8362
8376
|
if (valid === false) {
|