@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/README.md CHANGED
@@ -52,6 +52,26 @@ return Markdoc.renderers.react(content, React);
52
52
 
53
53
  Check out [our docs](https://markdoc.dev/docs) for more guidance on how to use Markdoc.
54
54
 
55
+ ### TypeScript
56
+
57
+ When using TypeScript, install Markdoc with:
58
+
59
+ ```sh
60
+ npm install @markdoc/markdoc @types/react @types/markdown-it
61
+ ```
62
+
63
+ Additionally, this is the minimal `tsconfig.json` required to use Markdoc in your TypeScript project:
64
+
65
+ ```json
66
+ {
67
+ "compilerOptions": {
68
+ "moduleResolution": "node",
69
+ "target": "esnext", // works with es2015 or greater
70
+ "esModuleInterop": true
71
+ }
72
+ }
73
+ ```
74
+
55
75
  ## Contributing
56
76
 
57
77
  Contributions and feedback are welcome and encouraged. Check out our [contributing guidelines](.github/CONTRIBUTING.md) on how to do so.
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export declare function resolve<C extends Config = Config>(content: Node, config
20
20
  export declare function resolve<C extends Config = Config>(content: Node[], config: C): Node[];
21
21
  export declare function transform<C extends Config = Config>(node: Node, config?: C): RenderableTreeNode;
22
22
  export declare function transform<C extends Config = Config>(nodes: Node[], config?: C): RenderableTreeNode[];
23
- export declare function validate<C extends Config = Config>(content: Node, options?: C): ValidateError[];
23
+ export declare function validate<C extends Config = Config>(node: Node, options?: C): ValidateError[];
24
24
  export declare function createElement(name: string | {
25
25
  key?: string | number;
26
26
  }, attributes?: {}, ...children: any[]): {
@@ -94,7 +94,7 @@ export default class Markdoc {
94
94
  fromJSON: (text: string) => Node | Node[];
95
95
  isAst(value?: any): value is import("./src/types").AstType;
96
96
  isFunction(value?: any): value is import("./src/ast/function").default;
97
- isVariable(value?: any): value is import("./src/types").Variable;
97
+ isVariable(value?: any): value is import("./src/ast/variable").default;
98
98
  getAstValues(value: any): Generator<import("./src/types").AstType, void, unknown>;
99
99
  resolve(value: any, config?: Readonly<Partial<{
100
100
  nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
@@ -108,7 +108,7 @@ export default class Markdoc {
108
108
  }>>): any;
109
109
  Function: typeof import("./src/ast/function").default;
110
110
  Node: typeof Node;
111
- Variable: typeof import("./src/types").Variable;
111
+ Variable: typeof import("./src/ast/variable").default;
112
112
  };
113
113
  static Tag: typeof Tag;
114
114
  static Tokenizer: typeof Tokenizer;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,sBAAsB,MAAM,iBAAiB,CAAC;AACrD,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,WAAW,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,cAAc,aAAa,CAAC;AAsB5B,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE,IAA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.js 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, module2) {
2800
2800
  "use strict";
2801
- module2.exports = function block3(state) {
2801
+ module2.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, module2) {
2819
2819
  "use strict";
2820
- module2.exports = function inline3(state) {
2820
+ module2.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
  module2.exports.HTML_TAG_RE = HTML_TAG_RE;
4231
4231
  module2.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) {
@@ -6618,8 +6618,8 @@ __export(exports, {
6618
6618
  transformer: () => transformer_default,
6619
6619
  transforms: () => transforms_default,
6620
6620
  truthy: () => truthy,
6621
- validate: () => validate2,
6622
- validator: () => validate
6621
+ validate: () => validate,
6622
+ validator: () => validator
6623
6623
  });
6624
6624
 
6625
6625
  // src/ast/base.ts
@@ -7031,7 +7031,10 @@ function* formatFunction(f) {
7031
7031
  function* trimStart(g) {
7032
7032
  let n;
7033
7033
  do {
7034
- n = g.next().value.trimStart();
7034
+ const { value, done } = g.next();
7035
+ if (done)
7036
+ return;
7037
+ n = value.trimStart();
7035
7038
  } while (!n.length);
7036
7039
  yield n;
7037
7040
  yield* g;
@@ -7120,7 +7123,7 @@ function* formatNode(n, o = {}) {
7120
7123
  yield* formatAnnotations(n);
7121
7124
  yield NL;
7122
7125
  yield indent;
7123
- yield* formatChildren(n, no);
7126
+ yield n.attributes.content;
7124
7127
  yield indent;
7125
7128
  yield "```";
7126
7129
  yield NL;
@@ -7468,6 +7471,7 @@ function handleAttrs(token, type) {
7468
7471
  }
7469
7472
  case "text":
7470
7473
  case "code":
7474
+ case "comment":
7471
7475
  return { content: (token.meta || {}).variable || token.content };
7472
7476
  case "fence": {
7473
7477
  const [language] = token.info.split(" ", 1);
@@ -7591,6 +7595,7 @@ var schema_exports = {};
7591
7595
  __export(schema_exports, {
7592
7596
  blockquote: () => blockquote,
7593
7597
  code: () => code,
7598
+ comment: () => comment,
7594
7599
  document: () => document,
7595
7600
  em: () => em,
7596
7601
  error: () => error,
@@ -7626,6 +7631,7 @@ var document = {
7626
7631
  "tag",
7627
7632
  "fence",
7628
7633
  "blockquote",
7634
+ "comment",
7629
7635
  "list",
7630
7636
  "hr"
7631
7637
  ],
@@ -7773,7 +7779,8 @@ var inline = {
7773
7779
  "link",
7774
7780
  "image",
7775
7781
  "hardbreak",
7776
- "softbreak"
7782
+ "softbreak",
7783
+ "comment"
7777
7784
  ]
7778
7785
  };
7779
7786
  var link = {
@@ -7810,6 +7817,11 @@ var softbreak = {
7810
7817
  return " ";
7811
7818
  }
7812
7819
  };
7820
+ var comment = {
7821
+ attributes: {
7822
+ content: { type: String, required: true }
7823
+ }
7824
+ };
7813
7825
  var error = {};
7814
7826
  var node = {};
7815
7827
 
@@ -8121,6 +8133,45 @@ function plugin2(md) {
8121
8133
  md.block.ruler.before("hr", "frontmatter", block2);
8122
8134
  }
8123
8135
 
8136
+ // src/tokenizer/plugins/comments.ts
8137
+ var OPEN2 = "<!--";
8138
+ var CLOSE2 = "-->";
8139
+ function block3(state, startLine, endLine, silent) {
8140
+ const start = state.bMarks[startLine] + state.tShift[startLine];
8141
+ if (!state.src.startsWith(OPEN2, start))
8142
+ return false;
8143
+ const close = state.src.indexOf(CLOSE2, start);
8144
+ if (!close)
8145
+ return false;
8146
+ if (silent)
8147
+ return true;
8148
+ const content = state.src.slice(start + OPEN2.length, close);
8149
+ const lines = content.split("\n").length;
8150
+ const token = state.push("comment", "", 0);
8151
+ token.content = content.trim();
8152
+ token.map = [startLine, startLine + lines];
8153
+ state.line += lines;
8154
+ return true;
8155
+ }
8156
+ function inline3(state, silent) {
8157
+ if (!state.src.startsWith(OPEN2, state.pos))
8158
+ return false;
8159
+ const close = state.src.indexOf(CLOSE2, state.pos);
8160
+ if (!close)
8161
+ return false;
8162
+ if (silent)
8163
+ return true;
8164
+ const content = state.src.slice(state.pos + OPEN2.length, close);
8165
+ const token = state.push("comment", "", 0);
8166
+ token.content = content.trim();
8167
+ state.pos = close + CLOSE2.length;
8168
+ return true;
8169
+ }
8170
+ function plugin3(md) {
8171
+ md.block.ruler.before("table", "comment", block3, { alt: ["paragraph"] });
8172
+ md.inline.ruler.push("comment", inline3);
8173
+ }
8174
+
8124
8175
  // src/tokenizer/index.ts
8125
8176
  var Tokenizer = class {
8126
8177
  constructor(config = {}) {
@@ -8131,6 +8182,8 @@ var Tokenizer = class {
8131
8182
  "lheading",
8132
8183
  "code"
8133
8184
  ]);
8185
+ if (config.allowComments)
8186
+ this.parser.use(plugin3, "comments", {});
8134
8187
  }
8135
8188
  tokenize(content) {
8136
8189
  return this.parser.parse(content.toString(), {});
@@ -8222,7 +8275,7 @@ function validateFunction(fn, config) {
8222
8275
  });
8223
8276
  return errors;
8224
8277
  }
8225
- function validate(node2, config) {
8278
+ function validator(node2, config) {
8226
8279
  const schema = node2.findSchema(config);
8227
8280
  const errors = [...node2.errors || []];
8228
8281
  if (!schema) {
@@ -8243,8 +8296,6 @@ function validate(node2, config) {
8243
8296
  ...globalAttributes,
8244
8297
  ...schema.attributes
8245
8298
  };
8246
- if (schema.validate)
8247
- errors.push(...schema.validate(node2, config));
8248
8299
  for (let [key, value] of Object.entries(node2.attributes)) {
8249
8300
  const attrib = attributes[key];
8250
8301
  if (!attrib) {
@@ -8329,6 +8380,13 @@ function validate(node2, config) {
8329
8380
  message: `Can't nest '${type}' in '${node2.tag || node2.type}'`
8330
8381
  });
8331
8382
  }
8383
+ if (schema.validate) {
8384
+ const schemaErrors = schema.validate(node2, config);
8385
+ if (isPromise(schemaErrors)) {
8386
+ return schemaErrors.then((e) => errors.concat(e));
8387
+ }
8388
+ errors.push(...schemaErrors);
8389
+ }
8332
8390
  return errors;
8333
8391
  }
8334
8392
 
@@ -8368,16 +8426,20 @@ function transform2(nodes, options) {
8368
8426
  return content.flatMap((child) => child.transform(config));
8369
8427
  return content.transform(config);
8370
8428
  }
8371
- function validate2(content, options) {
8429
+ function validate(content, options) {
8372
8430
  const config = mergeConfig(options);
8373
- const output = [];
8374
- for (const node2 of [content, ...content.walk()]) {
8431
+ const output = [content, ...content.walk()].map((node2) => {
8375
8432
  const { type, lines, location } = node2;
8376
- const errors = validate(node2, config);
8377
- for (const error2 of errors)
8378
- output.push({ type, lines, location, error: error2 });
8433
+ const errors = validator(node2, config);
8434
+ if (isPromise(errors)) {
8435
+ return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
8436
+ }
8437
+ return errors.map((error2) => ({ type, lines, location, error: error2 }));
8438
+ });
8439
+ if (output.some(isPromise)) {
8440
+ return Promise.all(output).then((o) => o.flat());
8379
8441
  }
8380
- return output;
8442
+ return output.flat();
8381
8443
  }
8382
8444
  function createElement(name, attributes = {}, ...children) {
8383
8445
  return { name, attributes, children };
@@ -8387,7 +8449,7 @@ var Markdoc = class {
8387
8449
  this.parse = parse3;
8388
8450
  this.resolve = (content) => resolve2(content, this.config);
8389
8451
  this.transform = (content) => transform2(content, this.config);
8390
- this.validate = (content) => validate2(content, this.config);
8452
+ this.validate = (content) => validate(content, this.config);
8391
8453
  this.config = config;
8392
8454
  }
8393
8455
  };
@@ -8402,10 +8464,10 @@ Markdoc.Tag = Tag;
8402
8464
  Markdoc.Tokenizer = Tokenizer;
8403
8465
  Markdoc.parseTags = parseTags;
8404
8466
  Markdoc.transformer = transformer_default;
8405
- Markdoc.validator = validate;
8467
+ Markdoc.validator = validator;
8406
8468
  Markdoc.parse = parse3;
8407
8469
  Markdoc.transform = transform2;
8408
- Markdoc.validate = validate2;
8470
+ Markdoc.validate = validate;
8409
8471
  Markdoc.createElement = createElement;
8410
8472
  Markdoc.truthy = truthy;
8411
8473
  Markdoc.__EXPERIMENTAL__format = format;