@markdoc/markdoc 0.1.6 → 0.1.8
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 +13 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -45
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +108 -45
- package/dist/index.mjs.map +3 -3
- package/dist/src/formatter.d.ts +1 -0
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/schema.d.ts +8 -0
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/tokenizer/index.d.ts +1 -0
- package/dist/src/tokenizer/index.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/comments.d.ts +3 -0
- package/dist/src/tokenizer/plugins/comments.d.ts.map +1 -0
- package/dist/src/types.d.ts +4 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/validator.d.ts +1 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/index.ts +20 -7
- package/package.json +6 -4
- package/src/formatter.test.ts +74 -3
- package/src/formatter.ts +42 -24
- package/src/parser.test.ts +17 -1
- package/src/parser.ts +1 -0
- package/src/schema.ts +9 -1
- package/src/tokenizer/index.ts +7 -1
- package/src/tokenizer/plugins/comments.test.ts +94 -0
- package/src/tokenizer/plugins/comments.ts +51 -0
- package/src/types.ts +4 -3
- package/src/validator.test.ts +72 -15
- package/src/validator.ts +13 -5
package/dist/index.mjs
CHANGED
|
@@ -2798,7 +2798,7 @@ var require_normalize = __commonJS({
|
|
|
2798
2798
|
var require_block = __commonJS({
|
|
2799
2799
|
"node_modules/markdown-it/lib/rules_core/block.js"(exports, module) {
|
|
2800
2800
|
"use strict";
|
|
2801
|
-
module.exports = function
|
|
2801
|
+
module.exports = function block4(state) {
|
|
2802
2802
|
var token;
|
|
2803
2803
|
if (state.inlineMode) {
|
|
2804
2804
|
token = new state.Token("inline", "", 0);
|
|
@@ -2817,7 +2817,7 @@ var require_block = __commonJS({
|
|
|
2817
2817
|
var require_inline = __commonJS({
|
|
2818
2818
|
"node_modules/markdown-it/lib/rules_core/inline.js"(exports, module) {
|
|
2819
2819
|
"use strict";
|
|
2820
|
-
module.exports = function
|
|
2820
|
+
module.exports = function inline4(state) {
|
|
2821
2821
|
var tokens = state.tokens, tok, i, l;
|
|
2822
2822
|
for (i = 0, l = tokens.length; i < l; i++) {
|
|
2823
2823
|
tok = tokens[i];
|
|
@@ -4221,11 +4221,11 @@ var require_html_re = __commonJS({
|
|
|
4221
4221
|
var attribute = "(?:\\s+" + attr_name + "(?:\\s*=\\s*" + attr_value + ")?)";
|
|
4222
4222
|
var open_tag = "<[A-Za-z][A-Za-z0-9\\-]*" + attribute + "*\\s*\\/?>";
|
|
4223
4223
|
var close_tag = "<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>";
|
|
4224
|
-
var
|
|
4224
|
+
var comment2 = "<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->";
|
|
4225
4225
|
var processing = "<[?][\\s\\S]*?[?]>";
|
|
4226
4226
|
var declaration = "<![A-Z]+\\s+[^>]*>";
|
|
4227
4227
|
var cdata = "<!\\[CDATA\\[[\\s\\S]*?\\]\\]>";
|
|
4228
|
-
var HTML_TAG_RE = new RegExp("^(?:" + open_tag + "|" + close_tag + "|" +
|
|
4228
|
+
var HTML_TAG_RE = new RegExp("^(?:" + open_tag + "|" + close_tag + "|" + comment2 + "|" + processing + "|" + declaration + "|" + cdata + ")");
|
|
4229
4229
|
var HTML_OPEN_CLOSE_TAG_RE = new RegExp("^(?:" + open_tag + "|" + close_tag + ")");
|
|
4230
4230
|
module.exports.HTML_TAG_RE = HTML_TAG_RE;
|
|
4231
4231
|
module.exports.HTML_OPEN_CLOSE_TAG_RE = HTML_OPEN_CLOSE_TAG_RE;
|
|
@@ -6559,9 +6559,9 @@ var require_lib = __commonJS({
|
|
|
6559
6559
|
}
|
|
6560
6560
|
return this;
|
|
6561
6561
|
};
|
|
6562
|
-
MarkdownIt3.prototype.use = function(
|
|
6562
|
+
MarkdownIt3.prototype.use = function(plugin4) {
|
|
6563
6563
|
var args = [this].concat(Array.prototype.slice.call(arguments, 1));
|
|
6564
|
-
|
|
6564
|
+
plugin4.apply(plugin4, args);
|
|
6565
6565
|
return this;
|
|
6566
6566
|
};
|
|
6567
6567
|
MarkdownIt3.prototype.parse = function(src, env) {
|
|
@@ -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
|
|
@@ -7440,6 +7444,7 @@ function handleAttrs(token, type) {
|
|
|
7440
7444
|
}
|
|
7441
7445
|
case "text":
|
|
7442
7446
|
case "code":
|
|
7447
|
+
case "comment":
|
|
7443
7448
|
return { content: (token.meta || {}).variable || token.content };
|
|
7444
7449
|
case "fence": {
|
|
7445
7450
|
const [language] = token.info.split(" ", 1);
|
|
@@ -7563,6 +7568,7 @@ var schema_exports = {};
|
|
|
7563
7568
|
__export(schema_exports, {
|
|
7564
7569
|
blockquote: () => blockquote,
|
|
7565
7570
|
code: () => code,
|
|
7571
|
+
comment: () => comment,
|
|
7566
7572
|
document: () => document,
|
|
7567
7573
|
em: () => em,
|
|
7568
7574
|
error: () => error,
|
|
@@ -7598,6 +7604,7 @@ var document = {
|
|
|
7598
7604
|
"tag",
|
|
7599
7605
|
"fence",
|
|
7600
7606
|
"blockquote",
|
|
7607
|
+
"comment",
|
|
7601
7608
|
"list",
|
|
7602
7609
|
"hr"
|
|
7603
7610
|
],
|
|
@@ -7745,7 +7752,8 @@ var inline = {
|
|
|
7745
7752
|
"link",
|
|
7746
7753
|
"image",
|
|
7747
7754
|
"hardbreak",
|
|
7748
|
-
"softbreak"
|
|
7755
|
+
"softbreak",
|
|
7756
|
+
"comment"
|
|
7749
7757
|
]
|
|
7750
7758
|
};
|
|
7751
7759
|
var link = {
|
|
@@ -7778,10 +7786,15 @@ var hardbreak = {
|
|
|
7778
7786
|
render: "br"
|
|
7779
7787
|
};
|
|
7780
7788
|
var softbreak = {
|
|
7781
|
-
transform(
|
|
7789
|
+
transform() {
|
|
7782
7790
|
return " ";
|
|
7783
7791
|
}
|
|
7784
7792
|
};
|
|
7793
|
+
var comment = {
|
|
7794
|
+
attributes: {
|
|
7795
|
+
content: { type: String, required: true }
|
|
7796
|
+
}
|
|
7797
|
+
};
|
|
7785
7798
|
var error = {};
|
|
7786
7799
|
var node = {};
|
|
7787
7800
|
|
|
@@ -8093,6 +8106,45 @@ function plugin2(md) {
|
|
|
8093
8106
|
md.block.ruler.before("hr", "frontmatter", block2);
|
|
8094
8107
|
}
|
|
8095
8108
|
|
|
8109
|
+
// src/tokenizer/plugins/comments.ts
|
|
8110
|
+
var OPEN2 = "<!--";
|
|
8111
|
+
var CLOSE2 = "-->";
|
|
8112
|
+
function block3(state, startLine, endLine, silent) {
|
|
8113
|
+
const start = state.bMarks[startLine] + state.tShift[startLine];
|
|
8114
|
+
if (!state.src.startsWith(OPEN2, start))
|
|
8115
|
+
return false;
|
|
8116
|
+
const close = state.src.indexOf(CLOSE2, start);
|
|
8117
|
+
if (!close)
|
|
8118
|
+
return false;
|
|
8119
|
+
if (silent)
|
|
8120
|
+
return true;
|
|
8121
|
+
const content = state.src.slice(start + OPEN2.length, close);
|
|
8122
|
+
const lines = content.split("\n").length;
|
|
8123
|
+
const token = state.push("comment", "", 0);
|
|
8124
|
+
token.content = content.trim();
|
|
8125
|
+
token.map = [startLine, startLine + lines];
|
|
8126
|
+
state.line += lines;
|
|
8127
|
+
return true;
|
|
8128
|
+
}
|
|
8129
|
+
function inline3(state, silent) {
|
|
8130
|
+
if (!state.src.startsWith(OPEN2, state.pos))
|
|
8131
|
+
return false;
|
|
8132
|
+
const close = state.src.indexOf(CLOSE2, state.pos);
|
|
8133
|
+
if (!close)
|
|
8134
|
+
return false;
|
|
8135
|
+
if (silent)
|
|
8136
|
+
return true;
|
|
8137
|
+
const content = state.src.slice(state.pos + OPEN2.length, close);
|
|
8138
|
+
const token = state.push("comment", "", 0);
|
|
8139
|
+
token.content = content.trim();
|
|
8140
|
+
state.pos = close + CLOSE2.length;
|
|
8141
|
+
return true;
|
|
8142
|
+
}
|
|
8143
|
+
function plugin3(md) {
|
|
8144
|
+
md.block.ruler.before("table", "comment", block3, { alt: ["paragraph"] });
|
|
8145
|
+
md.inline.ruler.push("comment", inline3);
|
|
8146
|
+
}
|
|
8147
|
+
|
|
8096
8148
|
// src/tokenizer/index.ts
|
|
8097
8149
|
var Tokenizer = class {
|
|
8098
8150
|
constructor(config = {}) {
|
|
@@ -8103,6 +8155,8 @@ var Tokenizer = class {
|
|
|
8103
8155
|
"lheading",
|
|
8104
8156
|
"code"
|
|
8105
8157
|
]);
|
|
8158
|
+
if (config.allowComments)
|
|
8159
|
+
this.parser.use(plugin3, "comments", {});
|
|
8106
8160
|
}
|
|
8107
8161
|
tokenize(content) {
|
|
8108
8162
|
return this.parser.parse(content.toString(), {});
|
|
@@ -8194,7 +8248,7 @@ function validateFunction(fn, config) {
|
|
|
8194
8248
|
});
|
|
8195
8249
|
return errors;
|
|
8196
8250
|
}
|
|
8197
|
-
function
|
|
8251
|
+
function validator(node2, config) {
|
|
8198
8252
|
const schema = node2.findSchema(config);
|
|
8199
8253
|
const errors = [...node2.errors || []];
|
|
8200
8254
|
if (!schema) {
|
|
@@ -8215,8 +8269,6 @@ function validate(node2, config) {
|
|
|
8215
8269
|
...globalAttributes,
|
|
8216
8270
|
...schema.attributes
|
|
8217
8271
|
};
|
|
8218
|
-
if (schema.validate)
|
|
8219
|
-
errors.push(...schema.validate(node2, config));
|
|
8220
8272
|
for (let [key, value] of Object.entries(node2.attributes)) {
|
|
8221
8273
|
const attrib = attributes[key];
|
|
8222
8274
|
if (!attrib) {
|
|
@@ -8277,13 +8329,13 @@ function validate(node2, config) {
|
|
|
8277
8329
|
errors.push({
|
|
8278
8330
|
id: "attribute-value-invalid",
|
|
8279
8331
|
level: errorLevel || "error",
|
|
8280
|
-
message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}
|
|
8332
|
+
message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}. Got '${value}' instead.`
|
|
8281
8333
|
});
|
|
8282
8334
|
if (matches instanceof RegExp && !matches.test(value))
|
|
8283
8335
|
errors.push({
|
|
8284
8336
|
id: "attribute-value-invalid",
|
|
8285
8337
|
level: errorLevel || "error",
|
|
8286
|
-
message: `Attribute '${key}' must match ${matches}
|
|
8338
|
+
message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
|
|
8287
8339
|
});
|
|
8288
8340
|
}
|
|
8289
8341
|
for (const [key, { required }] of Object.entries(attributes))
|
|
@@ -8301,6 +8353,13 @@ function validate(node2, config) {
|
|
|
8301
8353
|
message: `Can't nest '${type}' in '${node2.tag || node2.type}'`
|
|
8302
8354
|
});
|
|
8303
8355
|
}
|
|
8356
|
+
if (schema.validate) {
|
|
8357
|
+
const schemaErrors = schema.validate(node2, config);
|
|
8358
|
+
if (isPromise(schemaErrors)) {
|
|
8359
|
+
return schemaErrors.then((e) => errors.concat(e));
|
|
8360
|
+
}
|
|
8361
|
+
errors.push(...schemaErrors);
|
|
8362
|
+
}
|
|
8304
8363
|
return errors;
|
|
8305
8364
|
}
|
|
8306
8365
|
|
|
@@ -8340,16 +8399,20 @@ function transform2(nodes, options) {
|
|
|
8340
8399
|
return content.flatMap((child) => child.transform(config));
|
|
8341
8400
|
return content.transform(config);
|
|
8342
8401
|
}
|
|
8343
|
-
function
|
|
8402
|
+
function validate(content, options) {
|
|
8344
8403
|
const config = mergeConfig(options);
|
|
8345
|
-
const output = []
|
|
8346
|
-
for (const node2 of [content, ...content.walk()]) {
|
|
8404
|
+
const output = [content, ...content.walk()].map((node2) => {
|
|
8347
8405
|
const { type, lines, location } = node2;
|
|
8348
|
-
const errors =
|
|
8349
|
-
|
|
8350
|
-
|
|
8406
|
+
const errors = validator(node2, config);
|
|
8407
|
+
if (isPromise(errors)) {
|
|
8408
|
+
return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
|
|
8409
|
+
}
|
|
8410
|
+
return errors.map((error2) => ({ type, lines, location, error: error2 }));
|
|
8411
|
+
});
|
|
8412
|
+
if (output.some(isPromise)) {
|
|
8413
|
+
return Promise.all(output).then((o) => o.flat());
|
|
8351
8414
|
}
|
|
8352
|
-
return output;
|
|
8415
|
+
return output.flat();
|
|
8353
8416
|
}
|
|
8354
8417
|
function createElement(name, attributes = {}, ...children) {
|
|
8355
8418
|
return { name, attributes, children };
|
|
@@ -8359,7 +8422,7 @@ var Markdoc = class {
|
|
|
8359
8422
|
this.parse = parse3;
|
|
8360
8423
|
this.resolve = (content) => resolve2(content, this.config);
|
|
8361
8424
|
this.transform = (content) => transform2(content, this.config);
|
|
8362
|
-
this.validate = (content) =>
|
|
8425
|
+
this.validate = (content) => validate(content, this.config);
|
|
8363
8426
|
this.config = config;
|
|
8364
8427
|
}
|
|
8365
8428
|
};
|
|
@@ -8374,10 +8437,10 @@ Markdoc.Tag = Tag;
|
|
|
8374
8437
|
Markdoc.Tokenizer = Tokenizer;
|
|
8375
8438
|
Markdoc.parseTags = parseTags;
|
|
8376
8439
|
Markdoc.transformer = transformer_default;
|
|
8377
|
-
Markdoc.validator =
|
|
8440
|
+
Markdoc.validator = validator;
|
|
8378
8441
|
Markdoc.parse = parse3;
|
|
8379
8442
|
Markdoc.transform = transform2;
|
|
8380
|
-
Markdoc.validate =
|
|
8443
|
+
Markdoc.validate = validate;
|
|
8381
8444
|
Markdoc.createElement = createElement;
|
|
8382
8445
|
Markdoc.truthy = truthy;
|
|
8383
8446
|
Markdoc.__EXPERIMENTAL__format = format;
|
|
@@ -8400,6 +8463,6 @@ export {
|
|
|
8400
8463
|
transformer_default as transformer,
|
|
8401
8464
|
transforms_default as transforms,
|
|
8402
8465
|
truthy,
|
|
8403
|
-
|
|
8404
|
-
|
|
8466
|
+
validate,
|
|
8467
|
+
validator
|
|
8405
8468
|
};
|