@markdoc/markdoc 0.3.0 → 0.3.1

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.
@@ -16,6 +16,7 @@ declare const _default: {
16
16
  functions: Record<string, import("../types").ConfigFunction>;
17
17
  partials: Record<string, any>;
18
18
  validation?: {
19
+ parents?: Node[] | undefined;
19
20
  validateFunctions?: boolean | undefined;
20
21
  } | undefined;
21
22
  }>>): any;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAcxC,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,CAE7C;;;;;;;;;;;;;;;;;;;;;AAED,wBAIE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAcxC,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,CAE7C;;;;;;;;;;;;;;;;;;;;;;AAED,wBAIE"}
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA8bF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA8cF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;AAI9B,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAsL/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,QAoBzE"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;AAI9B,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AA6L/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,QAoBzE"}
@@ -1,6 +1,6 @@
1
- import { CustomAttributeTypeInterface, ValidationError } from '../types';
1
+ import { Config, CustomAttributeTypeInterface, ValidationError } from '../types';
2
2
  export declare class Class implements CustomAttributeTypeInterface {
3
- validate(value: any): ValidationError[];
3
+ validate(value: any, _config: Config, key: string): ValidationError[];
4
4
  transform(value: any): any;
5
5
  }
6
6
  //# sourceMappingURL=class.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../../src/schema-types/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEzE,qBAAa,KAAM,YAAW,4BAA4B;IACxD,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,eAAe,EAAE;IAYvC,SAAS,CAAC,KAAK,EAAE,GAAG;CAOrB"}
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../../src/schema-types/class.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,4BAA4B,EAC5B,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,qBAAa,KAAM,YAAW,4BAA4B;IACxD,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,eAAe,EAAE;IAYrE,SAAS,CAAC,KAAK,EAAE,GAAG;CAOrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,eAAO,MAAM,QAAQ,EAAE,MAiBtB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAYrB,CAAC;AAEF,eAAO,MAAM,SAAS,E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O,EAAE,MAYrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAGvB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAQnB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAenB,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,MAaxB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAclB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAclB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAEhB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAEnB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAmBhB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAQhB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAGhB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAGnB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAGnB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAMpB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAMhB,CAAC;AAEF,eAAO,MAAM,CAAC,EAAE,MAGf,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAcpB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAOlB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MASlB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAOlB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAEvB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAIvB,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;;;CAInB,CAAC;AAEF,eAAO,MAAM,KAAK,IAAK,CAAC;AACxB,eAAO,MAAM,IAAI,IAAK,CAAC"}
@@ -6,6 +6,7 @@ declare const _default: {
6
6
  functions: Record<string, import("../types").ConfigFunction>;
7
7
  partials: Record<string, any>;
8
8
  validation?: {
9
+ parents?: import("../types").Node[] | undefined;
9
10
  validateFunctions?: boolean | undefined;
10
11
  } | undefined;
11
12
  }>>, string>;
@@ -16,6 +17,7 @@ declare const _default: {
16
17
  functions: Record<string, import("../types").ConfigFunction>;
17
18
  partials: Record<string, any>;
18
19
  validation?: {
20
+ parents?: import("../types").Node[] | undefined;
19
21
  validateFunctions?: boolean | undefined;
20
22
  } | undefined;
21
23
  }>>, string>;
@@ -26,6 +28,7 @@ declare const _default: {
26
28
  functions: Record<string, import("../types").ConfigFunction>;
27
29
  partials: Record<string, any>;
28
30
  validation?: {
31
+ parents?: import("../types").Node[] | undefined;
29
32
  validateFunctions?: boolean | undefined;
30
33
  } | undefined;
31
34
  }>>, string>;
@@ -36,6 +39,7 @@ declare const _default: {
36
39
  functions: Record<string, import("../types").ConfigFunction>;
37
40
  partials: Record<string, any>;
38
41
  validation?: {
42
+ parents?: import("../types").Node[] | undefined;
39
43
  validateFunctions?: boolean | undefined;
40
44
  } | undefined;
41
45
  }>>, string>;
@@ -46,6 +50,7 @@ declare const _default: {
46
50
  functions: Record<string, import("../types").ConfigFunction>;
47
51
  partials: Record<string, any>;
48
52
  validation?: {
53
+ parents?: import("../types").Node[] | undefined;
49
54
  validateFunctions?: boolean | undefined;
50
55
  } | undefined;
51
56
  }>>, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tags/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wBAME"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tags/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wBAME"}
@@ -1 +1 @@
1
- {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AA4H9C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAM5C"}
1
+ {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AA8H9C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAM5C"}
@@ -23,6 +23,7 @@ export declare type ConfigType = Partial<{
23
23
  functions: Record<string, ConfigFunction>;
24
24
  partials: Record<string, any>;
25
25
  validation?: {
26
+ parents?: Node[];
26
27
  validateFunctions?: boolean;
27
28
  };
28
29
  }>;
@@ -34,7 +35,7 @@ export declare type ConfigFunction = {
34
35
  };
35
36
  export interface CustomAttributeTypeInterface {
36
37
  transform?(value: any, config: Config): Scalar;
37
- validate?(value: any, config: Config): ValidationError[];
38
+ validate?(value: any, config: Config, name: string): ValidationError[];
38
39
  }
39
40
  export interface CustomAttributeType {
40
41
  new (): CustomAttributeTypeInterface;
@@ -73,7 +74,7 @@ export declare type SchemaAttribute = {
73
74
  default?: any;
74
75
  required?: boolean;
75
76
  matches?: SchemaMatches | ((config: Config) => SchemaMatches);
76
- validate?(value: any, config: Config): ValidationError[];
77
+ validate?(value: any, config: Config, name: string): ValidationError[];
77
78
  errorLevel?: ValidationError['level'];
78
79
  description?: string;
79
80
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAE7B,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAC1B,MAAM,CAAC,OAAO,MAAM,QAAQ,GAAG,IAAI,CAAC;AACpC,MAAM,CAAC,O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MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC;AAEF,oBAAY,cAAc,GACtB,mBAAmB,GACnB,OAAO,MAAM,GACb,OAAO,MAAM,GACb,OAAO,OAAO,GACd,OAAO,MAAM,GACb,OAAO,KAAK,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,CAAC;AAEZ,oBAAY,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErC,oBAAY,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC"}
@@ -1,6 +1,28 @@
1
1
  import type { Node, Config, SchemaAttribute, ValidationError, Value } from './types';
2
2
  declare type TypeParam = NonNullable<SchemaAttribute['type']>;
3
- export declare function validateType(type: TypeParam, value: Value, config: Config): boolean | ValidationError[];
3
+ export declare function validateType(type: TypeParam, value: Value, config: Config, key: string): boolean | ValidationError[];
4
4
  export default function validator(node: Node, config: Config): ValidationError[] | Promise<ValidationError[]>;
5
+ export declare function walkWithParents(node: Node, parents?: Node[]): Generator<[Node, Node[]]>;
6
+ export declare function validateTree(content: Node, config: Config): Promise<({
7
+ type: import("./types").NodeType;
8
+ lines: number[];
9
+ location: import("./types").Location | undefined;
10
+ error: ValidationError;
11
+ } | {
12
+ type: import("./types").NodeType;
13
+ lines: number[];
14
+ location: import("./types").Location | undefined;
15
+ error: ValidationError;
16
+ })[]> | (Promise<{
17
+ type: import("./types").NodeType;
18
+ lines: number[];
19
+ location: import("./types").Location | undefined;
20
+ error: ValidationError;
21
+ }[]> | {
22
+ type: import("./types").NodeType;
23
+ lines: number[];
24
+ location: import("./types").Location | undefined;
25
+ error: ValidationError;
26
+ })[];
5
27
  export {};
6
28
  //# sourceMappingURL=validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,IAAI,EAEJ,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAC;AAUjB,aAAK,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,GAAG,eAAe,EAAE,CA2B7B;AA2ED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kDAoK3D"}
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,IAAI,EAEJ,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAC;AAUjB,aAAK,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,GAAG,eAAe,EAAE,CA2B7B;AA2ED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kDAoK3D;AAED,wBAAiB,eAAe,CAC9B,IAAI,EAAE,IAAI,EACV,OAAO,GAAE,IAAI,EAAO,GACnB,SAAS,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAI3B;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;KAuBzD"}
package/index.ts CHANGED
@@ -10,8 +10,8 @@ import { truthy } from './src/tags/conditional';
10
10
  import Tokenizer from './src/tokenizer';
11
11
  import transformer, { globalAttributes } from './src/transformer';
12
12
  import transforms from './src/transforms';
13
- import { parseTags, isPromise } from './src/utils';
14
- import validator from './src/validator';
13
+ import { parseTags } from './src/utils';
14
+ import validator, { validateTree } from './src/validator';
15
15
 
16
16
  import type { Node, ParserArgs } from './src/types';
17
17
  import type Token from 'markdown-it/lib/token';
@@ -94,25 +94,7 @@ export function validate<C extends Config = Config>(
94
94
  options?: C
95
95
  ): any {
96
96
  const config = mergeConfig(options);
97
-
98
- const output = [content, ...content.walk()].map((node) => {
99
- const { type, lines, location } = node;
100
- const errors = validator(node, config);
101
-
102
- if (isPromise(errors)) {
103
- return errors.then((e) =>
104
- e.map((error) => ({ type, lines, location, error }))
105
- );
106
- }
107
-
108
- return errors.map((error) => ({ type, lines, location, error }));
109
- });
110
-
111
- if (output.some(isPromise)) {
112
- return Promise.all(output).then((o) => o.flat());
113
- }
114
-
115
- return output.flat();
97
+ return validateTree(content, config);
116
98
  }
117
99
 
118
100
  export function createElement(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markdoc/markdoc",
3
3
  "author": "Ryan Paul",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "description": "A text markup language for documentation",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -506,6 +506,12 @@ Yes!
506
506
 
507
507
  it('"loose" lists', () => {
508
508
  const source = `
509
+ - a
510
+
511
+ - b
512
+
513
+ ---
514
+
509
515
  - One
510
516
 
511
517
  My first paragraph
@@ -528,6 +534,12 @@ Yes!
528
534
 
529
535
  > Indented blockquote`;
530
536
  const expected = `
537
+ - a
538
+
539
+ - b
540
+
541
+ ---
542
+
531
543
  - One
532
544
 
533
545
  My first paragraph
@@ -540,6 +552,7 @@ Yes!
540
552
  \`\`\`
541
553
  {% $code %}
542
554
  \`\`\`
555
+
543
556
  - Two
544
557
 
545
558
  My second paragraph
@@ -626,6 +639,7 @@ Yes!
626
639
  "nested": "code block"
627
640
  }
628
641
  \`\`\`
642
+
629
643
  1. Enter these values in the form that opens:
630
644
 
631
645
  {% table %}
@@ -653,6 +667,7 @@ Yes!
653
667
  - \`Off\`
654
668
  - Set the proxy status to \`off\` to avoid issues during setup.
655
669
  {% /table %}
670
+
656
671
  1. foo\\
657
672
  baz
658
673
 
@@ -767,4 +782,21 @@ ${'`'.repeat(4)}
767
782
  check(source, expected);
768
783
  stable(expected);
769
784
  });
785
+ it('skips over undefined variables', () => {
786
+ const sourceNode = new Markdoc.Ast.Node(
787
+ 'tag',
788
+ {
789
+ undefinedAttribute: undefined,
790
+ validAttribute: true,
791
+ },
792
+ [],
793
+ 'tag'
794
+ );
795
+
796
+ const expected = `{% tag validAttribute=true /%}`;
797
+
798
+ const b = format(sourceNode);
799
+ const d = diff(expected, b.trim());
800
+ if (d && d.includes('Compared values have no visual difference.')) return;
801
+ });
770
802
  });
package/src/formatter.ts CHANGED
@@ -39,7 +39,10 @@ function* formatTableRow(items: Array<string>) {
39
39
  yield `| ${items.join(' | ')} |`;
40
40
  }
41
41
 
42
- function formatScalar(v: Value): string {
42
+ function formatScalar(v: Value): string | undefined {
43
+ if (v === undefined) {
44
+ return undefined;
45
+ }
43
46
  if (Ast.isAst(v)) {
44
47
  return format(v);
45
48
  }
@@ -64,12 +67,16 @@ function formatScalar(v: Value): string {
64
67
  return JSON.stringify(v);
65
68
  }
66
69
 
67
- function formatAnnotationValue(a: AttributeValue): string {
68
- if (a.name === 'primary') return formatScalar(a.value);
70
+ function formatAnnotationValue(a: AttributeValue): string | undefined {
71
+ const formattedValue = formatScalar(a.value);
72
+
73
+ if (formattedValue === undefined) return undefined;
74
+ if (a.name === 'primary') return formattedValue;
69
75
  if (a.name === 'id' && typeof a.value === 'string' && isIdentifier(a.value))
70
76
  return '#' + a.value;
71
77
  if (a.type === 'class' && isIdentifier(a.name)) return '.' + a.name;
72
- return `${a.name}=${formatScalar(a.value)}`;
78
+
79
+ return `${a.name}=${formattedValue}`;
73
80
  }
74
81
 
75
82
  function* formatAttributes(n: Node) {
@@ -258,7 +265,10 @@ function* formatNode(n: Node, o: Options = {}) {
258
265
  yield indent;
259
266
  }
260
267
  const open = OPEN + SPACE;
261
- const tag = [open + n.tag, ...formatAttributes(n)];
268
+ const attributes = [...formatAttributes(n)].filter(
269
+ (v) => v !== undefined
270
+ );
271
+ const tag = [open + n.tag, ...attributes];
262
272
  const inlineTag = tag.join(SPACE);
263
273
 
264
274
  const isLongTagOpening =
@@ -287,16 +297,22 @@ function* formatNode(n: Node, o: Options = {}) {
287
297
  break;
288
298
  }
289
299
  case 'list': {
300
+ const isLoose = n.children.some((n) =>
301
+ n.children.some((c) => c.type === 'paragraph')
302
+ );
303
+
290
304
  for (let i = 0; i < n.children.length; i++) {
291
305
  const prefix = n.attributes.ordered
292
306
  ? `${i === 0 ? n.attributes.start ?? '1' : '1'}${
293
307
  n.attributes.marker ?? OL
294
308
  }`
295
309
  : n.attributes.marker ?? UL;
296
- const d = format(
297
- n.children[i],
298
- increment(no, prefix.length + 1)
299
- ).trim();
310
+ let d = format(n.children[i], increment(no, prefix.length + 1));
311
+
312
+ if (!isLoose || i === n.children.length - 1) {
313
+ d = d.trim();
314
+ }
315
+
300
316
  yield NL + indent + prefix + ' ' + d;
301
317
  }
302
318
  yield NL;
@@ -740,6 +740,163 @@ describe('Markdown parser', function () {
740
740
  });
741
741
  });
742
742
 
743
+ describe('handles attribute errors correctly', function () {
744
+ it('with error for duplicate attributes', function () {
745
+ const example = convert(`{% foo bar=1 bar=2 bar=3 bar=4 /%}`);
746
+ expect(example.children[0].errors.length).toBe(3);
747
+ expect(example).toDeepEqualSubset({
748
+ type: 'document',
749
+ children: [
750
+ {
751
+ tag: 'foo',
752
+ errors: [
753
+ { id: 'duplicate-attribute' },
754
+ { id: 'duplicate-attribute' },
755
+ { id: 'duplicate-attribute' },
756
+ ],
757
+ },
758
+ ],
759
+ });
760
+ });
761
+
762
+ it('with error for duplicate ids', function () {
763
+ const example = convert(`{% foo #bar #baz #qux /%}`);
764
+ expect(example.children[0].errors.length).toBe(2);
765
+ expect(example).toDeepEqualSubset({
766
+ type: 'document',
767
+ children: [
768
+ {
769
+ tag: 'foo',
770
+ errors: [
771
+ { id: 'duplicate-attribute' },
772
+ { id: 'duplicate-attribute' },
773
+ ],
774
+ },
775
+ ],
776
+ });
777
+ });
778
+
779
+ it('with annotation values', function () {
780
+ const example = convert(`testing {% foo=1 foo=2 %}`);
781
+ expect(example.children[0].errors.length).toBe(1);
782
+ expect(example).toDeepEqualSubset({
783
+ type: 'document',
784
+ children: [
785
+ {
786
+ type: 'paragraph',
787
+ errors: [{ id: 'duplicate-attribute' }],
788
+ },
789
+ ],
790
+ });
791
+ });
792
+
793
+ it('across annotations on the same node', function () {
794
+ const example = convert(`testing {% foo=1 %} another test {% foo=1 %}`);
795
+ expect(example.children[0].errors.length).toBe(1);
796
+ expect(example).toDeepEqualSubset({
797
+ type: 'document',
798
+ children: [
799
+ {
800
+ type: 'paragraph',
801
+ errors: [{ id: 'duplicate-attribute' }],
802
+ },
803
+ ],
804
+ });
805
+ });
806
+
807
+ it('with no error for multiple classes', function () {
808
+ const example = convert(`{% foo .bar .baz .qux /%}`);
809
+ expect(example.children[0].errors.length).toBe(0);
810
+ });
811
+ });
812
+
813
+ it('displays error for annotations in a fence', function () {
814
+ const example = convert(`
815
+ ~~~
816
+ test
817
+ {% #foo %}
818
+ test
819
+ ~~~
820
+ `);
821
+
822
+ expect(Object.values(example.annotations).length).toEqual(0);
823
+ expect(example.children[0].errors[0]?.id).toEqual('no-inline-annotations');
824
+ });
825
+
826
+ it('correctly identifies inlines', function () {
827
+ const example = convert(`
828
+ # This is a test
829
+
830
+ {% foo %}
831
+ Another {% bar %}test{% /bar %} test
832
+ {% /foo %}
833
+
834
+ * bar
835
+ `);
836
+
837
+ expect(example).toDeepEqualSubset({
838
+ type: 'document',
839
+ inline: false,
840
+ children: [
841
+ {
842
+ type: 'heading',
843
+ inline: false,
844
+ children: [
845
+ {
846
+ type: 'inline',
847
+ inline: false,
848
+ children: [{ type: 'text', inline: true }],
849
+ },
850
+ ],
851
+ },
852
+ {
853
+ type: 'tag',
854
+ tag: 'foo',
855
+ inline: false,
856
+ children: [
857
+ {
858
+ type: 'paragraph',
859
+ inline: false,
860
+ children: [
861
+ {
862
+ type: 'inline',
863
+ inline: false,
864
+ children: [
865
+ { type: 'text', inline: true },
866
+ {
867
+ type: 'tag',
868
+ tag: 'bar',
869
+ inline: true,
870
+ children: [{ type: 'text', inline: true }],
871
+ },
872
+ { type: 'text', inline: true },
873
+ ],
874
+ },
875
+ ],
876
+ },
877
+ ],
878
+ },
879
+ {
880
+ type: 'list',
881
+ inline: false,
882
+ children: [
883
+ {
884
+ type: 'item',
885
+ inline: false,
886
+ children: [
887
+ {
888
+ type: 'inline',
889
+ inline: false,
890
+ children: [{ type: 'text', inline: true }],
891
+ },
892
+ ],
893
+ },
894
+ ],
895
+ },
896
+ ],
897
+ });
898
+ });
899
+
743
900
  describe('handles structural errors correctly', function () {
744
901
  it('with unmatched closing tag', function () {
745
902
  const example = convert(`
package/src/parser.ts CHANGED
@@ -19,8 +19,15 @@ function annotate(node: Node, attributes: AttributeValue[]) {
19
19
  node.annotations.push(attribute);
20
20
 
21
21
  const { name, value, type } = attribute;
22
- if (type === 'attribute') node.attributes[name] = value;
23
- else if (type === 'class')
22
+ if (type === 'attribute') {
23
+ if (node.attributes[name] !== undefined)
24
+ node.errors.push({
25
+ id: 'duplicate-attribute',
26
+ level: 'warning',
27
+ message: `Attribute '${name}' already set`,
28
+ });
29
+ node.attributes[name] = value;
30
+ } else if (type === 'class')
24
31
  if (node.attributes.class) node.attributes.class[name] = value;
25
32
  else node.attributes.class = { [name]: value };
26
33
  }
@@ -173,7 +180,7 @@ function handleToken(
173
180
 
174
181
  if (!Array.isArray(token.children)) return;
175
182
 
176
- inlineParent = parent;
183
+ if (node.type === 'inline') inlineParent = parent;
177
184
 
178
185
  nodes.push(node);
179
186
 
@@ -54,6 +54,13 @@ describe('HTML renderer', function () {
54
54
  expect(html).toEqual('<p>1</p>');
55
55
  });
56
56
 
57
+ it('lowercase attributes', function () {
58
+ const content = tag('td', { colSpan: 2, rowSpan: 3 }, ['Data']);
59
+
60
+ const html = render(content);
61
+ expect(html).toEqual('<td colspan="2" rowspan="3">Data</td>');
62
+ });
63
+
57
64
  describe('attributes', function () {
58
65
  it('with basic value', function () {
59
66
  const example = tag('foo', { bar: 'baz' });
@@ -36,7 +36,7 @@ export default function render(node: RenderableTreeNodes): string {
36
36
 
37
37
  let output = `<${name}`;
38
38
  for (const [k, v] of Object.entries(attributes ?? {}))
39
- output += ` ${k}="${escapeHtml(String(v))}"`;
39
+ output += ` ${k.toLowerCase()}="${escapeHtml(String(v))}"`;
40
40
  output += '>';
41
41
 
42
42
  if (voidElements.has(name)) return output;
@@ -1,14 +1,18 @@
1
- import { CustomAttributeTypeInterface, ValidationError } from '../types';
1
+ import {
2
+ Config,
3
+ CustomAttributeTypeInterface,
4
+ ValidationError,
5
+ } from '../types';
2
6
 
3
7
  export class Class implements CustomAttributeTypeInterface {
4
- validate(value: any): ValidationError[] {
8
+ validate(value: any, _config: Config, key: string): ValidationError[] {
5
9
  if (typeof value === 'string' || typeof value === 'object') return [];
6
10
 
7
11
  return [
8
12
  {
9
13
  id: 'attribute-type-invalid',
10
14
  level: 'error',
11
- message: `Attribute 'class' must be type 'string | object'`,
15
+ message: `Attribute '${key}' must be type 'string | object'`,
12
16
  },
13
17
  ];
14
18
  }
package/src/schema.ts CHANGED
@@ -136,9 +136,9 @@ export const td: Schema = {
136
136
  'hr',
137
137
  ],
138
138
  attributes: {
139
- colspan: { type: Number },
140
- rowspan: { type: Number },
141
139
  align: { type: String },
140
+ colspan: { type: Number, render: 'colSpan' },
141
+ rowspan: { type: Number, render: 'rowSpan' },
142
142
  },
143
143
  };
144
144
 
@@ -147,6 +147,8 @@ export const th: Schema = {
147
147
  attributes: {
148
148
  width: { type: Number },
149
149
  align: { type: String },
150
+ colspan: { type: Number, render: 'colSpan' },
151
+ rowspan: { type: Number, render: 'rowSpan' },
150
152
  },
151
153
  };
152
154