@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/README.md CHANGED
@@ -50,7 +50,7 @@ const content = Markdoc.transform(ast);
50
50
  return Markdoc.renderers.react(content, React);
51
51
  ```
52
52
 
53
- Check out [our docs](https://markdoc.io/docs) for more guidance on how to use Markdoc.
53
+ Check out [our docs](https://markdoc.dev/docs) for more guidance on how to use Markdoc.
54
54
 
55
55
  ## Contributing
56
56
 
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import tags from './src/tags/index';
7
7
  import { truthy } from './src/tags/conditional';
8
8
  import functions from './src/functions/index';
9
9
  import renderers from './src/renderers/index';
10
- import transformer from './src/transformer';
10
+ import transformer, { globalAttributes } from './src/transformer';
11
11
  import validator from './src/validator';
12
12
  import { parseTags } from './src/utils';
13
13
  import transforms from './src/transforms/index';
@@ -29,9 +29,10 @@ export declare function createElement(name: string | {
29
29
  attributes: {};
30
30
  children: any[];
31
31
  };
32
- declare const _default: {
33
- nodes: typeof nodes;
34
- tags: {
32
+ export { nodes, tags, functions, globalAttributes, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, truthy, };
33
+ export default class Markdoc {
34
+ static nodes: typeof nodes;
35
+ static tags: {
35
36
  if: import("./src/types").Schema<Readonly<Partial<{
36
37
  nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
37
38
  tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
@@ -73,7 +74,7 @@ declare const _default: {
73
74
  } | undefined;
74
75
  }>>, string>;
75
76
  };
76
- functions: {
77
+ static functions: {
77
78
  and: import("./src/types").ConfigFunction;
78
79
  or: import("./src/types").ConfigFunction;
79
80
  not: import("./src/types").ConfigFunction;
@@ -81,13 +82,14 @@ declare const _default: {
81
82
  default: import("./src/types").ConfigFunction;
82
83
  debug: import("./src/types").ConfigFunction;
83
84
  };
84
- renderers: {
85
+ static globalAttributes: Record<string, import("./src/types").SchemaAttribute> | undefined;
86
+ static renderers: {
85
87
  html: typeof import("./src/renderers/html").default;
86
88
  react: typeof import("./src/renderers/react/react").default;
87
89
  reactStatic: typeof import("./src/renderers/react/static").default;
88
90
  };
89
- transforms: typeof import("./src/transforms/table").default[];
90
- Ast: {
91
+ static transforms: typeof import("./src/transforms/table").default[];
92
+ static Ast: {
91
93
  fromJSON: (text: string) => Node | Node[];
92
94
  isAst(value?: any): value is import("./src/types").AstType;
93
95
  isFunction(value?: any): value is import("./src/ast/function").default;
@@ -106,17 +108,30 @@ declare const _default: {
106
108
  Node: typeof Node;
107
109
  Variable: typeof import("./src/ast/variable").default;
108
110
  };
109
- Tag: typeof Tag;
110
- Tokenizer: typeof Tokenizer;
111
- parseTags: typeof parseTags;
112
- transformer: import("./src/transformer").Transformer;
113
- validator: typeof validator;
111
+ static Tag: typeof Tag;
112
+ static Tokenizer: typeof Tokenizer;
113
+ static parseTags: typeof parseTags;
114
+ static transformer: import("./src/types").Transformer;
115
+ static validator: typeof validator;
116
+ static parse: typeof parse;
117
+ static transform: typeof transform;
118
+ static validate: typeof validate;
119
+ static createElement: typeof createElement;
120
+ static truthy: typeof truthy;
121
+ config: Readonly<Partial<{
122
+ nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
123
+ tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
124
+ variables: Record<string, any>;
125
+ functions: Record<string, import("./src/types").ConfigFunction>;
126
+ partials: Record<string, any>;
127
+ validation?: {
128
+ validateFunctions?: boolean | undefined;
129
+ } | undefined;
130
+ }>>;
131
+ constructor(config: Config);
114
132
  parse: typeof parse;
115
- transform: typeof transform;
116
- validate: typeof validate;
117
- createElement: typeof createElement;
118
- truthy: typeof truthy;
119
- };
120
- export default _default;
121
- export { nodes, tags, functions, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, truthy, };
133
+ resolve: (content: Parameters<typeof resolve>[0]) => Node[];
134
+ transform: (content: Parameters<typeof transform>[0]) => RenderableTreeNode[];
135
+ validate: (content: Parameters<typeof validate>[0]) => ValidateError[];
136
+ }
122
137
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAClC,OAAO,GAAG,MAAM,eAAe,CAAC;AAChC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,SAAS,MAAM,uBAAuB,CAAC;AAC9C,OAAO,SAAS,MAAM,uBAAuB,CAAC;AAC9C,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,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,OAAO,EAAE,IAAI,EACb,MAAM,EAAE,CAAC,GACR,IAAI,CAAC;AACR,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC/C,OAAO,EAAE,I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,qBAClB;CAClC"}
package/dist/index.js CHANGED
@@ -6604,8 +6604,9 @@ __export(exports, {
6604
6604
  Tag: () => Tag,
6605
6605
  Tokenizer: () => Tokenizer,
6606
6606
  createElement: () => createElement,
6607
- default: () => markdoc_default,
6607
+ default: () => Markdoc,
6608
6608
  functions: () => functions_default,
6609
+ globalAttributes: () => globalAttributes,
6609
6610
  nodes: () => schema_exports,
6610
6611
  parse: () => parse3,
6611
6612
  parseTags: () => parseTags,
@@ -6934,7 +6935,10 @@ var Tokenizer = class {
6934
6935
  this.parser = new import_lib.default(config);
6935
6936
  this.parser.use(plugin, "annotations", {});
6936
6937
  this.parser.use(plugin2, "frontmatter", {});
6937
- this.parser.disable("lheading");
6938
+ this.parser.disable([
6939
+ "lheading",
6940
+ "code"
6941
+ ]);
6938
6942
  }
6939
6943
  tokenize(content) {
6940
6944
  return this.parser.parse(content.toString(), {});
@@ -6976,6 +6980,9 @@ var Class = class {
6976
6980
  };
6977
6981
 
6978
6982
  // src/transformer.ts
6983
+ function isPromise(a) {
6984
+ return a && typeof a === "object" && typeof a.then === "function";
6985
+ }
6979
6986
  var globalAttributes = {
6980
6987
  class: { type: Class, render: true },
6981
6988
  id: { type: String, render: true }
@@ -7007,7 +7014,11 @@ var transformer_default = {
7007
7014
  return output;
7008
7015
  },
7009
7016
  children(node, config = {}) {
7010
- return node.children.flatMap((child) => this.node(child, config));
7017
+ const children = node.children.flatMap((child) => this.node(child, config));
7018
+ if (children.some(isPromise)) {
7019
+ return Promise.all(children);
7020
+ }
7021
+ return children;
7011
7022
  },
7012
7023
  node(node, config = {}) {
7013
7024
  const schema = this.findSchema(node, config) ?? {};
@@ -7017,6 +7028,9 @@ var transformer_default = {
7017
7028
  if (!schema || !schema.render)
7018
7029
  return children;
7019
7030
  const attributes = this.attributes(node, config);
7031
+ if (isPromise(attributes) || isPromise(children)) {
7032
+ return Promise.all([attributes, children]).then((values) => new Tag(schema.render, ...values));
7033
+ }
7020
7034
  return new Tag(schema.render, attributes, children);
7021
7035
  }
7022
7036
  };
@@ -7032,6 +7046,7 @@ var Node = class {
7032
7046
  this.children = children;
7033
7047
  this.type = type;
7034
7048
  this.tag = tag;
7049
+ this.annotations = [];
7035
7050
  }
7036
7051
  *walk() {
7037
7052
  for (const child of this.children) {
@@ -7138,7 +7153,9 @@ var mappings = {
7138
7153
  variable: "text"
7139
7154
  };
7140
7155
  function annotate(node, attributes) {
7141
- for (const { name, value, type } of attributes)
7156
+ for (const attribute of attributes) {
7157
+ node.annotations.push(attribute);
7158
+ const { name, value, type } = attribute;
7142
7159
  if (type === "attribute")
7143
7160
  node.attributes[name] = value;
7144
7161
  else if (type === "class")
@@ -7146,6 +7163,7 @@ function annotate(node, attributes) {
7146
7163
  node.attributes.class[name] = value;
7147
7164
  else
7148
7165
  node.attributes.class = { [name]: value };
7166
+ }
7149
7167
  }
7150
7168
  function handleAttrs(token, type) {
7151
7169
  switch (type) {
@@ -7545,10 +7563,25 @@ var tagElse = {
7545
7563
  };
7546
7564
 
7547
7565
  // src/tags/partial.ts
7566
+ var PartialFile = class {
7567
+ validate(file, config) {
7568
+ const { partials = {} } = config;
7569
+ const partial2 = partials[file];
7570
+ if (!partial2)
7571
+ return [
7572
+ {
7573
+ id: "attribute-value-invalid",
7574
+ level: "error",
7575
+ message: `Partial \`${file}\` not found. The 'file' attribute must be set in \`config.partials\``
7576
+ }
7577
+ ];
7578
+ return [];
7579
+ }
7580
+ };
7548
7581
  var partial = {
7549
7582
  selfClosing: true,
7550
7583
  attributes: {
7551
- file: { type: String, render: false, required: true },
7584
+ file: { type: PartialFile, render: false, required: true },
7552
7585
  variables: { type: Object, render: false }
7553
7586
  },
7554
7587
  transform(node, config) {
@@ -7972,21 +8005,29 @@ function validate2(content, options) {
7972
8005
  function createElement(name, attributes = {}, ...children) {
7973
8006
  return { name, attributes, children };
7974
8007
  }
7975
- var markdoc_default = {
7976
- nodes: schema_exports,
7977
- tags: tags_default,
7978
- functions: functions_default,
7979
- renderers: renderers_default,
7980
- transforms: transforms_default,
7981
- Ast: ast_default,
7982
- Tag,
7983
- Tokenizer,
7984
- parseTags,
7985
- transformer: transformer_default,
7986
- validator: validate,
7987
- parse: parse3,
7988
- transform: transform2,
7989
- validate: validate2,
7990
- createElement,
7991
- truthy
8008
+ var Markdoc = class {
8009
+ constructor(config) {
8010
+ this.parse = parse3;
8011
+ this.resolve = (content) => resolve2(content, this.config);
8012
+ this.transform = (content) => transform2(content, this.config);
8013
+ this.validate = (content) => validate2(content, this.config);
8014
+ this.config = config;
8015
+ }
7992
8016
  };
8017
+ Markdoc.nodes = schema_exports;
8018
+ Markdoc.tags = tags_default;
8019
+ Markdoc.functions = functions_default;
8020
+ Markdoc.globalAttributes = globalAttributes;
8021
+ Markdoc.renderers = renderers_default;
8022
+ Markdoc.transforms = transforms_default;
8023
+ Markdoc.Ast = ast_default;
8024
+ Markdoc.Tag = Tag;
8025
+ Markdoc.Tokenizer = Tokenizer;
8026
+ Markdoc.parseTags = parseTags;
8027
+ Markdoc.transformer = transformer_default;
8028
+ Markdoc.validator = validate;
8029
+ Markdoc.parse = parse3;
8030
+ Markdoc.transform = transform2;
8031
+ Markdoc.validate = validate2;
8032
+ Markdoc.createElement = createElement;
8033
+ Markdoc.truthy = truthy;