@markdoc/markdoc 0.5.12 → 0.5.14

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.
Files changed (86) hide show
  1. package/README.md +35 -1
  2. package/dist/index.d.ts +4 -4
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +472 -448
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.mjs +472 -448
  7. package/dist/index.mjs.map +4 -4
  8. package/dist/react.js +4 -4
  9. package/dist/react.js.map +2 -2
  10. package/dist/src/ast/base.d.ts +1 -1
  11. package/dist/src/ast/base.d.ts.map +1 -1
  12. package/dist/src/ast/function.d.ts +1 -1
  13. package/dist/src/ast/function.d.ts.map +1 -1
  14. package/dist/src/ast/index.d.ts +2 -2
  15. package/dist/src/ast/index.d.ts.map +1 -1
  16. package/dist/src/ast/node.d.ts.map +1 -1
  17. package/dist/src/ast/variable.d.ts +1 -1
  18. package/dist/src/ast/variable.d.ts.map +1 -1
  19. package/dist/src/formatter.d.ts.map +1 -1
  20. package/dist/src/functions/index.d.ts.map +1 -1
  21. package/dist/src/parser.d.ts.map +1 -1
  22. package/dist/src/renderers/html.d.ts.map +1 -1
  23. package/dist/src/renderers/react/react.d.ts +2 -2
  24. package/dist/src/renderers/react/react.d.ts.map +1 -1
  25. package/dist/src/renderers/react/static.d.ts +1 -1
  26. package/dist/src/renderers/react/static.d.ts.map +1 -1
  27. package/dist/src/schema-types/class.d.ts +1 -1
  28. package/dist/src/schema-types/class.d.ts.map +1 -1
  29. package/dist/src/schema-types/conditional.d.ts +1 -1
  30. package/dist/src/schema-types/conditional.d.ts.map +1 -1
  31. package/dist/src/schema.d.ts.map +1 -1
  32. package/dist/src/tags/conditional.d.ts +1 -1
  33. package/dist/src/tags/conditional.d.ts.map +1 -1
  34. package/dist/src/tokenizer/index.d.ts.map +1 -1
  35. package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -1
  36. package/dist/src/transformer.d.ts.map +1 -1
  37. package/dist/src/validator.d.ts +1 -1
  38. package/dist/src/validator.d.ts.map +1 -1
  39. package/index.ts +21 -22
  40. package/package.json +9 -14
  41. package/spec/support/matchers.d.ts +6 -4
  42. package/src/ast/base.ts +21 -6
  43. package/src/ast/function.ts +1 -1
  44. package/src/ast/index.ts +3 -4
  45. package/src/ast/node.test.ts +126 -36
  46. package/src/ast/node.ts +4 -4
  47. package/src/ast/variable.test.ts +5 -4
  48. package/src/ast/variable.ts +1 -1
  49. package/src/formatter.test.ts +4 -3
  50. package/src/formatter.ts +11 -11
  51. package/src/functions/index.test.ts +8 -7
  52. package/src/functions/index.ts +1 -1
  53. package/src/grammar/tag.d.ts +1 -1
  54. package/src/grammar/tag.js +208 -285
  55. package/src/grammar/tag.pegjs +8 -8
  56. package/src/grammar/tag.test.ts +80 -48
  57. package/src/parser.test.ts +124 -66
  58. package/src/parser.ts +29 -7
  59. package/src/renderers/html.test.ts +56 -16
  60. package/src/renderers/html.ts +10 -2
  61. package/src/renderers/react/react.test.ts +39 -27
  62. package/src/renderers/react/react.ts +9 -10
  63. package/src/renderers/react/static.ts +5 -6
  64. package/src/schema-types/class.ts +1 -1
  65. package/src/schema-types/conditional.ts +1 -1
  66. package/src/schema.ts +9 -4
  67. package/src/tag.test.ts +2 -1
  68. package/src/tag.ts +1 -1
  69. package/src/tags/conditional.ts +4 -4
  70. package/src/tags/index.ts +2 -2
  71. package/src/tags/partial.ts +1 -1
  72. package/src/tokenizer/index.ts +6 -5
  73. package/src/tokenizer/plugins/annotations.test.ts +29 -28
  74. package/src/tokenizer/plugins/annotations.ts +12 -12
  75. package/src/tokenizer/plugins/comments.test.ts +11 -10
  76. package/src/tokenizer/plugins/comments.ts +2 -2
  77. package/src/tokenizer/plugins/frontmatter.test.ts +7 -6
  78. package/src/tokenizer/plugins/frontmatter.ts +2 -2
  79. package/src/tokenizer/plugins/link.test.ts +14 -13
  80. package/src/transformer.ts +11 -7
  81. package/src/transforms/table.test.ts +18 -17
  82. package/src/transforms/table.ts +1 -1
  83. package/src/utils.test.ts +23 -22
  84. package/src/utils.ts +3 -3
  85. package/src/validator.test.ts +205 -31
  86. package/src/validator.ts +21 -13
package/src/validator.ts CHANGED
@@ -1,17 +1,16 @@
1
- import { globalAttributes } from './transformer';
2
1
  import Ast from './ast/index';
3
- import { isPromise } from './utils';
4
-
2
+ import { globalAttributes } from './transformer';
5
3
  import type {
4
+ Config,
5
+ Function,
6
6
  Location,
7
7
  Node,
8
- Function,
9
- Config,
10
8
  SchemaAttribute,
11
9
  ValidateError,
12
10
  ValidationError,
13
11
  Value,
14
12
  } from './types';
13
+ import { isPromise } from './utils';
15
14
 
16
15
  const TypeMappings = {
17
16
  String: String,
@@ -27,7 +26,7 @@ export function validateType(
27
26
  type: TypeParam,
28
27
  value: Value,
29
28
  config: Config,
30
- key: string
29
+ key: string,
31
30
  ): boolean | ValidationError[] {
32
31
  if (!type) return true;
33
32
 
@@ -146,7 +145,7 @@ export default function validator(node: Node, config: Config) {
146
145
  return errors;
147
146
  }
148
147
 
149
- if (schema.inline != undefined && node.inline !== schema.inline)
148
+ if (schema.inline != null && node.inline !== schema.inline)
150
149
  errors.push({
151
150
  id: 'tag-placement-invalid',
152
151
  level: 'critical',
@@ -178,7 +177,10 @@ export default function validator(node: Node, config: Config) {
178
177
  }
179
178
 
180
179
  for (let [key, value] of Object.entries(node.attributes)) {
181
- const attrib = attributes[key];
180
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn requires ES2022; Markdoc targets ES2021.
181
+ const attrib = Object.prototype.hasOwnProperty.call(attributes, key)
182
+ ? attributes[key]
183
+ : undefined;
182
184
 
183
185
  if (!attrib) {
184
186
  errors.push({
@@ -200,6 +202,7 @@ export default function validator(node: Node, config: Config) {
200
202
  let variables = config.variables;
201
203
 
202
204
  for (const key of value.path) {
205
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn requires ES2022; Markdoc targets ES2021.
203
206
  if (!Object.prototype.hasOwnProperty.call(variables, key)) {
204
207
  missing = true;
205
208
  break;
@@ -241,7 +244,7 @@ export default function validator(node: Node, config: Config) {
241
244
  level: errorLevel || 'error',
242
245
  message: `Attribute '${key}' must match one of ${displayMatches(
243
246
  matches,
244
- 8
247
+ 8,
245
248
  )}. Got '${value}' instead.`,
246
249
  });
247
250
 
@@ -259,7 +262,12 @@ export default function validator(node: Node, config: Config) {
259
262
  }
260
263
 
261
264
  for (const [key, { required }] of Object.entries(attributes))
262
- if (required && node.attributes[key] === undefined)
265
+ if (
266
+ required &&
267
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn requires ES2022; Markdoc targets ES2021.
268
+ (!Object.prototype.hasOwnProperty.call(node.attributes, key) ||
269
+ node.attributes[key] === undefined)
270
+ )
263
271
  errors.push({
264
272
  id: 'attribute-missing-required',
265
273
  level: 'error',
@@ -298,7 +306,7 @@ export default function validator(node: Node, config: Config) {
298
306
 
299
307
  export function* walkWithParents(
300
308
  node: Node,
301
- parents: Node[] = []
309
+ parents: Node[] = [],
302
310
  ): Generator<[Node, Node[]]> {
303
311
  yield [node, parents];
304
312
  for (const child of [...Object.values(node.slots), ...node.children])
@@ -306,7 +314,7 @@ export function* walkWithParents(
306
314
  }
307
315
 
308
316
  function hasValidLocation(
309
- error: ValidationError
317
+ error: ValidationError,
310
318
  ): error is ValidationError & { location: Location } {
311
319
  const loc = error.location;
312
320
  return (
@@ -319,7 +327,7 @@ function hasValidLocation(
319
327
 
320
328
  function toValidateError(
321
329
  node: { type: string; lines: number[]; location?: Location },
322
- error: ValidationError
330
+ error: ValidationError,
323
331
  ): ValidateError {
324
332
  if (hasValidLocation(error)) {
325
333
  return {