@markdoc/markdoc 0.1.1 → 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
@@ -1,6 +1,6 @@
1
1
  <h1 align="center">
2
2
  <br>
3
- <img src="https://user-images.githubusercontent.com/62121649/166497424-eed74185-92b8-48bf-9d54-493282df288b.png" alt="Markdoc" width="260">
3
+ <img src="https://user-images.githubusercontent.com/62121649/167893184-a2b69260-ca9e-4a77-a5bc-63b8135ae5db.png" alt="Markdoc" width="260">
4
4
  <br>
5
5
  <br>
6
6
  </h1>
@@ -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
 
@@ -59,7 +59,7 @@ Contributions and feedback are welcome and encouraged. Check out our [contributi
59
59
  ### Development
60
60
 
61
61
  1. Run `npm install`
62
- 1. Run `npm build`
62
+ 1. Run `npm run build`
63
63
  1. Run the tests using `npm test`
64
64
 
65
65
  ## Code of conduct
@@ -72,4 +72,7 @@ This project uses the [MIT license](LICENSE).
72
72
 
73
73
  ## Credits
74
74
 
75
- Shout out to [@marcioAlmada](https://github.com/marcioAlmada) for providing us with the [@markdoc](https://github.com/markdoc) GitHub org.
75
+ Special shout out to:
76
+
77
+ - [@marcioAlmada](https://github.com/marcioAlmada) for providing us with the [@markdoc](https://github.com/markdoc) GitHub org.
78
+ - [@koomen](https://github.com/koomen) for gifting us https://markdoc.dev.
package/dist/index.d.ts CHANGED
@@ -4,9 +4,10 @@ import Tag from './src/ast/tag';
4
4
  import Ast from './src/ast/index';
5
5
  import * as nodes from './src/schema';
6
6
  import tags from './src/tags/index';
7
+ import { truthy } from './src/tags/conditional';
7
8
  import functions from './src/functions/index';
8
9
  import renderers from './src/renderers/index';
9
- import transformer from './src/transformer';
10
+ import transformer, { globalAttributes } from './src/transformer';
10
11
  import validator from './src/validator';
11
12
  import { parseTags } from './src/utils';
12
13
  import transforms from './src/transforms/index';
@@ -28,9 +29,10 @@ export declare function createElement(name: string | {
28
29
  attributes: {};
29
30
  children: any[];
30
31
  };
31
- declare const _default: {
32
- nodes: typeof nodes;
33
- 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: {
34
36
  if: import("./src/types").Schema<Readonly<Partial<{
35
37
  nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
36
38
  tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
@@ -72,7 +74,7 @@ declare const _default: {
72
74
  } | undefined;
73
75
  }>>, string>;
74
76
  };
75
- functions: {
77
+ static functions: {
76
78
  and: import("./src/types").ConfigFunction;
77
79
  or: import("./src/types").ConfigFunction;
78
80
  not: import("./src/types").ConfigFunction;
@@ -80,16 +82,17 @@ declare const _default: {
80
82
  default: import("./src/types").ConfigFunction;
81
83
  debug: import("./src/types").ConfigFunction;
82
84
  };
83
- renderers: {
85
+ static globalAttributes: Record<string, import("./src/types").SchemaAttribute> | undefined;
86
+ static renderers: {
84
87
  html: typeof import("./src/renderers/html").default;
85
88
  react: typeof import("./src/renderers/react/react").default;
86
89
  reactStatic: typeof import("./src/renderers/react/static").default;
87
90
  };
88
- transforms: typeof import("./src/transforms/table").default[];
89
- Ast: {
91
+ static transforms: typeof import("./src/transforms/table").default[];
92
+ static Ast: {
90
93
  fromJSON: (text: string) => Node | Node[];
91
94
  isAst(value?: any): value is import("./src/types").AstType;
92
- isFunction(value?: any): value is import("./src/types").Function;
95
+ isFunction(value?: any): value is import("./src/ast/function").default;
93
96
  getAstValues(value: any): Generator<import("./src/types").AstType, void, unknown>;
94
97
  resolve(value: any, config?: Readonly<Partial<{
95
98
  nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
@@ -101,20 +104,34 @@ declare const _default: {
101
104
  validateFunctions?: boolean | undefined;
102
105
  } | undefined;
103
106
  }>>): any;
104
- Function: typeof import("./src/types").Function;
107
+ Function: typeof import("./src/ast/function").default;
105
108
  Node: typeof Node;
106
109
  Variable: typeof import("./src/ast/variable").default;
107
110
  };
108
- Tag: typeof Tag;
109
- Tokenizer: typeof Tokenizer;
110
- parseTags: typeof parseTags;
111
- transformer: import("./src/transformer").Transformer;
112
- 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);
113
132
  parse: typeof parse;
114
- transform: typeof transform;
115
- validate: typeof validate;
116
- createElement: typeof createElement;
117
- };
118
- export default _default;
119
- export { nodes, tags, functions, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, };
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
+ }
120
137
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file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AG,EACH,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,MAAM,GACP,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;IAEvB,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
@@ -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,
@@ -6615,6 +6616,7 @@ __export(exports, {
6615
6616
  transform: () => transform2,
6616
6617
  transformer: () => transformer_default,
6617
6618
  transforms: () => transforms_default,
6619
+ truthy: () => truthy,
6618
6620
  validate: () => validate2,
6619
6621
  validator: () => validate
6620
6622
  });
@@ -6728,6 +6730,7 @@ function findTagEnd(content, start = 0) {
6728
6730
  return pos;
6729
6731
  }
6730
6732
  }
6733
+ return null;
6731
6734
  }
6732
6735
  function parseTag(content, line, contentStart) {
6733
6736
  try {
@@ -6757,7 +6760,11 @@ function parseTags(content, firstLine = 0) {
6757
6760
  }
6758
6761
  if (!content.startsWith(OPEN, pos))
6759
6762
  continue;
6760
- const end = findTagEnd(content, pos) || 0;
6763
+ const end = findTagEnd(content, pos);
6764
+ if (end == null) {
6765
+ pos = pos + OPEN.length;
6766
+ continue;
6767
+ }
6761
6768
  const text2 = content.slice(pos, end + CLOSE.length);
6762
6769
  const inner = content.slice(pos + OPEN.length, end);
6763
6770
  const lineStart = content.lastIndexOf("\n", pos);
@@ -6803,6 +6810,9 @@ function createToken(state, content, contentStart) {
6803
6810
  const token = state.push(type, "", nesting);
6804
6811
  token.info = content;
6805
6812
  token.meta = meta;
6813
+ if (!state.delimiters) {
6814
+ state.delimiters = [];
6815
+ }
6806
6816
  return token;
6807
6817
  } catch (error2) {
6808
6818
  if (!(error2 instanceof import_tag2.SyntaxError))
@@ -6925,7 +6935,10 @@ var Tokenizer = class {
6925
6935
  this.parser = new import_lib.default(config);
6926
6936
  this.parser.use(plugin, "annotations", {});
6927
6937
  this.parser.use(plugin2, "frontmatter", {});
6928
- this.parser.disable("lheading");
6938
+ this.parser.disable([
6939
+ "lheading",
6940
+ "code"
6941
+ ]);
6929
6942
  }
6930
6943
  tokenize(content) {
6931
6944
  return this.parser.parse(content.toString(), {});
@@ -6967,6 +6980,9 @@ var Class = class {
6967
6980
  };
6968
6981
 
6969
6982
  // src/transformer.ts
6983
+ function isPromise(a) {
6984
+ return a && typeof a === "object" && typeof a.then === "function";
6985
+ }
6970
6986
  var globalAttributes = {
6971
6987
  class: { type: Class, render: true },
6972
6988
  id: { type: String, render: true }
@@ -6998,7 +7014,11 @@ var transformer_default = {
6998
7014
  return output;
6999
7015
  },
7000
7016
  children(node, config = {}) {
7001
- 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;
7002
7022
  },
7003
7023
  node(node, config = {}) {
7004
7024
  const schema = this.findSchema(node, config) ?? {};
@@ -7008,6 +7028,9 @@ var transformer_default = {
7008
7028
  if (!schema || !schema.render)
7009
7029
  return children;
7010
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
+ }
7011
7034
  return new Tag(schema.render, attributes, children);
7012
7035
  }
7013
7036
  };
@@ -7023,6 +7046,7 @@ var Node = class {
7023
7046
  this.children = children;
7024
7047
  this.type = type;
7025
7048
  this.tag = tag;
7049
+ this.annotations = [];
7026
7050
  }
7027
7051
  *walk() {
7028
7052
  for (const child of this.children) {
@@ -7099,7 +7123,7 @@ function transform(document2) {
7099
7123
  for (const row of rest) {
7100
7124
  if (row.type === "list")
7101
7125
  convertToRow(row);
7102
- else if (row.type === "tag" && row.tag == "if") {
7126
+ else if (row.type === "tag" && row.tag === "if") {
7103
7127
  const children = [];
7104
7128
  for (const child of row.children) {
7105
7129
  if (child.type === "hr")
@@ -7129,7 +7153,9 @@ var mappings = {
7129
7153
  variable: "text"
7130
7154
  };
7131
7155
  function annotate(node, attributes) {
7132
- for (const { name, value, type } of attributes)
7156
+ for (const attribute of attributes) {
7157
+ node.annotations.push(attribute);
7158
+ const { name, value, type } = attribute;
7133
7159
  if (type === "attribute")
7134
7160
  node.attributes[name] = value;
7135
7161
  else if (type === "class")
@@ -7137,6 +7163,7 @@ function annotate(node, attributes) {
7137
7163
  node.attributes.class[name] = value;
7138
7164
  else
7139
7165
  node.attributes.class = { [name]: value };
7166
+ }
7140
7167
  }
7141
7168
  function handleAttrs(token, type) {
7142
7169
  switch (type) {
@@ -7146,11 +7173,11 @@ function handleAttrs(token, type) {
7146
7173
  return { ordered: token.type.startsWith("ordered") };
7147
7174
  case "link": {
7148
7175
  const attrs = Object.fromEntries(token.attrs);
7149
- return { href: attrs.href };
7176
+ return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
7150
7177
  }
7151
7178
  case "image": {
7152
7179
  const attrs = Object.fromEntries(token.attrs);
7153
- return { alt: token.content, src: attrs.src };
7180
+ return attrs.title ? { alt: token.content, src: attrs.src, title: attrs.title } : { alt: token.content, src: attrs.src };
7154
7181
  }
7155
7182
  case "text":
7156
7183
  case "code":
@@ -7159,6 +7186,26 @@ function handleAttrs(token, type) {
7159
7186
  const [language] = token.info.split(" ", 1);
7160
7187
  return language === "" ? { content: token.content } : { content: token.content, language };
7161
7188
  }
7189
+ case "td":
7190
+ case "th": {
7191
+ if (token.attrs) {
7192
+ const attrs = Object.fromEntries(token.attrs);
7193
+ let align;
7194
+ if (attrs.style) {
7195
+ if (attrs.style.includes("left")) {
7196
+ align = "left";
7197
+ } else if (attrs.style.includes("center")) {
7198
+ align = "center";
7199
+ } else if (attrs.style.includes("right")) {
7200
+ align = "right";
7201
+ }
7202
+ }
7203
+ if (align) {
7204
+ return { align };
7205
+ }
7206
+ }
7207
+ return {};
7208
+ }
7162
7209
  default:
7163
7210
  return {};
7164
7211
  }
@@ -7315,7 +7362,8 @@ var image = {
7315
7362
  render: "img",
7316
7363
  attributes: {
7317
7364
  src: { type: String, required: true },
7318
- alt: { type: String }
7365
+ alt: { type: String },
7366
+ title: { type: String }
7319
7367
  }
7320
7368
  };
7321
7369
  var fence2 = {
@@ -7515,10 +7563,25 @@ var tagElse = {
7515
7563
  };
7516
7564
 
7517
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
+ };
7518
7581
  var partial = {
7519
7582
  selfClosing: true,
7520
7583
  attributes: {
7521
- file: { type: String, render: false, required: true },
7584
+ file: { type: PartialFile, render: false, required: true },
7522
7585
  variables: { type: Object, render: false }
7523
7586
  },
7524
7587
  transform(node, config) {
@@ -7758,7 +7821,7 @@ function validateFunction(fn, config) {
7758
7821
  {
7759
7822
  id: "function-undefined",
7760
7823
  level: "critical",
7761
- message: `Undefined function '${fn.name}'`
7824
+ message: `Undefined function: '${fn.name}'`
7762
7825
  }
7763
7826
  ];
7764
7827
  if (schema.validate)
@@ -7770,7 +7833,7 @@ function validateFunction(fn, config) {
7770
7833
  errors.push({
7771
7834
  id: "parameter-undefined",
7772
7835
  level: "error",
7773
- message: `Invalid parameter '${key}'`
7836
+ message: `Invalid parameter: '${key}'`
7774
7837
  });
7775
7838
  continue;
7776
7839
  }
@@ -7782,7 +7845,7 @@ function validateFunction(fn, config) {
7782
7845
  errors.push({
7783
7846
  id: "parameter-type-invalid",
7784
7847
  level: "error",
7785
- message: `Parameter '${key}' of '${fn.name}' must be type '${typeToString(param.type)}'`
7848
+ message: `Parameter '${key}' of '${fn.name}' must be type of '${typeToString(param.type)}'`
7786
7849
  });
7787
7850
  } else if (Array.isArray(valid)) {
7788
7851
  errors.push(...valid);
@@ -7795,7 +7858,7 @@ function validateFunction(fn, config) {
7795
7858
  errors.push({
7796
7859
  id: "parameter-missing-required",
7797
7860
  level: "error",
7798
- message: `Missing required parameter '${key}'`
7861
+ message: `Missing required parameter: '${key}'`
7799
7862
  });
7800
7863
  return errors;
7801
7864
  }
@@ -7806,7 +7869,7 @@ function validate(node, config) {
7806
7869
  errors.push({
7807
7870
  id: node.tag ? "tag-undefined" : "node-undefined",
7808
7871
  level: "critical",
7809
- message: node.tag ? `Undefined tag '${node.tag}'` : `Undefined node '${node.type}'`
7872
+ message: node.tag ? `Undefined tag: '${node.tag}'` : `Undefined node: '${node.type}'`
7810
7873
  });
7811
7874
  return errors;
7812
7875
  }
@@ -7814,7 +7877,7 @@ function validate(node, config) {
7814
7877
  errors.push({
7815
7878
  id: "tag-selfclosing-has-children",
7816
7879
  level: "critical",
7817
- message: `Tag '${node.tag}' should be self-closing`
7880
+ message: `'${node.tag}' tag should be self-closing`
7818
7881
  });
7819
7882
  const attributes = {
7820
7883
  ...globalAttributes,
@@ -7828,7 +7891,7 @@ function validate(node, config) {
7828
7891
  errors.push({
7829
7892
  id: "attribute-undefined",
7830
7893
  level: "error",
7831
- message: `Invalid attribute '${key}'`
7894
+ message: `Invalid attribute: '${key}'`
7832
7895
  });
7833
7896
  continue;
7834
7897
  }
@@ -7844,7 +7907,7 @@ function validate(node, config) {
7844
7907
  errors.push({
7845
7908
  id: "attribute-value-invalid",
7846
7909
  level: "error",
7847
- message: "The ID attribute must not start with a number"
7910
+ message: "The id attribute must not start with a number"
7848
7911
  });
7849
7912
  if (type) {
7850
7913
  const valid = validateType(type, value, config);
@@ -7852,7 +7915,7 @@ function validate(node, config) {
7852
7915
  errors.push({
7853
7916
  id: "attribute-type-invalid",
7854
7917
  level: errorLevel || "error",
7855
- message: `Attribute '${key}' must be type '${typeToString(type)}'`
7918
+ message: `Attribute '${key}' must be type of '${typeToString(type)}'`
7856
7919
  });
7857
7920
  }
7858
7921
  if (Array.isArray(valid)) {
@@ -7879,7 +7942,7 @@ function validate(node, config) {
7879
7942
  errors.push({
7880
7943
  id: "attribute-missing-required",
7881
7944
  level: "error",
7882
- message: `Missing required attribute '${key}'`
7945
+ message: `Missing required attribute: '${key}'`
7883
7946
  });
7884
7947
  for (const { type } of node.children) {
7885
7948
  if (schema.children && type !== "error" && !schema.children.includes(type))
@@ -7942,20 +8005,29 @@ function validate2(content, options) {
7942
8005
  function createElement(name, attributes = {}, ...children) {
7943
8006
  return { name, attributes, children };
7944
8007
  }
7945
- var markdoc_default = {
7946
- nodes: schema_exports,
7947
- tags: tags_default,
7948
- functions: functions_default,
7949
- renderers: renderers_default,
7950
- transforms: transforms_default,
7951
- Ast: ast_default,
7952
- Tag,
7953
- Tokenizer,
7954
- parseTags,
7955
- transformer: transformer_default,
7956
- validator: validate,
7957
- parse: parse3,
7958
- transform: transform2,
7959
- validate: validate2,
7960
- createElement
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
+ }
7961
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;