@markdoc/markdoc 0.5.4 → 0.5.6

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.
@@ -1,3 +1,3 @@
1
1
  import type { Node } from '../types';
2
- export default function transform(document: Node): void;
2
+ export default function transform(document: Node, conditionalTags?: string[]): void;
3
3
  //# sourceMappingURL=table.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/transforms/table.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,UAAU,CAAC;AAW/C,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,QAAQ,EAAE,IAAI,QAqC/C"}
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/transforms/table.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,UAAU,CAAC;AAuChE,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,IAAI,EACd,eAAe,GAAE,MAAM,EAAW,QAqDnC"}
@@ -108,5 +108,6 @@ export declare type ParserArgs = {
108
108
  file?: string;
109
109
  slots?: boolean;
110
110
  location?: boolean;
111
+ conditionalTags?: string[];
111
112
  };
112
113
  //# sourceMappingURL=types.d.ts.map
@@ -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,OAAO,MAAM,QAAQ,GAAG,GAAG,CA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AC;IAC5D,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAAC;CAC5D;AAED,oBAAY,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,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;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAKnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markdoc/markdoc",
3
3
  "author": "Ryan Paul",
4
- "version": "0.5.4",
4
+ "version": "0.5.6",
5
5
  "description": "A text markup language for documentation",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -946,4 +946,101 @@ describe('Markdown parser', function () {
946
946
  expect(example.children[0].errors[0].id).toEqual('missing-closing');
947
947
  });
948
948
  });
949
+
950
+ describe('table parsing', function () {
951
+ function setupTableDoc(rows: string[]) {
952
+ return `
953
+ {% table %}
954
+ - column 1
955
+ - column 2
956
+ ---
957
+ ${rows.join('\n')}
958
+ {% /table %}
959
+ `;
960
+ }
961
+
962
+ it('should preserve default if tag during table parsing without extra parser args', function () {
963
+ const document = setupTableDoc([
964
+ `
965
+ {% if $fakeCondition.condition1 %}
966
+ - cell 1
967
+ - cell 2
968
+ {% else /%}
969
+ - cell 3
970
+ - cell 4
971
+ {% /if %}
972
+ `,
973
+ ]);
974
+
975
+ const parsedDoc = convert(document);
976
+ const tags = [...parsedDoc.walk()]
977
+ .filter((node) => node.type === 'tag')
978
+ .map((node) => node.tag);
979
+
980
+ expect(tags).toContain('if');
981
+ });
982
+
983
+ it('should not preserve unregistered tags during table parsing without extra parser args', function () {
984
+ const document = setupTableDoc([
985
+ `
986
+ {% if-pref conditions=[{platform: 'web'}] %}
987
+ - cell 1
988
+ - cell 2
989
+ {% /if-pref %}
990
+ {% if-pref conditions=[{platform: 'ios'}] %}
991
+ - cell 1
992
+ - cell 2
993
+ {% /if-pref %}
994
+ `,
995
+ ]);
996
+
997
+ const parsedDoc = convert(document);
998
+ const tags = [...parsedDoc.walk()]
999
+ .filter((node) => node.type === 'tag')
1000
+ .map((node) => node.tag);
1001
+
1002
+ expect(tags).not.toContain('if-pref');
1003
+ });
1004
+
1005
+ it('should preserve all registered tags and ignore unregistered tags during table parsing with extra parser args', function () {
1006
+ const document = setupTableDoc([
1007
+ `
1008
+ {% if-pref conditions=[{platform: 'web'}] %}
1009
+ - cell 1
1010
+ - cell 2
1011
+ {% /if-pref %}
1012
+ {% if-pref conditions=[{platform: 'ios'}] %}
1013
+ - cell 1
1014
+ - cell 2
1015
+ {% /if-pref %}
1016
+ `,
1017
+ `
1018
+ {% if $fakeCondition.condition1 %}
1019
+ - cell 1
1020
+ - cell 2
1021
+ {% else /%}
1022
+ - cell 3
1023
+ - cell 4
1024
+ {% /if %}
1025
+ `,
1026
+ `
1027
+ {% unregistered-if-tag $fakeCondition.condition2 %}
1028
+ - cell 1
1029
+ - cell 2
1030
+ {% /unregistered-if-tag %}
1031
+ `,
1032
+ ]);
1033
+
1034
+ const parsedDoc = convert(document, {
1035
+ conditionalTags: ['if', 'if-pref'],
1036
+ });
1037
+ const tags = [...parsedDoc.walk()]
1038
+ .filter((node) => node.type === 'tag')
1039
+ .map((node) => node.tag);
1040
+
1041
+ expect(tags).toContain('if');
1042
+ expect(tags).toContain('if-pref');
1043
+ expect(tags).not.toContain('unregistered-if-tag');
1044
+ });
1045
+ });
949
1046
  });
package/src/parser.ts CHANGED
@@ -213,7 +213,7 @@ export default function parser(tokens: Token[], args?: string | ParserArgs) {
213
213
  message: `Node '${node.tag || node.type}' is missing closing`,
214
214
  });
215
215
 
216
- for (const transform of transforms) transform(doc);
216
+ for (const transform of transforms) transform(doc, args?.conditionalTags);
217
217
 
218
218
  return doc;
219
219
  }
@@ -0,0 +1,202 @@
1
+ import Markdoc from '../../index';
2
+
3
+ function validate(string: string, config = {}) {
4
+ return Markdoc.validate(Markdoc.parse(string), config);
5
+ }
6
+
7
+ describe('table transform validation', function () {
8
+ it('produces an error for non-row content at the row level of a table', function () {
9
+ const input = `{% table %}
10
+ * Heading 1
11
+ * Heading 2
12
+ ---
13
+ * Cell 1
14
+ * Cell 2
15
+ {% if $foo %}
16
+ This is invalid conditional content at the row level of the table.
17
+ {% /if %}
18
+ This is invalid non-conditional content at the row level.
19
+ {% /table %}`;
20
+
21
+ const errors = validate(input);
22
+ const tableSyntaxErrors = errors.filter(
23
+ (e) => e.error.id === 'table-syntax'
24
+ );
25
+
26
+ // One error for the paragraph inside the conditional (on the if tag),
27
+ // one for the bare paragraph (on the table tag since the node is discarded)
28
+ expect(tableSyntaxErrors.length).toBe(2);
29
+ for (const err of tableSyntaxErrors) {
30
+ expect(err.error.level).toBe('critical');
31
+ expect(err.error.message).toContain('paragraph');
32
+ expect(err.error.message).toContain('indented');
33
+ }
34
+
35
+ // The conditional error should point to the {% if %} tag, not the table
36
+ const conditionalError = tableSyntaxErrors.find(
37
+ (e) => e.type === 'tag' && e.location?.start.line !== 0
38
+ );
39
+ expect(conditionalError).toBeDefined();
40
+ expect(conditionalError?.location?.start.line).toBeGreaterThan(0);
41
+
42
+ // The row-level error should point to the table tag (paragraph is discarded)
43
+ const rowLevelError = tableSyntaxErrors.find(
44
+ (e) => e.location?.start.line === 0
45
+ );
46
+ expect(rowLevelError).toBeDefined();
47
+ });
48
+
49
+ it('does not produce errors for valid conditional rows', function () {
50
+ const input = `{% table %}
51
+ * Heading 1
52
+ * Heading 2
53
+ ---
54
+ {% if $foo %}
55
+ * Row 1 Cell 1
56
+ * Row 1 Cell 2
57
+ {% /if %}
58
+ ---
59
+ {% if $bar %}
60
+ * Row 2 Cell 1
61
+ * Row 2 Cell 2
62
+ {% else /%}
63
+ * Alt Row 2 Cell 1
64
+ * Alt Row 2 Cell 2
65
+ {% /if %}
66
+ {% /table %}`;
67
+
68
+ const errors = validate(input);
69
+ const tableSyntaxErrors = errors.filter(
70
+ (e) => e.error.id === 'table-syntax'
71
+ );
72
+
73
+ expect(tableSyntaxErrors).toEqual([]);
74
+ });
75
+
76
+ it('does not produce errors for valid conditionals within a cell', function () {
77
+ const input = `{% table %}
78
+ * Heading 1
79
+ * Heading 2
80
+ ---
81
+ * Cell 1
82
+ * Cell 2
83
+ {% if $foo %}
84
+ This is a conditional paragraph inside cell 2.
85
+ {% else /%}
86
+ This is an alternate paragraph inside cell 2.
87
+ {% /if %}
88
+ {% /table %}`;
89
+
90
+ const errors = validate(input);
91
+ const tableSyntaxErrors = errors.filter(
92
+ (e) => e.error.id === 'table-syntax'
93
+ );
94
+
95
+ expect(tableSyntaxErrors).toEqual([]);
96
+ });
97
+
98
+ it('does not produce errors for valid conditional with multiple rows and hr separators', function () {
99
+ const input = `{% table %}
100
+ * Heading 1
101
+ * Heading 2
102
+ ---
103
+ {% if $foo %}
104
+ * Row 1 Cell 1
105
+ * Row 1 Cell 2
106
+ ---
107
+ * Row 2 Cell 1
108
+ * Row 2 Cell 2
109
+ {% /if %}
110
+ {% /table %}`;
111
+
112
+ const errors = validate(input);
113
+ const tableSyntaxErrors = errors.filter(
114
+ (e) => e.error.id === 'table-syntax'
115
+ );
116
+
117
+ expect(tableSyntaxErrors).toEqual([]);
118
+ });
119
+
120
+ it('does not produce errors for comments in a table', function () {
121
+ function validateWithComments(string: string, config = {}) {
122
+ const tokenizer = new Markdoc.Tokenizer({ allowComments: true });
123
+ const tokens = tokenizer.tokenize(string);
124
+ return Markdoc.validate(Markdoc.parse(tokens), config);
125
+ }
126
+ const input = `{% table %}
127
+ * Heading 1
128
+ * Heading 2
129
+ ---
130
+ {% comment %}
131
+ comment row
132
+ {% /comment %}
133
+ * Cell 1
134
+ * Cell 2
135
+ ---
136
+ {% if $foo %}
137
+ {% comment %}
138
+ comment inside conditional
139
+ {% /comment %}
140
+ * Row Cell 1
141
+ * Row Cell 2
142
+ {% /if %}
143
+ {% /table %}`;
144
+
145
+ const errors = validateWithComments(input);
146
+ const tableSyntaxErrors = errors.filter(
147
+ (e) => e.error.id === 'table-syntax'
148
+ );
149
+
150
+ expect(tableSyntaxErrors).toEqual([]);
151
+ });
152
+
153
+ it('produces an error for invalid tags inside a table conditional', function () {
154
+ const input = `{% table %}
155
+ * Heading 1
156
+ * Heading 2
157
+ ---
158
+ {% if $foo %}
159
+ {% callout %}
160
+ This is not a valid row
161
+ {% /callout %}
162
+ {% /if %}
163
+ {% /table %}`;
164
+
165
+ const config = {
166
+ tags: { callout: { render: 'div' } },
167
+ };
168
+
169
+ const errors = validate(input, config);
170
+ const tableSyntaxErrors = errors.filter(
171
+ (e) => e.error.id === 'table-syntax'
172
+ );
173
+
174
+ expect(tableSyntaxErrors.length).toBe(1);
175
+ expect(tableSyntaxErrors[0].error.level).toBe('critical');
176
+ expect(tableSyntaxErrors[0].error.message).toContain('tag callout');
177
+ });
178
+
179
+ it('produces an error for non-conditional tags at the row level of a table', function () {
180
+ const input = `{% table %}
181
+ * Heading 1
182
+ * Heading 2
183
+ ---
184
+ {% callout %}
185
+ This is not a valid row
186
+ {% /callout %}
187
+ {% /table %}`;
188
+
189
+ const config = {
190
+ tags: { callout: { render: 'div' } },
191
+ };
192
+
193
+ const errors = validate(input, config);
194
+ const tableSyntaxErrors = errors.filter(
195
+ (e) => e.error.id === 'table-syntax'
196
+ );
197
+
198
+ expect(tableSyntaxErrors.length).toBe(1);
199
+ expect(tableSyntaxErrors[0].error.level).toBe('critical');
200
+ expect(tableSyntaxErrors[0].error.message).toContain('tag');
201
+ });
202
+ });
@@ -1,6 +1,6 @@
1
1
  import Ast from '../ast/index';
2
2
 
3
- import type { Node, NodeType } from '../types';
3
+ import type { Node, NodeType, ValidationError } from '../types';
4
4
 
5
5
  function convertToRow(node: Node, cellType: NodeType = 'td') {
6
6
  node.type = 'tr';
@@ -11,7 +11,38 @@ function convertToRow(node: Node, cellType: NodeType = 'td') {
11
11
  return node;
12
12
  }
13
13
 
14
- export default function transform(document: Node) {
14
+ function isConditionalTag(node: Node, conditionalTags: string[]) {
15
+ return (
16
+ node.type === 'tag' && !!node.tag && conditionalTags.includes(node.tag)
17
+ );
18
+ }
19
+
20
+ function isComment(node: Node) {
21
+ return (
22
+ node.type === 'comment' || (node.type === 'tag' && node.tag === 'comment')
23
+ );
24
+ }
25
+
26
+ function unexpectedNodeError({
27
+ type,
28
+ tag,
29
+ }: {
30
+ type: NodeType;
31
+ tag?: string;
32
+ }): ValidationError {
33
+ return {
34
+ id: 'table-syntax',
35
+ level: 'critical',
36
+ message: `Found ${type}${
37
+ tag ? ` ${tag}` : ''
38
+ } where a list was expected. Make sure all content inside table cells is indented.`,
39
+ };
40
+ }
41
+
42
+ export default function transform(
43
+ document: Node,
44
+ conditionalTags: string[] = ['if']
45
+ ) {
15
46
  for (const node of document.walk()) {
16
47
  if (node.type !== 'tag' || node.tag !== 'table') continue;
17
48
 
@@ -31,17 +62,32 @@ export default function transform(document: Node) {
31
62
  // Convert lists to rows with special-case support for conditionals
32
63
  // When a conditional is encountered, convert all of its top-level lists to rows
33
64
  if (row.type === 'list') convertToRow(row);
34
- else if (row.type === 'tag' && row.tag === 'if') {
65
+ else if (isConditionalTag(row, conditionalTags)) {
35
66
  const children = [];
36
67
 
37
68
  for (const child of row.children) {
38
69
  // Replace children and skip HRs in order to support conditionals with multiple rows
39
70
  if (child.type === 'hr') continue;
40
71
  if (child.type === 'list') convertToRow(child);
72
+ else if (
73
+ isComment(child) ||
74
+ child.tag === 'else' ||
75
+ isConditionalTag(child, conditionalTags)
76
+ ) {
77
+ // Allow structural tags: else, nested conditionals, and comments
78
+ } else {
79
+ row.errors.push(
80
+ unexpectedNodeError({ type: child.type, tag: child.tag })
81
+ );
82
+ continue;
83
+ }
41
84
  children.push(child);
42
85
  }
43
86
 
44
87
  row.children = children;
88
+ } else if (row.type !== 'hr' && !isComment(row)) {
89
+ node.errors.push(unexpectedNodeError({ type: row.type, tag: row.tag }));
90
+ continue;
45
91
  } else continue;
46
92
  tbody.push(row);
47
93
  }
package/src/types.ts CHANGED
@@ -170,4 +170,9 @@ export type ParserArgs = {
170
170
  file?: string;
171
171
  slots?: boolean;
172
172
  location?: boolean;
173
+ // A list of tags that are allowed to wrap table body content.
174
+ // During table transformation, these tags are kept as wrappers in tbody.
175
+ // Tags not in this list that appear between table rows are dropped, which prevents arbitrary custom components from wrapping rows in ways that could produce invalid HTML.
176
+ // @default ['if'] - By default, only the markdoc native conditional tag (`if`) is set
177
+ conditionalTags?: string[];
173
178
  };