@markdoc/markdoc 0.1.7 → 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 +81 -22
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +81 -22
- package/dist/index.mjs.map +3 -3
- 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/parser.test.ts +17 -1
- package/src/parser.ts +1 -0
- package/src/schema.ts +8 -0
- 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 +30 -1
- package/src/validator.ts +11 -3
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) {
|
|
@@ -7444,6 +7444,7 @@ function handleAttrs(token, type) {
|
|
|
7444
7444
|
}
|
|
7445
7445
|
case "text":
|
|
7446
7446
|
case "code":
|
|
7447
|
+
case "comment":
|
|
7447
7448
|
return { content: (token.meta || {}).variable || token.content };
|
|
7448
7449
|
case "fence": {
|
|
7449
7450
|
const [language] = token.info.split(" ", 1);
|
|
@@ -7567,6 +7568,7 @@ var schema_exports = {};
|
|
|
7567
7568
|
__export(schema_exports, {
|
|
7568
7569
|
blockquote: () => blockquote,
|
|
7569
7570
|
code: () => code,
|
|
7571
|
+
comment: () => comment,
|
|
7570
7572
|
document: () => document,
|
|
7571
7573
|
em: () => em,
|
|
7572
7574
|
error: () => error,
|
|
@@ -7602,6 +7604,7 @@ var document = {
|
|
|
7602
7604
|
"tag",
|
|
7603
7605
|
"fence",
|
|
7604
7606
|
"blockquote",
|
|
7607
|
+
"comment",
|
|
7605
7608
|
"list",
|
|
7606
7609
|
"hr"
|
|
7607
7610
|
],
|
|
@@ -7749,7 +7752,8 @@ var inline = {
|
|
|
7749
7752
|
"link",
|
|
7750
7753
|
"image",
|
|
7751
7754
|
"hardbreak",
|
|
7752
|
-
"softbreak"
|
|
7755
|
+
"softbreak",
|
|
7756
|
+
"comment"
|
|
7753
7757
|
]
|
|
7754
7758
|
};
|
|
7755
7759
|
var link = {
|
|
@@ -7786,6 +7790,11 @@ var softbreak = {
|
|
|
7786
7790
|
return " ";
|
|
7787
7791
|
}
|
|
7788
7792
|
};
|
|
7793
|
+
var comment = {
|
|
7794
|
+
attributes: {
|
|
7795
|
+
content: { type: String, required: true }
|
|
7796
|
+
}
|
|
7797
|
+
};
|
|
7789
7798
|
var error = {};
|
|
7790
7799
|
var node = {};
|
|
7791
7800
|
|
|
@@ -8097,6 +8106,45 @@ function plugin2(md) {
|
|
|
8097
8106
|
md.block.ruler.before("hr", "frontmatter", block2);
|
|
8098
8107
|
}
|
|
8099
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
|
+
|
|
8100
8148
|
// src/tokenizer/index.ts
|
|
8101
8149
|
var Tokenizer = class {
|
|
8102
8150
|
constructor(config = {}) {
|
|
@@ -8107,6 +8155,8 @@ var Tokenizer = class {
|
|
|
8107
8155
|
"lheading",
|
|
8108
8156
|
"code"
|
|
8109
8157
|
]);
|
|
8158
|
+
if (config.allowComments)
|
|
8159
|
+
this.parser.use(plugin3, "comments", {});
|
|
8110
8160
|
}
|
|
8111
8161
|
tokenize(content) {
|
|
8112
8162
|
return this.parser.parse(content.toString(), {});
|
|
@@ -8198,7 +8248,7 @@ function validateFunction(fn, config) {
|
|
|
8198
8248
|
});
|
|
8199
8249
|
return errors;
|
|
8200
8250
|
}
|
|
8201
|
-
function
|
|
8251
|
+
function validator(node2, config) {
|
|
8202
8252
|
const schema = node2.findSchema(config);
|
|
8203
8253
|
const errors = [...node2.errors || []];
|
|
8204
8254
|
if (!schema) {
|
|
@@ -8219,8 +8269,6 @@ function validate(node2, config) {
|
|
|
8219
8269
|
...globalAttributes,
|
|
8220
8270
|
...schema.attributes
|
|
8221
8271
|
};
|
|
8222
|
-
if (schema.validate)
|
|
8223
|
-
errors.push(...schema.validate(node2, config));
|
|
8224
8272
|
for (let [key, value] of Object.entries(node2.attributes)) {
|
|
8225
8273
|
const attrib = attributes[key];
|
|
8226
8274
|
if (!attrib) {
|
|
@@ -8305,6 +8353,13 @@ function validate(node2, config) {
|
|
|
8305
8353
|
message: `Can't nest '${type}' in '${node2.tag || node2.type}'`
|
|
8306
8354
|
});
|
|
8307
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
|
+
}
|
|
8308
8363
|
return errors;
|
|
8309
8364
|
}
|
|
8310
8365
|
|
|
@@ -8344,16 +8399,20 @@ function transform2(nodes, options) {
|
|
|
8344
8399
|
return content.flatMap((child) => child.transform(config));
|
|
8345
8400
|
return content.transform(config);
|
|
8346
8401
|
}
|
|
8347
|
-
function
|
|
8402
|
+
function validate(content, options) {
|
|
8348
8403
|
const config = mergeConfig(options);
|
|
8349
|
-
const output = []
|
|
8350
|
-
for (const node2 of [content, ...content.walk()]) {
|
|
8404
|
+
const output = [content, ...content.walk()].map((node2) => {
|
|
8351
8405
|
const { type, lines, location } = node2;
|
|
8352
|
-
const errors =
|
|
8353
|
-
|
|
8354
|
-
|
|
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());
|
|
8355
8414
|
}
|
|
8356
|
-
return output;
|
|
8415
|
+
return output.flat();
|
|
8357
8416
|
}
|
|
8358
8417
|
function createElement(name, attributes = {}, ...children) {
|
|
8359
8418
|
return { name, attributes, children };
|
|
@@ -8363,7 +8422,7 @@ var Markdoc = class {
|
|
|
8363
8422
|
this.parse = parse3;
|
|
8364
8423
|
this.resolve = (content) => resolve2(content, this.config);
|
|
8365
8424
|
this.transform = (content) => transform2(content, this.config);
|
|
8366
|
-
this.validate = (content) =>
|
|
8425
|
+
this.validate = (content) => validate(content, this.config);
|
|
8367
8426
|
this.config = config;
|
|
8368
8427
|
}
|
|
8369
8428
|
};
|
|
@@ -8378,10 +8437,10 @@ Markdoc.Tag = Tag;
|
|
|
8378
8437
|
Markdoc.Tokenizer = Tokenizer;
|
|
8379
8438
|
Markdoc.parseTags = parseTags;
|
|
8380
8439
|
Markdoc.transformer = transformer_default;
|
|
8381
|
-
Markdoc.validator =
|
|
8440
|
+
Markdoc.validator = validator;
|
|
8382
8441
|
Markdoc.parse = parse3;
|
|
8383
8442
|
Markdoc.transform = transform2;
|
|
8384
|
-
Markdoc.validate =
|
|
8443
|
+
Markdoc.validate = validate;
|
|
8385
8444
|
Markdoc.createElement = createElement;
|
|
8386
8445
|
Markdoc.truthy = truthy;
|
|
8387
8446
|
Markdoc.__EXPERIMENTAL__format = format;
|
|
@@ -8404,6 +8463,6 @@ export {
|
|
|
8404
8463
|
transformer_default as transformer,
|
|
8405
8464
|
transforms_default as transforms,
|
|
8406
8465
|
truthy,
|
|
8407
|
-
|
|
8408
|
-
|
|
8466
|
+
validate,
|
|
8467
|
+
validator
|
|
8409
8468
|
};
|