@markdoc/markdoc 0.1.3 → 0.1.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.
- package/README.md +1 -1
- package/dist/index.d.ts +48 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6744 -6329
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +6827 -6412
- 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 +5 -4
- package/dist/src/ast/node.d.ts.map +1 -1
- package/dist/src/formatter.d.ts +9 -0
- package/dist/src/formatter.d.ts.map +1 -0
- package/dist/src/parser.d.ts.map +1 -1
- 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/tags/partial.d.ts.map +1 -1
- package/dist/src/tokenizer/index.d.ts.map +1 -1
- package/dist/src/transformer.d.ts +1 -7
- 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 +12 -4
- 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 +47 -29
- package/package.json +3 -2
- package/src/ast/base.ts +5 -0
- package/src/ast/node.test.ts +73 -21
- package/src/ast/node.ts +9 -4
- package/src/formatter.test.ts +404 -0
- package/src/formatter.ts +373 -0
- package/src/parser.ts +5 -1
- package/src/schema.ts +2 -1
- package/src/tag.ts +22 -0
- package/src/tags/conditional.ts +10 -3
- package/src/tags/partial.ts +20 -3
- package/src/tokenizer/index.ts +5 -1
- package/src/transformer.ts +15 -17
- package/src/transforms/table.ts +2 -2
- package/src/types.ts +31 -19
- package/src/utils.ts +4 -0
- package/src/validator.test.ts +60 -0
- package/src/validator.ts +20 -1
- 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.test.ts
CHANGED
|
@@ -295,4 +295,64 @@ describe('validate', function () {
|
|
|
295
295
|
expect(output).toEqual([]);
|
|
296
296
|
});
|
|
297
297
|
});
|
|
298
|
+
|
|
299
|
+
describe('variable validation', () => {
|
|
300
|
+
it('should only validate if the variables config is passed', () => {
|
|
301
|
+
const example = `{% $valid.variable %}`;
|
|
302
|
+
const output = validate(example, {});
|
|
303
|
+
|
|
304
|
+
expect(output).toEqual([]);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('should warn against missing variables', () => {
|
|
308
|
+
const example = `{% $undefinedVariable %}`;
|
|
309
|
+
const output = validate(example, { variables: {} });
|
|
310
|
+
|
|
311
|
+
expect(output).toDeepEqualSubset([
|
|
312
|
+
{
|
|
313
|
+
type: 'text',
|
|
314
|
+
error: {
|
|
315
|
+
id: 'variable-undefined',
|
|
316
|
+
level: 'error',
|
|
317
|
+
message: "Undefined variable: 'undefinedVariable'",
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
]);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('should not warn if variable exists', () => {
|
|
324
|
+
const example = `{% $valid.variable %}`;
|
|
325
|
+
const output = validate(example, {
|
|
326
|
+
variables: { valid: { variable: false } },
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
expect(output).toEqual([]);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('should not error for missing support for code_block', () => {
|
|
334
|
+
const example = ` # https://spec.commonmark.org/0.30/#indented-code-block
|
|
335
|
+
4-space indented code`;
|
|
336
|
+
const output = validate(example, {});
|
|
337
|
+
|
|
338
|
+
expect(output).toEqual([]);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// https://github.com/markdoc/markdoc/issues/122
|
|
342
|
+
it('should validate partial file attributes', () => {
|
|
343
|
+
const example = `{% partial file="non-existent.md" /%}`;
|
|
344
|
+
const output = validate(example, {});
|
|
345
|
+
|
|
346
|
+
expect(output).toDeepEqualSubset([
|
|
347
|
+
{
|
|
348
|
+
type: 'tag',
|
|
349
|
+
error: {
|
|
350
|
+
id: 'attribute-value-invalid',
|
|
351
|
+
level: 'error',
|
|
352
|
+
message:
|
|
353
|
+
"Partial `non-existent.md` not found. The 'file' attribute must be set in `config.partials`",
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
]);
|
|
357
|
+
});
|
|
298
358
|
});
|
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;
|
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
|
-
}
|