@markdoc/markdoc 0.1.4 → 0.1.7
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/dist/index.d.ts +14 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6787 -6409
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +6787 -6409
- package/dist/index.mjs.map +3 -3
- package/dist/src/ast/base.d.ts +2 -1
- package/dist/src/ast/base.d.ts.map +1 -1
- package/dist/src/ast/index.d.ts +1 -0
- package/dist/src/ast/index.d.ts.map +1 -1
- package/dist/src/ast/node.d.ts +4 -4
- package/dist/src/ast/node.d.ts.map +1 -1
- package/dist/src/formatter.d.ts +10 -0
- package/dist/src/formatter.d.ts.map +1 -0
- package/dist/src/schema.d.ts +1 -0
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/tag.d.ts +9 -0
- package/dist/src/tag.d.ts.map +1 -0
- package/dist/src/tags/conditional.d.ts.map +1 -1
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/transforms/table.d.ts.map +1 -1
- package/dist/src/types.d.ts +7 -5
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/index.ts +12 -9
- package/package.json +2 -1
- package/src/ast/base.ts +5 -0
- package/src/ast/node.test.ts +21 -21
- package/src/ast/node.ts +6 -4
- package/src/formatter.test.ts +475 -0
- package/src/formatter.ts +391 -0
- package/src/schema.ts +3 -2
- package/src/tag.ts +22 -0
- package/src/tags/conditional.ts +10 -3
- package/src/transformer.ts +2 -5
- package/src/transforms/table.ts +2 -2
- package/src/types.ts +25 -20
- package/src/utils.ts +4 -0
- package/src/validator.test.ts +80 -18
- package/src/validator.ts +22 -3
- package/dist/src/ast/tag.d.ts +0 -9
- package/dist/src/ast/tag.d.ts.map +0 -1
- package/src/ast/tag.ts +0 -19
package/src/validator.ts
CHANGED
|
@@ -168,7 +168,26 @@ export default function validate(node: Node, config: Config) {
|
|
|
168
168
|
if (Ast.isAst(value)) {
|
|
169
169
|
if (Ast.isFunction(value) && config.validation?.validateFunctions)
|
|
170
170
|
errors.push(...validateFunction(value, config));
|
|
171
|
-
else
|
|
171
|
+
else if (Ast.isVariable(value) && config.variables) {
|
|
172
|
+
let missing = false;
|
|
173
|
+
let variables = config.variables;
|
|
174
|
+
|
|
175
|
+
for (const key of value.path) {
|
|
176
|
+
if (!Object.prototype.hasOwnProperty.call(variables, key)) {
|
|
177
|
+
missing = true;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
variables = variables[key];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (missing) {
|
|
184
|
+
errors.push({
|
|
185
|
+
id: 'variable-undefined',
|
|
186
|
+
level: 'error',
|
|
187
|
+
message: `Undefined variable: '${value.path.join('.')}'`,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
} else continue;
|
|
172
191
|
}
|
|
173
192
|
|
|
174
193
|
value = value as string;
|
|
@@ -201,14 +220,14 @@ export default function validate(node: Node, config: Config) {
|
|
|
201
220
|
level: errorLevel || 'error',
|
|
202
221
|
message: `Attribute '${key}' must match one of ${JSON.stringify(
|
|
203
222
|
matches
|
|
204
|
-
)}
|
|
223
|
+
)}. Got '${value}' instead.`,
|
|
205
224
|
});
|
|
206
225
|
|
|
207
226
|
if (matches instanceof RegExp && !matches.test(value))
|
|
208
227
|
errors.push({
|
|
209
228
|
id: 'attribute-value-invalid',
|
|
210
229
|
level: errorLevel || 'error',
|
|
211
|
-
message: `Attribute '${key}' must match ${matches}
|
|
230
|
+
message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`,
|
|
212
231
|
});
|
|
213
232
|
}
|
|
214
233
|
|
package/dist/src/ast/tag.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { RenderableTreeNode } from '../types';
|
|
2
|
-
export default class Tag {
|
|
3
|
-
readonly $$mdtype: "Tag";
|
|
4
|
-
name: string;
|
|
5
|
-
attributes: Record<string, any>;
|
|
6
|
-
children: RenderableTreeNode[];
|
|
7
|
-
constructor(name?: string, attributes?: {}, children?: RenderableTreeNode[]);
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=tag.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../src/ast/tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,QAAQ,CAAC,QAAQ,QAAkB;IAEnC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,QAAQ,EAAE,kBAAkB,EAAE,CAAC;gBAG7B,IAAI,SAAQ,EACZ,UAAU,KAAK,EACf,QAAQ,GAAE,kBAAkB,EAAO;CAMtC"}
|
package/src/ast/tag.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { RenderableTreeNode } from '../types';
|
|
2
|
-
|
|
3
|
-
export default class Tag {
|
|
4
|
-
readonly $$mdtype = 'Tag' as const;
|
|
5
|
-
|
|
6
|
-
name: string;
|
|
7
|
-
attributes: Record<string, any>;
|
|
8
|
-
children: RenderableTreeNode[];
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
name = 'div',
|
|
12
|
-
attributes = {},
|
|
13
|
-
children: RenderableTreeNode[] = []
|
|
14
|
-
) {
|
|
15
|
-
this.name = name;
|
|
16
|
-
this.attributes = attributes;
|
|
17
|
-
this.children = children;
|
|
18
|
-
}
|
|
19
|
-
}
|