@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 CHANGED
@@ -52,6 +52,19 @@ 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
+ This is the minimal `tsconfig.json` in order to use Markdoc in your TypeScript project
57
+
58
+ ```json
59
+ {
60
+ "compilerOptions": {
61
+ "moduleResolution": "node",
62
+ "target": "esnext", // works with es2015 or greater
63
+ "esModuleInterop": true
64
+ }
65
+ }
66
+ ```
67
+
55
68
  ## Contributing
56
69
 
57
70
  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,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAGpE;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC/C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AK,EACL,IAAI,EACJ,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,GAAG,EACH,GAAG,EACH,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,MAAM,EACN,sBAAsB,GACvB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,MAAM,CAAC,KAAK,eAAS;IACrB,MAAM,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAQ;IACnB,MAAM,CAAC,SAAS;;;;;;;MAAa;IAC7B,MAAM,CAAC,gBAAgB,oEAAoB;IAC3C,MAAM,CAAC,SAAS;;;;MAAa;IAC7B,MAAM,CAAC,UAAU,oDAAc;IAC/B,MAAM,CAAC,GAAG;;;;;;;;;;;;;;;;;;;MAAO;IACjB,MAAM,CAAC,GAAG,aAAO;IACjB,MAAM,CAAC,SAAS,mBAAa;IAC7B,MAAM,CAAC,SAAS,mBAAa;IAC7B,MAAM,CAAC,WAAW,oCAAe;IACjC,MAAM,CAAC,SAAS,mBAAa;IAC7B,MAAM,CAAC,KAAK,eAAS;IACrB,MAAM,CAAC,SAAS,mBAAa;IAC7B,MAAM,CAAC,QAAQ,kBAAY;IAC3B,MAAM,CAAC,aAAa,uBAAiB;IACrC,MAAM,CAAC,MAAM,gBAAU;IACvB,MAAM,CAAC,sBAAsB,gCAA0B;IAEvD,MAAM;;;;;;;;;QAAC;gBACK,MAAM,EAAE,MAAM;IAI1B,KAAK,eAAS;IACd,OAAO,YAAa,WAAW,cAAc,CAAC,CAAC,CAAC,CAAC,YACjB;IAChC,SAAS,YAAa,WAAW,gBAAgB,CAAC,CAAC,CAAC,CAAC,0BACnB;IAClC,QAAQ,YAAa,WAAW,eAAe,CAAC,CAAC,CAAC,CAAC,qBAClB;CAClC"}
package/dist/index.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
@@ -6963,7 +6963,7 @@ var SEP = ", ";
6963
6963
  var NL = "\n";
6964
6964
  var OL = "1. ";
6965
6965
  var UL = "- ";
6966
- var MAX_TAG_HEAD_LENGTH = 80;
6966
+ var MAX_TAG_OPENING_WIDTH = 80;
6967
6967
  var max = (a, b) => Math.max(a, b);
6968
6968
  var increment = (o, n = 2) => ({
6969
6969
  ...o,
@@ -6994,7 +6994,7 @@ function formatScalar(v) {
6994
6994
  }
6995
6995
  function formatAnnotationValue(a) {
6996
6996
  if (a.name === "primary")
6997
- return a.value;
6997
+ return formatScalar(a.value);
6998
6998
  if (a.name === "id" && typeof a.value === "string")
6999
6999
  return "#" + a.value;
7000
7000
  if (a.type === "class")
@@ -7134,20 +7134,14 @@ function* formatNode(n, o = {}) {
7134
7134
  const open = OPEN + SPACE;
7135
7135
  const tag = [open + n.tag, ...formatAttributes(n)];
7136
7136
  const inlineTag = tag.join(SPACE);
7137
- if (inlineTag.length + open.length * 2 > MAX_TAG_HEAD_LENGTH) {
7138
- yield tag.join(NL + SPACE.repeat(open.length) + indent);
7139
- } else {
7140
- yield inlineTag;
7141
- }
7142
- yield SPACE + (n.children.length ? "" : "/") + CLOSE;
7137
+ const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
7138
+ yield (isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
7143
7139
  if (n.children.length) {
7144
7140
  yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
7145
7141
  if (!n.inline) {
7146
7142
  yield indent;
7147
7143
  }
7148
- yield OPEN + SPACE + "/";
7149
- yield n.tag;
7150
- yield SPACE + CLOSE;
7144
+ yield OPEN + SPACE + "/" + n.tag + SPACE + CLOSE;
7151
7145
  }
7152
7146
  if (!n.inline) {
7153
7147
  yield NL;
@@ -7206,16 +7200,26 @@ function* formatNode(n, o = {}) {
7206
7200
  case "table": {
7207
7201
  const table3 = [...formatChildren(n, increment(no))];
7208
7202
  if (o.parent && o.parent.type === "tag" && o.parent.tag === "table") {
7209
- for (const row of table3) {
7210
- yield NL;
7211
- for (const d of row) {
7212
- yield indent + UL + d.trim();
7213
- yield NL;
7214
- }
7215
- if (row !== table3[table3.length - 1]) {
7216
- yield indent + "---";
7203
+ for (let i = 0; i < table3.length; i++) {
7204
+ const row = table3[i];
7205
+ if (typeof row === "string") {
7206
+ if (row.trim().length) {
7207
+ yield NL;
7208
+ yield row;
7209
+ }
7210
+ } else {
7211
+ if (i !== 0) {
7212
+ yield NL;
7213
+ yield indent + "---";
7214
+ }
7215
+ for (let j = 0; j < row.length; j++) {
7216
+ const d = row[j];
7217
+ yield NL;
7218
+ yield indent + UL + d.trim();
7219
+ }
7217
7220
  }
7218
7221
  }
7222
+ yield NL;
7219
7223
  } else {
7220
7224
  yield NL;
7221
7225
  const [head, ...rows] = table3;
@@ -7298,7 +7302,7 @@ function format(v, options) {
7298
7302
  let doc = "";
7299
7303
  for (const s2 of formatValue(v, options))
7300
7304
  doc += s2;
7301
- return doc;
7305
+ return doc.trimStart();
7302
7306
  }
7303
7307
 
7304
7308
  // src/tags/conditional.ts
@@ -7464,6 +7468,7 @@ function handleAttrs(token, type) {
7464
7468
  }
7465
7469
  case "text":
7466
7470
  case "code":
7471
+ case "comment":
7467
7472
  return { content: (token.meta || {}).variable || token.content };
7468
7473
  case "fence": {
7469
7474
  const [language] = token.info.split(" ", 1);
@@ -7587,6 +7592,7 @@ var schema_exports = {};
7587
7592
  __export(schema_exports, {
7588
7593
  blockquote: () => blockquote,
7589
7594
  code: () => code,
7595
+ comment: () => comment,
7590
7596
  document: () => document,
7591
7597
  em: () => em,
7592
7598
  error: () => error,
@@ -7622,6 +7628,7 @@ var document = {
7622
7628
  "tag",
7623
7629
  "fence",
7624
7630
  "blockquote",
7631
+ "comment",
7625
7632
  "list",
7626
7633
  "hr"
7627
7634
  ],
@@ -7769,7 +7776,8 @@ var inline = {
7769
7776
  "link",
7770
7777
  "image",
7771
7778
  "hardbreak",
7772
- "softbreak"
7779
+ "softbreak",
7780
+ "comment"
7773
7781
  ]
7774
7782
  };
7775
7783
  var link = {
@@ -7802,10 +7810,15 @@ var hardbreak = {
7802
7810
  render: "br"
7803
7811
  };
7804
7812
  var softbreak = {
7805
- transform(_node, _config) {
7813
+ transform() {
7806
7814
  return " ";
7807
7815
  }
7808
7816
  };
7817
+ var comment = {
7818
+ attributes: {
7819
+ content: { type: String, required: true }
7820
+ }
7821
+ };
7809
7822
  var error = {};
7810
7823
  var node = {};
7811
7824
 
@@ -8117,6 +8130,45 @@ function plugin2(md) {
8117
8130
  md.block.ruler.before("hr", "frontmatter", block2);
8118
8131
  }
8119
8132
 
8133
+ // src/tokenizer/plugins/comments.ts
8134
+ var OPEN2 = "<!--";
8135
+ var CLOSE2 = "-->";
8136
+ function block3(state, startLine, endLine, silent) {
8137
+ const start = state.bMarks[startLine] + state.tShift[startLine];
8138
+ if (!state.src.startsWith(OPEN2, start))
8139
+ return false;
8140
+ const close = state.src.indexOf(CLOSE2, start);
8141
+ if (!close)
8142
+ return false;
8143
+ if (silent)
8144
+ return true;
8145
+ const content = state.src.slice(start + OPEN2.length, close);
8146
+ const lines = content.split("\n").length;
8147
+ const token = state.push("comment", "", 0);
8148
+ token.content = content.trim();
8149
+ token.map = [startLine, startLine + lines];
8150
+ state.line += lines;
8151
+ return true;
8152
+ }
8153
+ function inline3(state, silent) {
8154
+ if (!state.src.startsWith(OPEN2, state.pos))
8155
+ return false;
8156
+ const close = state.src.indexOf(CLOSE2, state.pos);
8157
+ if (!close)
8158
+ return false;
8159
+ if (silent)
8160
+ return true;
8161
+ const content = state.src.slice(state.pos + OPEN2.length, close);
8162
+ const token = state.push("comment", "", 0);
8163
+ token.content = content.trim();
8164
+ state.pos = close + CLOSE2.length;
8165
+ return true;
8166
+ }
8167
+ function plugin3(md) {
8168
+ md.block.ruler.before("table", "comment", block3, { alt: ["paragraph"] });
8169
+ md.inline.ruler.push("comment", inline3);
8170
+ }
8171
+
8120
8172
  // src/tokenizer/index.ts
8121
8173
  var Tokenizer = class {
8122
8174
  constructor(config = {}) {
@@ -8127,6 +8179,8 @@ var Tokenizer = class {
8127
8179
  "lheading",
8128
8180
  "code"
8129
8181
  ]);
8182
+ if (config.allowComments)
8183
+ this.parser.use(plugin3, "comments", {});
8130
8184
  }
8131
8185
  tokenize(content) {
8132
8186
  return this.parser.parse(content.toString(), {});
@@ -8218,7 +8272,7 @@ function validateFunction(fn, config) {
8218
8272
  });
8219
8273
  return errors;
8220
8274
  }
8221
- function validate(node2, config) {
8275
+ function validator(node2, config) {
8222
8276
  const schema = node2.findSchema(config);
8223
8277
  const errors = [...node2.errors || []];
8224
8278
  if (!schema) {
@@ -8239,8 +8293,6 @@ function validate(node2, config) {
8239
8293
  ...globalAttributes,
8240
8294
  ...schema.attributes
8241
8295
  };
8242
- if (schema.validate)
8243
- errors.push(...schema.validate(node2, config));
8244
8296
  for (let [key, value] of Object.entries(node2.attributes)) {
8245
8297
  const attrib = attributes[key];
8246
8298
  if (!attrib) {
@@ -8301,13 +8353,13 @@ function validate(node2, config) {
8301
8353
  errors.push({
8302
8354
  id: "attribute-value-invalid",
8303
8355
  level: errorLevel || "error",
8304
- message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}`
8356
+ message: `Attribute '${key}' must match one of ${JSON.stringify(matches)}. Got '${value}' instead.`
8305
8357
  });
8306
8358
  if (matches instanceof RegExp && !matches.test(value))
8307
8359
  errors.push({
8308
8360
  id: "attribute-value-invalid",
8309
8361
  level: errorLevel || "error",
8310
- message: `Attribute '${key}' must match ${matches}`
8362
+ message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
8311
8363
  });
8312
8364
  }
8313
8365
  for (const [key, { required }] of Object.entries(attributes))
@@ -8325,6 +8377,13 @@ function validate(node2, config) {
8325
8377
  message: `Can't nest '${type}' in '${node2.tag || node2.type}'`
8326
8378
  });
8327
8379
  }
8380
+ if (schema.validate) {
8381
+ const schemaErrors = schema.validate(node2, config);
8382
+ if (isPromise(schemaErrors)) {
8383
+ return schemaErrors.then((e) => errors.concat(e));
8384
+ }
8385
+ errors.push(...schemaErrors);
8386
+ }
8328
8387
  return errors;
8329
8388
  }
8330
8389
 
@@ -8364,16 +8423,20 @@ function transform2(nodes, options) {
8364
8423
  return content.flatMap((child) => child.transform(config));
8365
8424
  return content.transform(config);
8366
8425
  }
8367
- function validate2(content, options) {
8426
+ function validate(content, options) {
8368
8427
  const config = mergeConfig(options);
8369
- const output = [];
8370
- for (const node2 of [content, ...content.walk()]) {
8428
+ const output = [content, ...content.walk()].map((node2) => {
8371
8429
  const { type, lines, location } = node2;
8372
- const errors = validate(node2, config);
8373
- for (const error2 of errors)
8374
- output.push({ type, lines, location, error: error2 });
8430
+ const errors = validator(node2, config);
8431
+ if (isPromise(errors)) {
8432
+ return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
8433
+ }
8434
+ return errors.map((error2) => ({ type, lines, location, error: error2 }));
8435
+ });
8436
+ if (output.some(isPromise)) {
8437
+ return Promise.all(output).then((o) => o.flat());
8375
8438
  }
8376
- return output;
8439
+ return output.flat();
8377
8440
  }
8378
8441
  function createElement(name, attributes = {}, ...children) {
8379
8442
  return { name, attributes, children };
@@ -8383,7 +8446,7 @@ var Markdoc = class {
8383
8446
  this.parse = parse3;
8384
8447
  this.resolve = (content) => resolve2(content, this.config);
8385
8448
  this.transform = (content) => transform2(content, this.config);
8386
- this.validate = (content) => validate2(content, this.config);
8449
+ this.validate = (content) => validate(content, this.config);
8387
8450
  this.config = config;
8388
8451
  }
8389
8452
  };
@@ -8398,10 +8461,10 @@ Markdoc.Tag = Tag;
8398
8461
  Markdoc.Tokenizer = Tokenizer;
8399
8462
  Markdoc.parseTags = parseTags;
8400
8463
  Markdoc.transformer = transformer_default;
8401
- Markdoc.validator = validate;
8464
+ Markdoc.validator = validator;
8402
8465
  Markdoc.parse = parse3;
8403
8466
  Markdoc.transform = transform2;
8404
- Markdoc.validate = validate2;
8467
+ Markdoc.validate = validate;
8405
8468
  Markdoc.createElement = createElement;
8406
8469
  Markdoc.truthy = truthy;
8407
8470
  Markdoc.__EXPERIMENTAL__format = format;