@markdoc/markdoc 0.1.0 → 0.1.3

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>
@@ -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,6 +4,7 @@ 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
10
  import transformer from './src/transformer';
@@ -89,7 +90,7 @@ declare const _default: {
89
90
  Ast: {
90
91
  fromJSON: (text: string) => Node | Node[];
91
92
  isAst(value?: any): value is import("./src/types").AstType;
92
- isFunction(value?: any): value is import("./src/types").Function;
93
+ isFunction(value?: any): value is import("./src/ast/function").default;
93
94
  getAstValues(value: any): Generator<import("./src/types").AstType, void, unknown>;
94
95
  resolve(value: any, config?: Readonly<Partial<{
95
96
  nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
@@ -101,7 +102,7 @@ declare const _default: {
101
102
  validateFunctions?: boolean | undefined;
102
103
  } | undefined;
103
104
  }>>): any;
104
- Function: typeof import("./src/types").Function;
105
+ Function: typeof import("./src/ast/function").default;
105
106
  Node: typeof Node;
106
107
  Variable: typeof import("./src/ast/variable").default;
107
108
  };
@@ -114,7 +115,8 @@ declare const _default: {
114
115
  transform: typeof transform;
115
116
  validate: typeof validate;
116
117
  createElement: typeof createElement;
118
+ truthy: typeof truthy;
117
119
  };
118
120
  export default _default;
119
- export { nodes, tags, functions, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, };
121
+ export { nodes, tags, functions, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, truthy, };
120
122
  //# 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,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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AAM,EACjD,IAAI,EAAE,IAAI,EACV,MAAM,CAAC,EAAE,CAAC,GACT,kBAAkB,CAAC;AACtB,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EACjD,KAAK,EAAE,IAAI,EAAE,EACb,MAAM,CAAC,EAAE,CAAC,GACT,kBAAkB,EAAE,CAAC;AAaxB,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAChD,OAAO,EAAE,IAAI,EACb,OAAO,CAAC,EAAE,CAAC,GACV,aAAa,EAAE,CAYjB;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACxC,UAAU,KAAK,EACf,GAAG,QAAQ,EAAE,GAAG,EAAE;;;;;;EAGnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAED,wBAiBE;AAEF,OAAO,EACL,KAAK,EACL,IAAI,EACJ,SAAS,EACT,UAAU,EACV,SAAS,EACT,GAAG,EACH,GAAG,EACH,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,MAAM,GACP,CAAC"}
package/dist/index.js CHANGED
@@ -6615,6 +6615,7 @@ __export(exports, {
6615
6615
  transform: () => transform2,
6616
6616
  transformer: () => transformer_default,
6617
6617
  transforms: () => transforms_default,
6618
+ truthy: () => truthy,
6618
6619
  validate: () => validate2,
6619
6620
  validator: () => validate
6620
6621
  });
@@ -6728,6 +6729,7 @@ function findTagEnd(content, start = 0) {
6728
6729
  return pos;
6729
6730
  }
6730
6731
  }
6732
+ return null;
6731
6733
  }
6732
6734
  function parseTag(content, line, contentStart) {
6733
6735
  try {
@@ -6757,7 +6759,11 @@ function parseTags(content, firstLine = 0) {
6757
6759
  }
6758
6760
  if (!content.startsWith(OPEN, pos))
6759
6761
  continue;
6760
- const end = findTagEnd(content, pos) || 0;
6762
+ const end = findTagEnd(content, pos);
6763
+ if (end == null) {
6764
+ pos = pos + OPEN.length;
6765
+ continue;
6766
+ }
6761
6767
  const text2 = content.slice(pos, end + CLOSE.length);
6762
6768
  const inner = content.slice(pos + OPEN.length, end);
6763
6769
  const lineStart = content.lastIndexOf("\n", pos);
@@ -6803,6 +6809,9 @@ function createToken(state, content, contentStart) {
6803
6809
  const token = state.push(type, "", nesting);
6804
6810
  token.info = content;
6805
6811
  token.meta = meta;
6812
+ if (!state.delimiters) {
6813
+ state.delimiters = [];
6814
+ }
6806
6815
  return token;
6807
6816
  } catch (error2) {
6808
6817
  if (!(error2 instanceof import_tag2.SyntaxError))
@@ -7099,7 +7108,7 @@ function transform(document2) {
7099
7108
  for (const row of rest) {
7100
7109
  if (row.type === "list")
7101
7110
  convertToRow(row);
7102
- else if (row.type === "tag" && row.tag == "if") {
7111
+ else if (row.type === "tag" && row.tag === "if") {
7103
7112
  const children = [];
7104
7113
  for (const child of row.children) {
7105
7114
  if (child.type === "hr")
@@ -7146,11 +7155,11 @@ function handleAttrs(token, type) {
7146
7155
  return { ordered: token.type.startsWith("ordered") };
7147
7156
  case "link": {
7148
7157
  const attrs = Object.fromEntries(token.attrs);
7149
- return { href: attrs.href };
7158
+ return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
7150
7159
  }
7151
7160
  case "image": {
7152
7161
  const attrs = Object.fromEntries(token.attrs);
7153
- return { alt: token.content, src: attrs.src };
7162
+ return attrs.title ? { alt: token.content, src: attrs.src, title: attrs.title } : { alt: token.content, src: attrs.src };
7154
7163
  }
7155
7164
  case "text":
7156
7165
  case "code":
@@ -7159,6 +7168,26 @@ function handleAttrs(token, type) {
7159
7168
  const [language] = token.info.split(" ", 1);
7160
7169
  return language === "" ? { content: token.content } : { content: token.content, language };
7161
7170
  }
7171
+ case "td":
7172
+ case "th": {
7173
+ if (token.attrs) {
7174
+ const attrs = Object.fromEntries(token.attrs);
7175
+ let align;
7176
+ if (attrs.style) {
7177
+ if (attrs.style.includes("left")) {
7178
+ align = "left";
7179
+ } else if (attrs.style.includes("center")) {
7180
+ align = "center";
7181
+ } else if (attrs.style.includes("right")) {
7182
+ align = "right";
7183
+ }
7184
+ }
7185
+ if (align) {
7186
+ return { align };
7187
+ }
7188
+ }
7189
+ return {};
7190
+ }
7162
7191
  default:
7163
7192
  return {};
7164
7193
  }
@@ -7315,7 +7344,8 @@ var image = {
7315
7344
  render: "img",
7316
7345
  attributes: {
7317
7346
  src: { type: String, required: true },
7318
- alt: { type: String }
7347
+ alt: { type: String },
7348
+ title: { type: String }
7319
7349
  }
7320
7350
  };
7321
7351
  var fence2 = {
@@ -7758,7 +7788,7 @@ function validateFunction(fn, config) {
7758
7788
  {
7759
7789
  id: "function-undefined",
7760
7790
  level: "critical",
7761
- message: `Undefined function '${fn.name}'`
7791
+ message: `Undefined function: '${fn.name}'`
7762
7792
  }
7763
7793
  ];
7764
7794
  if (schema.validate)
@@ -7770,7 +7800,7 @@ function validateFunction(fn, config) {
7770
7800
  errors.push({
7771
7801
  id: "parameter-undefined",
7772
7802
  level: "error",
7773
- message: `Invalid parameter '${key}'`
7803
+ message: `Invalid parameter: '${key}'`
7774
7804
  });
7775
7805
  continue;
7776
7806
  }
@@ -7782,7 +7812,7 @@ function validateFunction(fn, config) {
7782
7812
  errors.push({
7783
7813
  id: "parameter-type-invalid",
7784
7814
  level: "error",
7785
- message: `Parameter '${key}' of '${fn.name}' must be type '${typeToString(param.type)}'`
7815
+ message: `Parameter '${key}' of '${fn.name}' must be type of '${typeToString(param.type)}'`
7786
7816
  });
7787
7817
  } else if (Array.isArray(valid)) {
7788
7818
  errors.push(...valid);
@@ -7795,7 +7825,7 @@ function validateFunction(fn, config) {
7795
7825
  errors.push({
7796
7826
  id: "parameter-missing-required",
7797
7827
  level: "error",
7798
- message: `Missing required parameter '${key}'`
7828
+ message: `Missing required parameter: '${key}'`
7799
7829
  });
7800
7830
  return errors;
7801
7831
  }
@@ -7806,7 +7836,7 @@ function validate(node, config) {
7806
7836
  errors.push({
7807
7837
  id: node.tag ? "tag-undefined" : "node-undefined",
7808
7838
  level: "critical",
7809
- message: node.tag ? `Undefined tag '${node.tag}'` : `Undefined node '${node.type}'`
7839
+ message: node.tag ? `Undefined tag: '${node.tag}'` : `Undefined node: '${node.type}'`
7810
7840
  });
7811
7841
  return errors;
7812
7842
  }
@@ -7814,7 +7844,7 @@ function validate(node, config) {
7814
7844
  errors.push({
7815
7845
  id: "tag-selfclosing-has-children",
7816
7846
  level: "critical",
7817
- message: `Tag '${node.tag}' should be self-closing`
7847
+ message: `'${node.tag}' tag should be self-closing`
7818
7848
  });
7819
7849
  const attributes = {
7820
7850
  ...globalAttributes,
@@ -7828,7 +7858,7 @@ function validate(node, config) {
7828
7858
  errors.push({
7829
7859
  id: "attribute-undefined",
7830
7860
  level: "error",
7831
- message: `Invalid attribute '${key}'`
7861
+ message: `Invalid attribute: '${key}'`
7832
7862
  });
7833
7863
  continue;
7834
7864
  }
@@ -7844,7 +7874,7 @@ function validate(node, config) {
7844
7874
  errors.push({
7845
7875
  id: "attribute-value-invalid",
7846
7876
  level: "error",
7847
- message: "The ID attribute must not start with a number"
7877
+ message: "The id attribute must not start with a number"
7848
7878
  });
7849
7879
  if (type) {
7850
7880
  const valid = validateType(type, value, config);
@@ -7852,7 +7882,7 @@ function validate(node, config) {
7852
7882
  errors.push({
7853
7883
  id: "attribute-type-invalid",
7854
7884
  level: errorLevel || "error",
7855
- message: `Attribute '${key}' must be type '${typeToString(type)}'`
7885
+ message: `Attribute '${key}' must be type of '${typeToString(type)}'`
7856
7886
  });
7857
7887
  }
7858
7888
  if (Array.isArray(valid)) {
@@ -7879,7 +7909,7 @@ function validate(node, config) {
7879
7909
  errors.push({
7880
7910
  id: "attribute-missing-required",
7881
7911
  level: "error",
7882
- message: `Missing required attribute '${key}'`
7912
+ message: `Missing required attribute: '${key}'`
7883
7913
  });
7884
7914
  for (const { type } of node.children) {
7885
7915
  if (schema.children && type !== "error" && !schema.children.includes(type))
@@ -7957,5 +7987,6 @@ var markdoc_default = {
7957
7987
  parse: parse3,
7958
7988
  transform: transform2,
7959
7989
  validate: validate2,
7960
- createElement
7990
+ createElement,
7991
+ truthy
7961
7992
  };