@markdoc/markdoc 0.1.7 → 0.1.9

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.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 block3(state) {
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 inline3(state) {
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 comment = "<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->";
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 + "|" + comment + "|" + processing + "|" + declaration + "|" + cdata + ")");
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(plugin3) {
6562
+ MarkdownIt3.prototype.use = function(plugin4) {
6563
6563
  var args = [this].concat(Array.prototype.slice.call(arguments, 1));
6564
- plugin3.apply(plugin3, args);
6564
+ plugin4.apply(plugin4, args);
6565
6565
  return this;
6566
6566
  };
6567
6567
  MarkdownIt3.prototype.parse = function(src, env) {
@@ -7007,7 +7007,10 @@ function* formatFunction(f) {
7007
7007
  function* trimStart(g) {
7008
7008
  let n;
7009
7009
  do {
7010
- n = g.next().value.trimStart();
7010
+ const { value, done } = g.next();
7011
+ if (done)
7012
+ return;
7013
+ n = value.trimStart();
7011
7014
  } while (!n.length);
7012
7015
  yield n;
7013
7016
  yield* g;
@@ -7096,7 +7099,7 @@ function* formatNode(n, o = {}) {
7096
7099
  yield* formatAnnotations(n);
7097
7100
  yield NL;
7098
7101
  yield indent;
7099
- yield* formatChildren(n, no);
7102
+ yield n.attributes.content;
7100
7103
  yield indent;
7101
7104
  yield "```";
7102
7105
  yield NL;
@@ -7444,6 +7447,7 @@ function handleAttrs(token, type) {
7444
7447
  }
7445
7448
  case "text":
7446
7449
  case "code":
7450
+ case "comment":
7447
7451
  return { content: (token.meta || {}).variable || token.content };
7448
7452
  case "fence": {
7449
7453
  const [language] = token.info.split(" ", 1);
@@ -7567,6 +7571,7 @@ var schema_exports = {};
7567
7571
  __export(schema_exports, {
7568
7572
  blockquote: () => blockquote,
7569
7573
  code: () => code,
7574
+ comment: () => comment,
7570
7575
  document: () => document,
7571
7576
  em: () => em,
7572
7577
  error: () => error,
@@ -7602,6 +7607,7 @@ var document = {
7602
7607
  "tag",
7603
7608
  "fence",
7604
7609
  "blockquote",
7610
+ "comment",
7605
7611
  "list",
7606
7612
  "hr"
7607
7613
  ],
@@ -7749,7 +7755,8 @@ var inline = {
7749
7755
  "link",
7750
7756
  "image",
7751
7757
  "hardbreak",
7752
- "softbreak"
7758
+ "softbreak",
7759
+ "comment"
7753
7760
  ]
7754
7761
  };
7755
7762
  var link = {
@@ -7786,6 +7793,11 @@ var softbreak = {
7786
7793
  return " ";
7787
7794
  }
7788
7795
  };
7796
+ var comment = {
7797
+ attributes: {
7798
+ content: { type: String, required: true }
7799
+ }
7800
+ };
7789
7801
  var error = {};
7790
7802
  var node = {};
7791
7803
 
@@ -8097,6 +8109,45 @@ function plugin2(md) {
8097
8109
  md.block.ruler.before("hr", "frontmatter", block2);
8098
8110
  }
8099
8111
 
8112
+ // src/tokenizer/plugins/comments.ts
8113
+ var OPEN2 = "<!--";
8114
+ var CLOSE2 = "-->";
8115
+ function block3(state, startLine, endLine, silent) {
8116
+ const start = state.bMarks[startLine] + state.tShift[startLine];
8117
+ if (!state.src.startsWith(OPEN2, start))
8118
+ return false;
8119
+ const close = state.src.indexOf(CLOSE2, start);
8120
+ if (!close)
8121
+ return false;
8122
+ if (silent)
8123
+ return true;
8124
+ const content = state.src.slice(start + OPEN2.length, close);
8125
+ const lines = content.split("\n").length;
8126
+ const token = state.push("comment", "", 0);
8127
+ token.content = content.trim();
8128
+ token.map = [startLine, startLine + lines];
8129
+ state.line += lines;
8130
+ return true;
8131
+ }
8132
+ function inline3(state, silent) {
8133
+ if (!state.src.startsWith(OPEN2, state.pos))
8134
+ return false;
8135
+ const close = state.src.indexOf(CLOSE2, state.pos);
8136
+ if (!close)
8137
+ return false;
8138
+ if (silent)
8139
+ return true;
8140
+ const content = state.src.slice(state.pos + OPEN2.length, close);
8141
+ const token = state.push("comment", "", 0);
8142
+ token.content = content.trim();
8143
+ state.pos = close + CLOSE2.length;
8144
+ return true;
8145
+ }
8146
+ function plugin3(md) {
8147
+ md.block.ruler.before("table", "comment", block3, { alt: ["paragraph"] });
8148
+ md.inline.ruler.push("comment", inline3);
8149
+ }
8150
+
8100
8151
  // src/tokenizer/index.ts
8101
8152
  var Tokenizer = class {
8102
8153
  constructor(config = {}) {
@@ -8107,6 +8158,8 @@ var Tokenizer = class {
8107
8158
  "lheading",
8108
8159
  "code"
8109
8160
  ]);
8161
+ if (config.allowComments)
8162
+ this.parser.use(plugin3, "comments", {});
8110
8163
  }
8111
8164
  tokenize(content) {
8112
8165
  return this.parser.parse(content.toString(), {});
@@ -8198,7 +8251,7 @@ function validateFunction(fn, config) {
8198
8251
  });
8199
8252
  return errors;
8200
8253
  }
8201
- function validate(node2, config) {
8254
+ function validator(node2, config) {
8202
8255
  const schema = node2.findSchema(config);
8203
8256
  const errors = [...node2.errors || []];
8204
8257
  if (!schema) {
@@ -8219,8 +8272,6 @@ function validate(node2, config) {
8219
8272
  ...globalAttributes,
8220
8273
  ...schema.attributes
8221
8274
  };
8222
- if (schema.validate)
8223
- errors.push(...schema.validate(node2, config));
8224
8275
  for (let [key, value] of Object.entries(node2.attributes)) {
8225
8276
  const attrib = attributes[key];
8226
8277
  if (!attrib) {
@@ -8305,6 +8356,13 @@ function validate(node2, config) {
8305
8356
  message: `Can't nest '${type}' in '${node2.tag || node2.type}'`
8306
8357
  });
8307
8358
  }
8359
+ if (schema.validate) {
8360
+ const schemaErrors = schema.validate(node2, config);
8361
+ if (isPromise(schemaErrors)) {
8362
+ return schemaErrors.then((e) => errors.concat(e));
8363
+ }
8364
+ errors.push(...schemaErrors);
8365
+ }
8308
8366
  return errors;
8309
8367
  }
8310
8368
 
@@ -8344,16 +8402,20 @@ function transform2(nodes, options) {
8344
8402
  return content.flatMap((child) => child.transform(config));
8345
8403
  return content.transform(config);
8346
8404
  }
8347
- function validate2(content, options) {
8405
+ function validate(content, options) {
8348
8406
  const config = mergeConfig(options);
8349
- const output = [];
8350
- for (const node2 of [content, ...content.walk()]) {
8407
+ const output = [content, ...content.walk()].map((node2) => {
8351
8408
  const { type, lines, location } = node2;
8352
- const errors = validate(node2, config);
8353
- for (const error2 of errors)
8354
- output.push({ type, lines, location, error: error2 });
8409
+ const errors = validator(node2, config);
8410
+ if (isPromise(errors)) {
8411
+ return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
8412
+ }
8413
+ return errors.map((error2) => ({ type, lines, location, error: error2 }));
8414
+ });
8415
+ if (output.some(isPromise)) {
8416
+ return Promise.all(output).then((o) => o.flat());
8355
8417
  }
8356
- return output;
8418
+ return output.flat();
8357
8419
  }
8358
8420
  function createElement(name, attributes = {}, ...children) {
8359
8421
  return { name, attributes, children };
@@ -8363,7 +8425,7 @@ var Markdoc = class {
8363
8425
  this.parse = parse3;
8364
8426
  this.resolve = (content) => resolve2(content, this.config);
8365
8427
  this.transform = (content) => transform2(content, this.config);
8366
- this.validate = (content) => validate2(content, this.config);
8428
+ this.validate = (content) => validate(content, this.config);
8367
8429
  this.config = config;
8368
8430
  }
8369
8431
  };
@@ -8378,10 +8440,10 @@ Markdoc.Tag = Tag;
8378
8440
  Markdoc.Tokenizer = Tokenizer;
8379
8441
  Markdoc.parseTags = parseTags;
8380
8442
  Markdoc.transformer = transformer_default;
8381
- Markdoc.validator = validate;
8443
+ Markdoc.validator = validator;
8382
8444
  Markdoc.parse = parse3;
8383
8445
  Markdoc.transform = transform2;
8384
- Markdoc.validate = validate2;
8446
+ Markdoc.validate = validate;
8385
8447
  Markdoc.createElement = createElement;
8386
8448
  Markdoc.truthy = truthy;
8387
8449
  Markdoc.__EXPERIMENTAL__format = format;
@@ -8404,6 +8466,6 @@ export {
8404
8466
  transformer_default as transformer,
8405
8467
  transforms_default as transforms,
8406
8468
  truthy,
8407
- validate2 as validate,
8408
- validate as validator
8469
+ validate,
8470
+ validator
8409
8471
  };