@markdoc/markdoc 0.1.0
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/LICENSE +21 -0
- package/README.md +75 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7961 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +7959 -0
- package/dist/index.mjs.map +7 -0
- package/dist/react.js +40 -0
- package/dist/react.js.map +7 -0
- package/dist/src/ast/base.d.ts +6 -0
- package/dist/src/ast/base.d.ts.map +1 -0
- package/dist/src/ast/function.d.ts +9 -0
- package/dist/src/ast/function.d.ts.map +1 -0
- package/dist/src/ast/index.d.ts +26 -0
- package/dist/src/ast/index.d.ts.map +1 -0
- package/dist/src/ast/node.d.ts +21 -0
- package/dist/src/ast/node.d.ts.map +1 -0
- package/dist/src/ast/tag.d.ts +9 -0
- package/dist/src/ast/tag.d.ts.map +1 -0
- package/dist/src/ast/variable.d.ts +8 -0
- package/dist/src/ast/variable.d.ts.map +1 -0
- package/dist/src/functions/index.d.ts +11 -0
- package/dist/src/functions/index.d.ts.map +1 -0
- package/dist/src/parser.d.ts +4 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/renderers/html.d.ts +3 -0
- package/dist/src/renderers/html.d.ts.map +1 -0
- package/dist/src/renderers/index.d.ts +10 -0
- package/dist/src/renderers/index.d.ts.map +1 -0
- package/dist/src/renderers/react/react.d.ts +11 -0
- package/dist/src/renderers/react/react.d.ts.map +1 -0
- package/dist/src/renderers/react/shared.d.ts +5 -0
- package/dist/src/renderers/react/shared.d.ts.map +1 -0
- package/dist/src/renderers/react/static.d.ts +3 -0
- package/dist/src/renderers/react/static.d.ts.map +1 -0
- package/dist/src/schema-types/class.d.ts +6 -0
- package/dist/src/schema-types/class.d.ts.map +1 -0
- package/dist/src/schema.d.ts +27 -0
- package/dist/src/schema.d.ts.map +1 -0
- package/dist/src/tags/conditional.d.ts +5 -0
- package/dist/src/tags/conditional.d.ts.map +1 -0
- package/dist/src/tags/index.d.ts +44 -0
- package/dist/src/tags/index.d.ts.map +1 -0
- package/dist/src/tags/partial.d.ts +3 -0
- package/dist/src/tags/partial.d.ts.map +1 -0
- package/dist/src/tags/table.d.ts +3 -0
- package/dist/src/tags/table.d.ts.map +1 -0
- package/dist/src/tokenizer/index.d.ts +10 -0
- package/dist/src/tokenizer/index.d.ts.map +1 -0
- package/dist/src/tokenizer/plugins/annotations.d.ts +3 -0
- package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -0
- package/dist/src/tokenizer/plugins/frontmatter.d.ts +3 -0
- package/dist/src/tokenizer/plugins/frontmatter.d.ts.map +1 -0
- package/dist/src/transformer.d.ts +12 -0
- package/dist/src/transformer.d.ts.map +1 -0
- package/dist/src/transforms/index.d.ts +4 -0
- package/dist/src/transforms/index.d.ts.map +1 -0
- package/dist/src/transforms/table.d.ts +3 -0
- package/dist/src/transforms/table.d.ts.map +1 -0
- package/dist/src/types.d.ts +88 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils.d.ts +6 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/validator.d.ts +6 -0
- package/dist/src/validator.d.ts.map +1 -0
- package/global.d.ts +11 -0
- package/index.ts +138 -0
- package/package.json +63 -0
- package/spec/support/matchers.d.ts +6 -0
- package/src/ast/base.ts +41 -0
- package/src/ast/function.ts +22 -0
- package/src/ast/index.ts +28 -0
- package/src/ast/node.test.ts +307 -0
- package/src/ast/node.ts +71 -0
- package/src/ast/tag.ts +19 -0
- package/src/ast/variable.test.ts +35 -0
- package/src/ast/variable.ts +17 -0
- package/src/functions/index.test.ts +34 -0
- package/src/functions/index.ts +45 -0
- package/src/grammar/tag.d.ts +23 -0
- package/src/grammar/tag.js +1836 -0
- package/src/grammar/tag.pegjs +170 -0
- package/src/grammar/tag.test.ts +364 -0
- package/src/parser.test.ts +597 -0
- package/src/parser.ts +158 -0
- package/src/renderers/html.test.ts +62 -0
- package/src/renderers/html.ts +46 -0
- package/src/renderers/index.ts +5 -0
- package/src/renderers/react/react.test.ts +204 -0
- package/src/renderers/react/react.ts +51 -0
- package/src/renderers/react/shared.ts +16 -0
- package/src/renderers/react/static.ts +52 -0
- package/src/schema-types/class.ts +23 -0
- package/src/schema.ts +233 -0
- package/src/tags/conditional.ts +45 -0
- package/src/tags/index.ts +10 -0
- package/src/tags/partial.ts +33 -0
- package/src/tags/table.ts +5 -0
- package/src/tokenizer/index.ts +21 -0
- package/src/tokenizer/plugins/annotations.test.ts +337 -0
- package/src/tokenizer/plugins/annotations.ts +133 -0
- package/src/tokenizer/plugins/frontmatter.test.ts +86 -0
- package/src/tokenizer/plugins/frontmatter.ts +39 -0
- package/src/transformer.ts +72 -0
- package/src/transforms/index.ts +2 -0
- package/src/transforms/table.ts +51 -0
- package/src/types.ts +142 -0
- package/src/utils.test.ts +173 -0
- package/src/utils.ts +116 -0
- package/src/validator.test.ts +298 -0
- package/src/validator.ts +233 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Variable from './variable';
|
|
2
|
+
|
|
3
|
+
describe('variable', function () {
|
|
4
|
+
const config = {
|
|
5
|
+
variables: {
|
|
6
|
+
foo: {
|
|
7
|
+
bar: 'example',
|
|
8
|
+
baz: [1, { qux: 'value' }, 2],
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
it('basic resolution', function () {
|
|
14
|
+
const example = new Variable(['foo', 'bar']);
|
|
15
|
+
const output = example.resolve(config);
|
|
16
|
+
expect(output).toEqual('example');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('resolution with a number in the path', function () {
|
|
20
|
+
const example = new Variable(['foo', 'baz', 1, 'qux']);
|
|
21
|
+
const output = example.resolve(config);
|
|
22
|
+
expect(output).toEqual('value');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('resolution with a function', function () {
|
|
26
|
+
function variables(path) {
|
|
27
|
+
expect(path).toDeepEqual(['foo', 'bar']);
|
|
28
|
+
return 'example';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const example = new Variable(['foo', 'bar']);
|
|
32
|
+
const output = example.resolve({ variables });
|
|
33
|
+
expect(output).toEqual('example');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Config, AstType } from '../types';
|
|
2
|
+
|
|
3
|
+
export default class Variable implements AstType {
|
|
4
|
+
readonly $$mdtype = 'Variable';
|
|
5
|
+
|
|
6
|
+
path;
|
|
7
|
+
|
|
8
|
+
constructor(path: (string | number)[] = []) {
|
|
9
|
+
this.path = path;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
resolve({ variables }: Config = {}) {
|
|
13
|
+
return variables instanceof Function
|
|
14
|
+
? variables(this.path)
|
|
15
|
+
: this.path.reduce((obj = {}, key) => obj[key], variables);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import functions from './index';
|
|
2
|
+
import Ast from '../ast';
|
|
3
|
+
|
|
4
|
+
describe('built-in functions', function () {
|
|
5
|
+
describe('equals function', function () {
|
|
6
|
+
it('true match with variable', function () {
|
|
7
|
+
const example = new Ast.Function('equals', {
|
|
8
|
+
0: new Ast.Variable(['foo']),
|
|
9
|
+
1: 'bar',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const output = example.resolve({
|
|
13
|
+
functions,
|
|
14
|
+
variables: { foo: 'bar' },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
expect(output).toBeTrue();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('false match with variable', function () {
|
|
21
|
+
const example = new Ast.Function('equals', {
|
|
22
|
+
0: new Ast.Variable(['foo']),
|
|
23
|
+
1: 'bar',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const output = example.resolve({
|
|
27
|
+
functions,
|
|
28
|
+
variables: { foo: 'baz' },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
expect(output).toBeFalse();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ConfigFunction } from '../types';
|
|
2
|
+
import { truthy } from '../tags/conditional';
|
|
3
|
+
|
|
4
|
+
const and: ConfigFunction = {
|
|
5
|
+
transform(parameters) {
|
|
6
|
+
return Object.values(parameters).every((x) => truthy(x));
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const or: ConfigFunction = {
|
|
11
|
+
transform(parameters) {
|
|
12
|
+
return Object.values(parameters).find((x) => truthy(x)) !== undefined;
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const not: ConfigFunction = {
|
|
17
|
+
parameters: {
|
|
18
|
+
0: { required: true },
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
transform(parameters) {
|
|
22
|
+
return !truthy(parameters[0]);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const equals: ConfigFunction = {
|
|
27
|
+
transform(parameters) {
|
|
28
|
+
const values = Object.values(parameters);
|
|
29
|
+
return values.every((v) => v === values[0]);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const debug: ConfigFunction = {
|
|
34
|
+
transform(parameters) {
|
|
35
|
+
return JSON.stringify(parameters[0], null, 2);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const defaultFn: ConfigFunction = {
|
|
40
|
+
transform(parameters) {
|
|
41
|
+
return parameters[0] === undefined ? parameters[1] : parameters[0];
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default { and, or, not, equals, default: defaultFn, debug };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type AstVariable from '../ast/variable';
|
|
2
|
+
import type AstFunction from '../ast/function';
|
|
3
|
+
import type Token from 'markdown-it/lib/token';
|
|
4
|
+
|
|
5
|
+
type astTypes = {
|
|
6
|
+
Variable?: typeof AstVariable;
|
|
7
|
+
Function?: typeof AstFunction;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function parse(input: string, astTypes?: astTypes): Token;
|
|
11
|
+
|
|
12
|
+
type PegLocation = {
|
|
13
|
+
offset: number;
|
|
14
|
+
line: number;
|
|
15
|
+
column: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface SyntaxError extends Error {
|
|
19
|
+
location: {
|
|
20
|
+
start: PegLocation;
|
|
21
|
+
end: PegLocation;
|
|
22
|
+
};
|
|
23
|
+
}
|