@markdoc/markdoc 0.1.0 → 0.1.3
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 +6 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -16
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +47 -16
- package/dist/index.mjs.map +2 -2
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -1
- package/dist/src/types.d.ts +4 -5
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/global.d.ts +7 -0
- package/index.ts +3 -0
- package/package.json +5 -4
- package/src/parser.test.ts +42 -0
- package/src/parser.ts +28 -2
- package/src/schema.ts +1 -0
- package/src/tokenizer/plugins/annotations.test.ts +60 -0
- package/src/tokenizer/plugins/annotations.ts +4 -0
- package/src/transforms/table.ts +1 -1
- package/src/types.ts +4 -5
- package/src/utils.test.ts +15 -2
- package/src/utils.ts +10 -1
- package/src/validator.test.ts +10 -10
- package/src/validator.ts +11 -11
package/dist/src/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;AAK9B,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;AAK9B,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAiK/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,QAiB5D"}
|
package/dist/src/schema.d.ts.map
CHANGED
|
@@ -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,MAgBtB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAYrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAGvB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,
|
|
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,MAgBtB,CAAC;AAEF,eAAO,MAAM,OAAO,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,MAYlB,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,MAMhB,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,MAGpB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,MAGhB,CAAC;AAEF,eAAO,MAAM,CAAC,EAAE,MAGf,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAapB,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,KAAK,IAAK,CAAC"}
|
|
@@ -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;
|
|
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"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import type Func from './ast/function';
|
|
1
2
|
import type Node from './ast/node';
|
|
2
|
-
import type Function from './ast/function';
|
|
3
3
|
import type Tag from './ast/tag';
|
|
4
|
-
export type {
|
|
5
|
-
export type
|
|
6
|
-
export type { default as Tag } from './ast/tag';
|
|
4
|
+
export type { Node, Tag };
|
|
5
|
+
export declare type Function = Func;
|
|
7
6
|
export interface AstType {
|
|
8
7
|
readonly $$mdtype: 'Function' | 'Node' | 'Variable';
|
|
9
8
|
resolve(config: Config): any;
|
|
@@ -28,7 +27,7 @@ export declare type ConfigFunction = {
|
|
|
28
27
|
returns?: ValidationType | ValidationType[];
|
|
29
28
|
parameters?: Record<string, SchemaAttribute>;
|
|
30
29
|
transform?(parameters: Record<string, any>, config: Config): any;
|
|
31
|
-
validate?(fn:
|
|
30
|
+
validate?(fn: Func, config: Config): ValidationError[];
|
|
32
31
|
};
|
|
33
32
|
export interface CustomAttributeTypeInterface {
|
|
34
33
|
transform?(value: any, config: Config): Scalar;
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,
|
|
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,WAAW,CAAC;AAEjC,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAC1B,MAAM,CAAC,OAAO,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEpC,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;IACpD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC;CAC9B;AAED,oBAAY,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,oBAAY,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;AAE1C,oBAAY,UAAU,GAAG,OAAO,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IACzC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1C,QAAQ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,eAAe,CAAC,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF,oBAAY,aAAa,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;AAErD,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"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type Token from 'markdown-it/lib/token';
|
|
2
2
|
export declare const OPEN = "{%";
|
|
3
3
|
export declare const CLOSE = "%}";
|
|
4
|
-
export declare function findTagEnd(content: string, start?: number): number |
|
|
4
|
+
export declare function findTagEnd(content: string, start?: number): number | null;
|
|
5
5
|
export declare function parseTags(content: string, firstLine?: number): Token[];
|
|
6
6
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAQ/C,eAAO,MAAM,IAAI,OAAO,CAAC;AACzB,eAAO,MAAM,KAAK,OAAO,CAAC;AAE1B,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAI,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAQ/C,eAAO,MAAM,IAAI,OAAO,CAAC;AACzB,eAAO,MAAM,KAAK,OAAO,CAAC;AAE1B,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAI,iBA0BpD;AAoBD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,KAAK,EAAE,CA+DjE"}
|
package/global.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Delimiter } from 'markdown-it/lib/rules_inline/state_inline';
|
|
1
2
|
import type { ValidationError } from './src/types';
|
|
2
3
|
|
|
3
4
|
declare module 'markdown-it/lib/token' {
|
|
@@ -9,3 +10,9 @@ declare module 'markdown-it/lib/token' {
|
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
12
|
}
|
|
13
|
+
|
|
14
|
+
declare module 'markdown-it/lib/rules_block/state_block' {
|
|
15
|
+
export default class Token extends require('markdown-it/lib/rules_block/state_block') {
|
|
16
|
+
delimiters?: Delimiter[];
|
|
17
|
+
}
|
|
18
|
+
}
|
package/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import Tag from './src/ast/tag';
|
|
|
5
5
|
import Ast from './src/ast/index';
|
|
6
6
|
import * as nodes from './src/schema';
|
|
7
7
|
import tags from './src/tags/index';
|
|
8
|
+
import { truthy } from './src/tags/conditional';
|
|
8
9
|
import functions from './src/functions/index';
|
|
9
10
|
import renderers from './src/renderers/index';
|
|
10
11
|
import transformer from './src/transformer';
|
|
@@ -121,6 +122,7 @@ export default {
|
|
|
121
122
|
transform,
|
|
122
123
|
validate,
|
|
123
124
|
createElement,
|
|
125
|
+
truthy,
|
|
124
126
|
};
|
|
125
127
|
|
|
126
128
|
export {
|
|
@@ -135,4 +137,5 @@ export {
|
|
|
135
137
|
parseTags,
|
|
136
138
|
transformer,
|
|
137
139
|
validator,
|
|
140
|
+
truthy,
|
|
138
141
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdoc/markdoc",
|
|
3
3
|
"author": "Ryan Paul",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"description": "A text markup language for documentation",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -17,16 +17,17 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"test": "node -r ts-eager/register ./node_modules/.bin/jasmine",
|
|
19
19
|
"marktest": "node -r ts-eager/register ${INSPECT:+--inspect-brk} spec/marktest/index.ts spec/marktest/tests.yaml",
|
|
20
|
+
"prebuild": "npx patch-package",
|
|
20
21
|
"build": "npm run build:common && npm run build:types",
|
|
21
22
|
"build:common": "node build.js",
|
|
22
23
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
23
24
|
"lint": "eslint .",
|
|
24
|
-
"grammar": "pegjs -o src/grammar/tag.js src/grammar/tag.pegjs
|
|
25
|
+
"grammar": "pegjs -o src/grammar/tag.js src/grammar/tag.pegjs",
|
|
26
|
+
"postgrammar": "prettier --write src/grammar/tag.js",
|
|
25
27
|
"prettier": "prettier --write index.ts src spec",
|
|
26
28
|
"prettier:check": "prettier --check index.ts src spec",
|
|
27
29
|
"type:check": "tsc --noEmit",
|
|
28
|
-
"typedoc": "typedoc index.ts --includeVersion --readme none --excludePrivate --excludeExternals --excludeInternal --sort source-order --out types"
|
|
29
|
-
"postinstall": "patch-package"
|
|
30
|
+
"typedoc": "typedoc index.ts --includeVersion --readme none --excludePrivate --excludeExternals --excludeInternal --sort source-order --out types"
|
|
30
31
|
},
|
|
31
32
|
"engines": {
|
|
32
33
|
"node": ">=14.7.0"
|
package/src/parser.test.ts
CHANGED
|
@@ -86,6 +86,15 @@ describe('Markdown parser', function () {
|
|
|
86
86
|
expect(link.attributes).toDeepEqual({ href: '/bar' });
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
+
it('for link with one word and a title', function () {
|
|
90
|
+
const document = convert(`
|
|
91
|
+
[foo](/bar "title")
|
|
92
|
+
`);
|
|
93
|
+
|
|
94
|
+
const link = document.children[0].children[0].children[0];
|
|
95
|
+
expect(link.attributes).toDeepEqual({ href: '/bar', title: 'title' });
|
|
96
|
+
});
|
|
97
|
+
|
|
89
98
|
it('for link', function () {
|
|
90
99
|
const document = convert(`
|
|
91
100
|
[this is a test](/bar)
|
|
@@ -137,6 +146,39 @@ describe('Markdown parser', function () {
|
|
|
137
146
|
content: 'This is a test\n',
|
|
138
147
|
});
|
|
139
148
|
});
|
|
149
|
+
|
|
150
|
+
it('for image with no title', function () {
|
|
151
|
+
const document = convert(``);
|
|
152
|
+
const image = document.children[0].children[0].children[0];
|
|
153
|
+
expect(image.attributes.title).toBe(undefined);
|
|
154
|
+
expect(image.attributes.src).toBe('/url');
|
|
155
|
+
expect(image.attributes.alt).toBe('foo');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('for image with a title', function () {
|
|
159
|
+
const document = convert(``);
|
|
160
|
+
const image = document.children[0].children[0].children[0];
|
|
161
|
+
expect(image.attributes.title).toBe('title');
|
|
162
|
+
expect(image.attributes.src).toBe('/url');
|
|
163
|
+
expect(image.attributes.alt).toBe('foo');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('for table with alignments', function () {
|
|
167
|
+
const document = convert(`
|
|
168
|
+
| Left | Center | Right |
|
|
169
|
+
| :--- | :----: | ----: |
|
|
170
|
+
| Left | Center | Right |
|
|
171
|
+
`);
|
|
172
|
+
const [thead, tbody] = document.children[0].children;
|
|
173
|
+
|
|
174
|
+
expect(thead.children[0].children[0].attributes.align).toBe('left');
|
|
175
|
+
expect(thead.children[0].children[1].attributes.align).toBe('center');
|
|
176
|
+
expect(thead.children[0].children[2].attributes.align).toBe('right');
|
|
177
|
+
|
|
178
|
+
expect(tbody.children[0].children[0].attributes.align).toBe('left');
|
|
179
|
+
expect(tbody.children[0].children[1].attributes.align).toBe('center');
|
|
180
|
+
expect(tbody.children[0].children[2].attributes.align).toBe('right');
|
|
181
|
+
});
|
|
140
182
|
});
|
|
141
183
|
|
|
142
184
|
it('handling a header', function () {
|
package/src/parser.ts
CHANGED
|
@@ -29,11 +29,15 @@ function handleAttrs(token: Token, type: string) {
|
|
|
29
29
|
return { ordered: token.type.startsWith('ordered') };
|
|
30
30
|
case 'link': {
|
|
31
31
|
const attrs = Object.fromEntries(token.attrs);
|
|
32
|
-
return
|
|
32
|
+
return attrs.title
|
|
33
|
+
? { href: attrs.href, title: attrs.title }
|
|
34
|
+
: { href: attrs.href };
|
|
33
35
|
}
|
|
34
36
|
case 'image': {
|
|
35
37
|
const attrs = Object.fromEntries(token.attrs);
|
|
36
|
-
return
|
|
38
|
+
return attrs.title
|
|
39
|
+
? { alt: token.content, src: attrs.src, title: attrs.title }
|
|
40
|
+
: { alt: token.content, src: attrs.src };
|
|
37
41
|
}
|
|
38
42
|
case 'text':
|
|
39
43
|
case 'code':
|
|
@@ -44,6 +48,28 @@ function handleAttrs(token: Token, type: string) {
|
|
|
44
48
|
? { content: token.content }
|
|
45
49
|
: { content: token.content, language };
|
|
46
50
|
}
|
|
51
|
+
case 'td':
|
|
52
|
+
case 'th': {
|
|
53
|
+
if (token.attrs) {
|
|
54
|
+
const attrs = Object.fromEntries(token.attrs);
|
|
55
|
+
|
|
56
|
+
let align;
|
|
57
|
+
if (attrs.style) {
|
|
58
|
+
if (attrs.style.includes('left')) {
|
|
59
|
+
align = 'left';
|
|
60
|
+
} else if (attrs.style.includes('center')) {
|
|
61
|
+
align = 'center';
|
|
62
|
+
} else if (attrs.style.includes('right')) {
|
|
63
|
+
align = 'right';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (align) {
|
|
68
|
+
return { align };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
47
73
|
default:
|
|
48
74
|
return {};
|
|
49
75
|
}
|
package/src/schema.ts
CHANGED
|
@@ -280,6 +280,66 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
280
280
|
]);
|
|
281
281
|
});
|
|
282
282
|
});
|
|
283
|
+
|
|
284
|
+
describe('fence', function () {
|
|
285
|
+
it('simple with no tags', function () {
|
|
286
|
+
const example = parse('```\nhello\n```');
|
|
287
|
+
expect(example).toDeepEqualSubset([
|
|
288
|
+
{
|
|
289
|
+
type: 'fence',
|
|
290
|
+
children: [
|
|
291
|
+
{
|
|
292
|
+
type: 'text',
|
|
293
|
+
content: 'hello\n',
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
},
|
|
297
|
+
]);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('simple with one tag', function () {
|
|
301
|
+
const example = parse('```\nhello {% foo %}bar{% /foo %}\n```');
|
|
302
|
+
expect(example).toDeepEqualSubset([
|
|
303
|
+
{
|
|
304
|
+
type: 'fence',
|
|
305
|
+
children: [
|
|
306
|
+
{
|
|
307
|
+
type: 'text',
|
|
308
|
+
content: 'hello ',
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
type: 'tag_open',
|
|
312
|
+
info: '{% foo %}',
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
type: 'text',
|
|
316
|
+
content: 'bar',
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
type: 'tag_close',
|
|
320
|
+
info: '{% /foo %}',
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
},
|
|
324
|
+
]);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('unclosed tag', function () {
|
|
328
|
+
const example = parse('```\nhello {%\n```');
|
|
329
|
+
// unclosed tags should not result in crashes
|
|
330
|
+
expect(example).toDeepEqualSubset([
|
|
331
|
+
{
|
|
332
|
+
type: 'fence',
|
|
333
|
+
children: [
|
|
334
|
+
{
|
|
335
|
+
type: 'text',
|
|
336
|
+
content: 'hello {%\n',
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
},
|
|
340
|
+
]);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
283
343
|
});
|
|
284
344
|
|
|
285
345
|
describe('parsing inline annotations', function () {
|
package/src/transforms/table.ts
CHANGED
|
@@ -31,7 +31,7 @@ export default function transform(document: Node) {
|
|
|
31
31
|
// Convert lists to rows with special-case support for conditionals
|
|
32
32
|
// When a conditional is encountered, convert all of its top-level lists to rows
|
|
33
33
|
if (row.type === 'list') convertToRow(row);
|
|
34
|
-
else if (row.type === 'tag' && row.tag
|
|
34
|
+
else if (row.type === 'tag' && row.tag === 'if') {
|
|
35
35
|
const children = [];
|
|
36
36
|
|
|
37
37
|
for (const child of row.children) {
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import type Func from './ast/function';
|
|
1
2
|
import type Node from './ast/node';
|
|
2
|
-
import type Function from './ast/function';
|
|
3
3
|
import type Tag from './ast/tag';
|
|
4
4
|
|
|
5
|
-
export type {
|
|
6
|
-
export type
|
|
7
|
-
export type { default as Tag } from './ast/tag';
|
|
5
|
+
export type { Node, Tag };
|
|
6
|
+
export declare type Function = Func;
|
|
8
7
|
|
|
9
8
|
export interface AstType {
|
|
10
9
|
readonly $$mdtype: 'Function' | 'Node' | 'Variable';
|
|
@@ -34,7 +33,7 @@ export type ConfigFunction = {
|
|
|
34
33
|
returns?: ValidationType | ValidationType[];
|
|
35
34
|
parameters?: Record<string, SchemaAttribute>;
|
|
36
35
|
transform?(parameters: Record<string, any>, config: Config): any;
|
|
37
|
-
validate?(fn:
|
|
36
|
+
validate?(fn: Func, config: Config): ValidationError[];
|
|
38
37
|
};
|
|
39
38
|
|
|
40
39
|
export interface CustomAttributeTypeInterface {
|
package/src/utils.test.ts
CHANGED
|
@@ -165,9 +165,22 @@ describe('Templating', function () {
|
|
|
165
165
|
example=1 another="test}"}
|
|
166
166
|
`;
|
|
167
167
|
|
|
168
|
-
const end = findTagEnd(example, 0
|
|
169
|
-
expect(end).toEqual(
|
|
168
|
+
const end = findTagEnd(example, 0);
|
|
169
|
+
expect(end).toEqual(null);
|
|
170
170
|
});
|
|
171
171
|
});
|
|
172
|
+
it("shouldn't hang when {% is included in code block", () => {
|
|
173
|
+
const example = '```\n{%a %b %c}\n```';
|
|
174
|
+
|
|
175
|
+
const output = parseTags(example);
|
|
176
|
+
expect(output).toEqual([
|
|
177
|
+
{
|
|
178
|
+
type: 'text',
|
|
179
|
+
start: 0,
|
|
180
|
+
end: 17,
|
|
181
|
+
content: '```\n{%a %b %c}\n```',
|
|
182
|
+
},
|
|
183
|
+
]);
|
|
184
|
+
});
|
|
172
185
|
});
|
|
173
186
|
});
|
package/src/utils.ts
CHANGED
|
@@ -37,6 +37,8 @@ export function findTagEnd(content: string, start = 0) {
|
|
|
37
37
|
else if (content.startsWith(CLOSE, pos)) return pos;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
return null;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
function parseTag(content: string, line: number, contentStart: number) {
|
|
@@ -70,7 +72,14 @@ export function parseTags(content: string, firstLine = 0): Token[] {
|
|
|
70
72
|
|
|
71
73
|
if (!content.startsWith(OPEN, pos)) continue;
|
|
72
74
|
|
|
73
|
-
const end = findTagEnd(content, pos)
|
|
75
|
+
const end = findTagEnd(content, pos);
|
|
76
|
+
|
|
77
|
+
if (end == null) {
|
|
78
|
+
// If we cannot find the closing tag, we skip over it
|
|
79
|
+
pos = pos + OPEN.length;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
74
83
|
const text = content.slice(pos, end + CLOSE.length);
|
|
75
84
|
const inner = content.slice(pos + OPEN.length, end);
|
|
76
85
|
const lineStart = content.lastIndexOf('\n', pos);
|
package/src/validator.test.ts
CHANGED
|
@@ -24,7 +24,7 @@ describe('validate', function () {
|
|
|
24
24
|
{
|
|
25
25
|
error: {
|
|
26
26
|
id: 'function-undefined',
|
|
27
|
-
message: "Undefined function 'baz'",
|
|
27
|
+
message: "Undefined function: 'baz'",
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
]);
|
|
@@ -79,7 +79,7 @@ describe('validate', function () {
|
|
|
79
79
|
{
|
|
80
80
|
error: {
|
|
81
81
|
id: 'attribute-type-invalid',
|
|
82
|
-
message: "Attribute 'baz' must be type 'Boolean'",
|
|
82
|
+
message: "Attribute 'baz' must be type of 'Boolean'",
|
|
83
83
|
},
|
|
84
84
|
},
|
|
85
85
|
]);
|
|
@@ -94,13 +94,13 @@ describe('validate', function () {
|
|
|
94
94
|
{
|
|
95
95
|
error: {
|
|
96
96
|
id: 'parameter-type-invalid',
|
|
97
|
-
message: "Parameter '0' of 'nested' must be type 'String'",
|
|
97
|
+
message: "Parameter '0' of 'nested' must be type of 'String'",
|
|
98
98
|
},
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
101
|
error: {
|
|
102
102
|
id: 'parameter-type-invalid',
|
|
103
|
-
message: "Parameter '1' of 'nested' must be type 'Number'",
|
|
103
|
+
message: "Parameter '1' of 'nested' must be type of 'Number'",
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
106
|
]);
|
|
@@ -173,7 +173,7 @@ describe('validate', function () {
|
|
|
173
173
|
{
|
|
174
174
|
error: {
|
|
175
175
|
id: 'parameter-missing-required',
|
|
176
|
-
message: "Missing required parameter 'req'",
|
|
176
|
+
message: "Missing required parameter: 'req'",
|
|
177
177
|
},
|
|
178
178
|
},
|
|
179
179
|
]);
|
|
@@ -199,7 +199,7 @@ describe('validate', function () {
|
|
|
199
199
|
type: 'tag',
|
|
200
200
|
error: {
|
|
201
201
|
id: 'parameter-undefined',
|
|
202
|
-
message: "Invalid parameter 'foo'",
|
|
202
|
+
message: "Invalid parameter: 'foo'",
|
|
203
203
|
},
|
|
204
204
|
},
|
|
205
205
|
]);
|
|
@@ -211,7 +211,7 @@ describe('validate', function () {
|
|
|
211
211
|
type: 'tag',
|
|
212
212
|
error: {
|
|
213
213
|
id: 'parameter-undefined',
|
|
214
|
-
message: "Invalid parameter '0'",
|
|
214
|
+
message: "Invalid parameter: '0'",
|
|
215
215
|
},
|
|
216
216
|
},
|
|
217
217
|
]);
|
|
@@ -223,7 +223,7 @@ describe('validate', function () {
|
|
|
223
223
|
type: 'tag',
|
|
224
224
|
error: {
|
|
225
225
|
id: 'parameter-undefined',
|
|
226
|
-
message: "Invalid parameter '0'",
|
|
226
|
+
message: "Invalid parameter: '0'",
|
|
227
227
|
},
|
|
228
228
|
},
|
|
229
229
|
]);
|
|
@@ -242,7 +242,7 @@ describe('validate', function () {
|
|
|
242
242
|
const error: ValidationError = {
|
|
243
243
|
id: 'attribute-type-invalid',
|
|
244
244
|
level: 'error',
|
|
245
|
-
message: "Attribute 'href' must be type 'Link'",
|
|
245
|
+
message: "Attribute 'href' must be type of 'Link'",
|
|
246
246
|
};
|
|
247
247
|
|
|
248
248
|
return [error];
|
|
@@ -270,7 +270,7 @@ describe('validate', function () {
|
|
|
270
270
|
error: {
|
|
271
271
|
id: 'attribute-type-invalid',
|
|
272
272
|
level: 'error',
|
|
273
|
-
message: "Attribute 'href' must be type 'Link'",
|
|
273
|
+
message: "Attribute 'href' must be type of 'Link'",
|
|
274
274
|
},
|
|
275
275
|
},
|
|
276
276
|
]);
|
package/src/validator.ts
CHANGED
|
@@ -70,7 +70,7 @@ function validateFunction(fn: Function, config: Config): ValidationError[] {
|
|
|
70
70
|
{
|
|
71
71
|
id: 'function-undefined',
|
|
72
72
|
level: 'critical',
|
|
73
|
-
message: `Undefined function '${fn.name}'`,
|
|
73
|
+
message: `Undefined function: '${fn.name}'`,
|
|
74
74
|
},
|
|
75
75
|
];
|
|
76
76
|
|
|
@@ -84,7 +84,7 @@ function validateFunction(fn: Function, config: Config): ValidationError[] {
|
|
|
84
84
|
errors.push({
|
|
85
85
|
id: 'parameter-undefined',
|
|
86
86
|
level: 'error',
|
|
87
|
-
message: `Invalid parameter '${key}'`,
|
|
87
|
+
message: `Invalid parameter: '${key}'`,
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
continue;
|
|
@@ -100,7 +100,7 @@ function validateFunction(fn: Function, config: Config): ValidationError[] {
|
|
|
100
100
|
level: 'error',
|
|
101
101
|
message: `Parameter '${key}' of '${
|
|
102
102
|
fn.name
|
|
103
|
-
}' must be type '${typeToString(param.type)}'`,
|
|
103
|
+
}' must be type of '${typeToString(param.type)}'`,
|
|
104
104
|
});
|
|
105
105
|
} else if (Array.isArray(valid)) {
|
|
106
106
|
errors.push(...valid);
|
|
@@ -114,7 +114,7 @@ function validateFunction(fn: Function, config: Config): ValidationError[] {
|
|
|
114
114
|
errors.push({
|
|
115
115
|
id: 'parameter-missing-required',
|
|
116
116
|
level: 'error',
|
|
117
|
-
message: `Missing required parameter '${key}'`,
|
|
117
|
+
message: `Missing required parameter: '${key}'`,
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
return errors;
|
|
@@ -129,8 +129,8 @@ export default function validate(node: Node, config: Config) {
|
|
|
129
129
|
id: node.tag ? 'tag-undefined' : 'node-undefined',
|
|
130
130
|
level: 'critical',
|
|
131
131
|
message: node.tag
|
|
132
|
-
? `Undefined tag '${node.tag}'`
|
|
133
|
-
: `Undefined node '${node.type}'`,
|
|
132
|
+
? `Undefined tag: '${node.tag}'`
|
|
133
|
+
: `Undefined node: '${node.type}'`,
|
|
134
134
|
});
|
|
135
135
|
|
|
136
136
|
return errors;
|
|
@@ -140,7 +140,7 @@ export default function validate(node: Node, config: Config) {
|
|
|
140
140
|
errors.push({
|
|
141
141
|
id: 'tag-selfclosing-has-children',
|
|
142
142
|
level: 'critical',
|
|
143
|
-
message: `
|
|
143
|
+
message: `'${node.tag}' tag should be self-closing`,
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
const attributes = {
|
|
@@ -157,7 +157,7 @@ export default function validate(node: Node, config: Config) {
|
|
|
157
157
|
errors.push({
|
|
158
158
|
id: 'attribute-undefined',
|
|
159
159
|
level: 'error',
|
|
160
|
-
message: `Invalid attribute '${key}'`,
|
|
160
|
+
message: `Invalid attribute: '${key}'`,
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
continue;
|
|
@@ -176,7 +176,7 @@ export default function validate(node: Node, config: Config) {
|
|
|
176
176
|
errors.push({
|
|
177
177
|
id: 'attribute-value-invalid',
|
|
178
178
|
level: 'error',
|
|
179
|
-
message: 'The
|
|
179
|
+
message: 'The id attribute must not start with a number',
|
|
180
180
|
});
|
|
181
181
|
|
|
182
182
|
if (type) {
|
|
@@ -185,7 +185,7 @@ export default function validate(node: Node, config: Config) {
|
|
|
185
185
|
errors.push({
|
|
186
186
|
id: 'attribute-type-invalid',
|
|
187
187
|
level: errorLevel || 'error',
|
|
188
|
-
message: `Attribute '${key}' must be type '${typeToString(type)}'`,
|
|
188
|
+
message: `Attribute '${key}' must be type of '${typeToString(type)}'`,
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
191
|
if (Array.isArray(valid)) {
|
|
@@ -217,7 +217,7 @@ export default function validate(node: Node, config: Config) {
|
|
|
217
217
|
errors.push({
|
|
218
218
|
id: 'attribute-missing-required',
|
|
219
219
|
level: 'error',
|
|
220
|
-
message: `Missing required attribute '${key}'`,
|
|
220
|
+
message: `Missing required attribute: '${key}'`,
|
|
221
221
|
});
|
|
222
222
|
|
|
223
223
|
for (const { type } of node.children) {
|