@markdoc/markdoc 0.1.3 → 0.1.4

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
@@ -6912,7 +6912,10 @@ var Tokenizer = class {
6912
6912
  this.parser = new import_lib.default(config);
6913
6913
  this.parser.use(plugin, "annotations", {});
6914
6914
  this.parser.use(plugin2, "frontmatter", {});
6915
- this.parser.disable("lheading");
6915
+ this.parser.disable([
6916
+ "lheading",
6917
+ "code"
6918
+ ]);
6916
6919
  }
6917
6920
  tokenize(content) {
6918
6921
  return this.parser.parse(content.toString(), {});
@@ -6954,6 +6957,9 @@ var Class = class {
6954
6957
  };
6955
6958
 
6956
6959
  // src/transformer.ts
6960
+ function isPromise(a) {
6961
+ return a && typeof a === "object" && typeof a.then === "function";
6962
+ }
6957
6963
  var globalAttributes = {
6958
6964
  class: { type: Class, render: true },
6959
6965
  id: { type: String, render: true }
@@ -6985,7 +6991,11 @@ var transformer_default = {
6985
6991
  return output;
6986
6992
  },
6987
6993
  children(node, config = {}) {
6988
- return node.children.flatMap((child) => this.node(child, config));
6994
+ const children = node.children.flatMap((child) => this.node(child, config));
6995
+ if (children.some(isPromise)) {
6996
+ return Promise.all(children);
6997
+ }
6998
+ return children;
6989
6999
  },
6990
7000
  node(node, config = {}) {
6991
7001
  const schema = this.findSchema(node, config) ?? {};
@@ -6995,6 +7005,9 @@ var transformer_default = {
6995
7005
  if (!schema || !schema.render)
6996
7006
  return children;
6997
7007
  const attributes = this.attributes(node, config);
7008
+ if (isPromise(attributes) || isPromise(children)) {
7009
+ return Promise.all([attributes, children]).then((values) => new Tag(schema.render, ...values));
7010
+ }
6998
7011
  return new Tag(schema.render, attributes, children);
6999
7012
  }
7000
7013
  };
@@ -7010,6 +7023,7 @@ var Node = class {
7010
7023
  this.children = children;
7011
7024
  this.type = type;
7012
7025
  this.tag = tag;
7026
+ this.annotations = [];
7013
7027
  }
7014
7028
  *walk() {
7015
7029
  for (const child of this.children) {
@@ -7116,7 +7130,9 @@ var mappings = {
7116
7130
  variable: "text"
7117
7131
  };
7118
7132
  function annotate(node, attributes) {
7119
- for (const { name, value, type } of attributes)
7133
+ for (const attribute of attributes) {
7134
+ node.annotations.push(attribute);
7135
+ const { name, value, type } = attribute;
7120
7136
  if (type === "attribute")
7121
7137
  node.attributes[name] = value;
7122
7138
  else if (type === "class")
@@ -7124,6 +7140,7 @@ function annotate(node, attributes) {
7124
7140
  node.attributes.class[name] = value;
7125
7141
  else
7126
7142
  node.attributes.class = { [name]: value };
7143
+ }
7127
7144
  }
7128
7145
  function handleAttrs(token, type) {
7129
7146
  switch (type) {
@@ -7523,10 +7540,25 @@ var tagElse = {
7523
7540
  };
7524
7541
 
7525
7542
  // src/tags/partial.ts
7543
+ var PartialFile = class {
7544
+ validate(file, config) {
7545
+ const { partials = {} } = config;
7546
+ const partial2 = partials[file];
7547
+ if (!partial2)
7548
+ return [
7549
+ {
7550
+ id: "attribute-value-invalid",
7551
+ level: "error",
7552
+ message: `Partial \`${file}\` not found. The 'file' attribute must be set in \`config.partials\``
7553
+ }
7554
+ ];
7555
+ return [];
7556
+ }
7557
+ };
7526
7558
  var partial = {
7527
7559
  selfClosing: true,
7528
7560
  attributes: {
7529
- file: { type: String, render: false, required: true },
7561
+ file: { type: PartialFile, render: false, required: true },
7530
7562
  variables: { type: Object, render: false }
7531
7563
  },
7532
7564
  transform(node, config) {
@@ -7950,31 +7982,40 @@ function validate2(content, options) {
7950
7982
  function createElement(name, attributes = {}, ...children) {
7951
7983
  return { name, attributes, children };
7952
7984
  }
7953
- var markdoc_default = {
7954
- nodes: schema_exports,
7955
- tags: tags_default,
7956
- functions: functions_default,
7957
- renderers: renderers_default,
7958
- transforms: transforms_default,
7959
- Ast: ast_default,
7960
- Tag,
7961
- Tokenizer,
7962
- parseTags,
7963
- transformer: transformer_default,
7964
- validator: validate,
7965
- parse: parse3,
7966
- transform: transform2,
7967
- validate: validate2,
7968
- createElement,
7969
- truthy
7985
+ var Markdoc = class {
7986
+ constructor(config) {
7987
+ this.parse = parse3;
7988
+ this.resolve = (content) => resolve2(content, this.config);
7989
+ this.transform = (content) => transform2(content, this.config);
7990
+ this.validate = (content) => validate2(content, this.config);
7991
+ this.config = config;
7992
+ }
7970
7993
  };
7994
+ Markdoc.nodes = schema_exports;
7995
+ Markdoc.tags = tags_default;
7996
+ Markdoc.functions = functions_default;
7997
+ Markdoc.globalAttributes = globalAttributes;
7998
+ Markdoc.renderers = renderers_default;
7999
+ Markdoc.transforms = transforms_default;
8000
+ Markdoc.Ast = ast_default;
8001
+ Markdoc.Tag = Tag;
8002
+ Markdoc.Tokenizer = Tokenizer;
8003
+ Markdoc.parseTags = parseTags;
8004
+ Markdoc.transformer = transformer_default;
8005
+ Markdoc.validator = validate;
8006
+ Markdoc.parse = parse3;
8007
+ Markdoc.transform = transform2;
8008
+ Markdoc.validate = validate2;
8009
+ Markdoc.createElement = createElement;
8010
+ Markdoc.truthy = truthy;
7971
8011
  export {
7972
8012
  ast_default as Ast,
7973
8013
  Tag,
7974
8014
  Tokenizer,
7975
8015
  createElement,
7976
- markdoc_default as default,
8016
+ Markdoc as default,
7977
8017
  functions_default as functions,
8018
+ globalAttributes,
7978
8019
  schema_exports as nodes,
7979
8020
  parse3 as parse,
7980
8021
  parseTags,