@markdoc/markdoc 0.1.6 → 0.1.8
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 +13 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -45
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +108 -45
- package/dist/index.mjs.map +3 -3
- package/dist/src/formatter.d.ts +1 -0
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/schema.d.ts +8 -0
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/tokenizer/index.d.ts +1 -0
- package/dist/src/tokenizer/index.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/comments.d.ts +3 -0
- package/dist/src/tokenizer/plugins/comments.d.ts.map +1 -0
- package/dist/src/types.d.ts +4 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/validator.d.ts +1 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/index.ts +20 -7
- package/package.json +6 -4
- package/src/formatter.test.ts +74 -3
- package/src/formatter.ts +42 -24
- package/src/parser.test.ts +17 -1
- package/src/parser.ts +1 -0
- package/src/schema.ts +9 -1
- package/src/tokenizer/index.ts +7 -1
- package/src/tokenizer/plugins/comments.test.ts +94 -0
- package/src/tokenizer/plugins/comments.ts +51 -0
- package/src/types.ts +4 -3
- package/src/validator.test.ts +72 -15
- package/src/validator.ts +13 -5
package/dist/src/formatter.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAyXF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
|
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;AAsK/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,QAiB5D"}
|
package/dist/src/schema.d.ts
CHANGED
|
@@ -23,6 +23,14 @@ export declare const code: Schema;
|
|
|
23
23
|
export declare const text: Schema;
|
|
24
24
|
export declare const hardbreak: Schema;
|
|
25
25
|
export declare const softbreak: Schema;
|
|
26
|
+
export declare const comment: {
|
|
27
|
+
attributes: {
|
|
28
|
+
content: {
|
|
29
|
+
type: StringConstructor;
|
|
30
|
+
required: boolean;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
26
34
|
export declare const error: {};
|
|
27
35
|
export declare const node: {};
|
|
28
36
|
//# sourceMappingURL=schema.d.ts.map
|
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,
|
|
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,MAiBtB,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,MAcpB,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,OAAO;;;;;;;CAInB,CAAC;AAEF,eAAO,MAAM,KAAK,IAAK,CAAC;AACxB,eAAO,MAAM,IAAI,IAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAIzC,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAE/C,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAa;gBAGzB,MAAM,GAAE,UAAU,CAAC,OAAO,GAAG;QAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;KACpB;IAcR,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE;CAGnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/comments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AA+C9C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAG5C"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type Func from './ast/function';
|
|
2
2
|
import type Node from './ast/node';
|
|
3
|
-
import type
|
|
3
|
+
import type Var from './ast/variable';
|
|
4
4
|
import type Tag from './tag';
|
|
5
|
-
export type { Node, Tag
|
|
5
|
+
export type { Node, Tag };
|
|
6
6
|
export declare type Function = Func;
|
|
7
|
+
export declare type Variable = Var;
|
|
7
8
|
export declare type MaybePromise<T> = T | Promise<T>;
|
|
8
9
|
export interface AstType {
|
|
9
10
|
readonly $$mdtype: 'Function' | 'Node' | 'Variable';
|
|
@@ -61,7 +62,7 @@ export declare type Schema<C extends Config = Config, R = string> = {
|
|
|
61
62
|
attributes?: Record<string, SchemaAttribute>;
|
|
62
63
|
selfClosing?: boolean;
|
|
63
64
|
transform?(node: Node, config: C): MaybePromise<RenderableTreeNodes>;
|
|
64
|
-
validate?(node: Node, config: C): ValidationError[]
|
|
65
|
+
validate?(node: Node, config: C): MaybePromise<ValidationError[]>;
|
|
65
66
|
};
|
|
66
67
|
export declare type SchemaAttribute = {
|
|
67
68
|
type?: ValidationType | ValidationType[];
|
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,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,
|
|
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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M,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;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"}
|
package/dist/src/validator.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Node, Config, SchemaAttribute, ValidationError, Value } from './types';
|
|
2
2
|
declare type TypeParam = NonNullable<SchemaAttribute['type']>;
|
|
3
3
|
export declare function validateType(type: TypeParam, value: Value, config: Config): boolean | ValidationError[];
|
|
4
|
-
export default function
|
|
4
|
+
export default function validator(node: Node, config: Config): ValidationError[] | Promise<ValidationError[]>;
|
|
5
5
|
export {};
|
|
6
6
|
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,IAAI,EAEJ,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAC;AAUjB,aAAK,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,GAAG,eAAe,EAAE,CA2B7B;AAqED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kDAwI3D"}
|
package/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { truthy } from './src/tags/conditional';
|
|
|
10
10
|
import Tokenizer from './src/tokenizer';
|
|
11
11
|
import transformer, { globalAttributes } from './src/transformer';
|
|
12
12
|
import transforms from './src/transforms';
|
|
13
|
-
import { parseTags } from './src/utils';
|
|
13
|
+
import { parseTags, isPromise } from './src/utils';
|
|
14
14
|
import validator from './src/validator';
|
|
15
15
|
|
|
16
16
|
import type { Node } from './src/types';
|
|
@@ -83,20 +83,33 @@ export function transform<C extends Config = Config>(
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export function validate<C extends Config = Config>(
|
|
86
|
-
|
|
86
|
+
node: Node,
|
|
87
|
+
options?: C
|
|
88
|
+
): ValidateError[];
|
|
89
|
+
export function validate<C extends Config = Config>(
|
|
90
|
+
content: any,
|
|
87
91
|
options?: C
|
|
88
|
-
):
|
|
92
|
+
): any {
|
|
89
93
|
const config = mergeConfig(options);
|
|
90
94
|
|
|
91
|
-
const output = []
|
|
92
|
-
for (const node of [content, ...content.walk()]) {
|
|
95
|
+
const output = [content, ...content.walk()].map((node) => {
|
|
93
96
|
const { type, lines, location } = node;
|
|
94
97
|
const errors = validator(node, config);
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
if (isPromise(errors)) {
|
|
100
|
+
return errors.then((e) =>
|
|
101
|
+
e.map((error) => ({ type, lines, location, error }))
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return errors.map((error) => ({ type, lines, location, error }));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (output.some(isPromise)) {
|
|
109
|
+
return Promise.all(output).then((o) => o.flat());
|
|
97
110
|
}
|
|
98
111
|
|
|
99
|
-
return output;
|
|
112
|
+
return output.flat();
|
|
100
113
|
}
|
|
101
114
|
|
|
102
115
|
export function createElement(
|
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.8",
|
|
5
5
|
"description": "A text markup language for documentation",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -32,11 +32,13 @@
|
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=14.7.0"
|
|
34
34
|
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@types/markdown-it": "*",
|
|
37
|
+
"@types/react": "*"
|
|
38
|
+
},
|
|
35
39
|
"devDependencies": {
|
|
36
40
|
"@types/jasmine": "^3.10.2",
|
|
37
|
-
"@types/
|
|
38
|
-
"@types/node": "^16.11.12",
|
|
39
|
-
"@types/react": "^17.0.38",
|
|
41
|
+
"@types/node": "^16.11.58",
|
|
40
42
|
"@typescript-eslint/eslint-plugin": "^5.12.0",
|
|
41
43
|
"@typescript-eslint/parser": "^5.12.0",
|
|
42
44
|
"deep-assert": "0.3.0",
|
package/src/formatter.test.ts
CHANGED
|
@@ -79,8 +79,8 @@ function check(source, expected, options = {}) {
|
|
|
79
79
|
throw d;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
function stable(source) {
|
|
83
|
-
return check(source, source);
|
|
82
|
+
function stable(source, options?) {
|
|
83
|
+
return check(source, source, options);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
describe('Formatter', () => {
|
|
@@ -105,10 +105,17 @@ describe('Formatter', () => {
|
|
|
105
105
|
|
|
106
106
|
it('variables', () => {
|
|
107
107
|
const source = `
|
|
108
|
+
{% if $primary %}
|
|
109
|
+
X
|
|
110
|
+
{% /if %}
|
|
108
111
|
{% $user.name %}
|
|
109
112
|
{% key x=$user.name new=$flag /%}
|
|
110
113
|
`;
|
|
111
114
|
const expected = `
|
|
115
|
+
{% if $primary %}
|
|
116
|
+
X
|
|
117
|
+
{% /if %}
|
|
118
|
+
|
|
112
119
|
{% $user.name %}
|
|
113
120
|
|
|
114
121
|
{% key x=$user.name new=$flag /%}
|
|
@@ -128,11 +135,21 @@ describe('Formatter', () => {
|
|
|
128
135
|
`;
|
|
129
136
|
|
|
130
137
|
check(source, expected);
|
|
138
|
+
stable(expected, expected);
|
|
131
139
|
});
|
|
132
140
|
|
|
133
141
|
it('tags', () => {
|
|
134
142
|
const source = `
|
|
135
143
|
{% key /%}
|
|
144
|
+
|
|
145
|
+
{% a %}{% /a %}
|
|
146
|
+
|
|
147
|
+
{% a %}
|
|
148
|
+
{% /a %}
|
|
149
|
+
|
|
150
|
+
{% a %}
|
|
151
|
+
|
|
152
|
+
{% /a %}
|
|
136
153
|
|
|
137
154
|
{% checkout %}
|
|
138
155
|
{% if true %}
|
|
@@ -143,6 +160,12 @@ describe('Formatter', () => {
|
|
|
143
160
|
const expected = `
|
|
144
161
|
{% key /%}
|
|
145
162
|
|
|
163
|
+
{% a /%}
|
|
164
|
+
|
|
165
|
+
{% a /%}
|
|
166
|
+
|
|
167
|
+
{% a /%}
|
|
168
|
+
|
|
146
169
|
{% checkout %}
|
|
147
170
|
{% if true %}
|
|
148
171
|
Yes!
|
|
@@ -168,6 +191,13 @@ Yes!
|
|
|
168
191
|
stable(expected);
|
|
169
192
|
});
|
|
170
193
|
|
|
194
|
+
it('long tags with maxTagOpeningWidth=Infinity', () => {
|
|
195
|
+
const source = `
|
|
196
|
+
{% tag a=true b="My very long text well over 80 characters in total" c=123456789 d=false /%}
|
|
197
|
+
`;
|
|
198
|
+
check(source, source, { maxTagOpeningWidth: Infinity });
|
|
199
|
+
});
|
|
200
|
+
|
|
171
201
|
it('nested tags — allowIndentation: true', () => {
|
|
172
202
|
const source = `
|
|
173
203
|
{% checkout %}
|
|
@@ -186,6 +216,7 @@ Yes!
|
|
|
186
216
|
`;
|
|
187
217
|
|
|
188
218
|
check(source, expected, { allowIndentation: true });
|
|
219
|
+
stable(expected, { allowIndentation: true });
|
|
189
220
|
});
|
|
190
221
|
|
|
191
222
|
it('tables', () => {
|
|
@@ -251,6 +282,34 @@ Yes!
|
|
|
251
282
|
stable(expected);
|
|
252
283
|
});
|
|
253
284
|
|
|
285
|
+
it('tables with tags', () => {
|
|
286
|
+
const source = `
|
|
287
|
+
{% table %}
|
|
288
|
+
* H1
|
|
289
|
+
* H2
|
|
290
|
+
{% if $var %}
|
|
291
|
+
---
|
|
292
|
+
* H3
|
|
293
|
+
* H4
|
|
294
|
+
{% /if %}
|
|
295
|
+
{% /table %}
|
|
296
|
+
`;
|
|
297
|
+
const expected = `
|
|
298
|
+
{% table %}
|
|
299
|
+
- H1
|
|
300
|
+
- H2
|
|
301
|
+
{% if $var %}
|
|
302
|
+
---
|
|
303
|
+
- H3
|
|
304
|
+
- H4
|
|
305
|
+
{% /if %}
|
|
306
|
+
{% /table %}
|
|
307
|
+
`;
|
|
308
|
+
|
|
309
|
+
check(source, expected);
|
|
310
|
+
stable(expected);
|
|
311
|
+
});
|
|
312
|
+
|
|
254
313
|
it('lists', () => {
|
|
255
314
|
const source = `
|
|
256
315
|
- [Install Markdoc](/docs/getting-started)
|
|
@@ -363,7 +422,13 @@ Yes!
|
|
|
363
422
|
* Proxy status
|
|
364
423
|
* \`Off\`
|
|
365
424
|
* Set the proxy status to \`off\` to avoid issues during setup.
|
|
366
|
-
{% /table %}
|
|
425
|
+
{% /table %}
|
|
426
|
+
1. foo\\
|
|
427
|
+
baz
|
|
428
|
+
|
|
429
|
+
Soft
|
|
430
|
+
break
|
|
431
|
+
Markdoc uses…`;
|
|
367
432
|
|
|
368
433
|
const expected = `
|
|
369
434
|
- Create your CNAME record
|
|
@@ -396,6 +461,12 @@ Yes!
|
|
|
396
461
|
- \`Off\`
|
|
397
462
|
- Set the proxy status to \`off\` to avoid issues during setup.
|
|
398
463
|
{% /table %}
|
|
464
|
+
1. foo\\
|
|
465
|
+
baz
|
|
466
|
+
|
|
467
|
+
Soft
|
|
468
|
+
break
|
|
469
|
+
Markdoc uses…
|
|
399
470
|
`;
|
|
400
471
|
|
|
401
472
|
check(source, expected);
|
package/src/formatter.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { AttributeValue, Function, Node, Value, Variable } from './types';
|
|
|
4
4
|
|
|
5
5
|
type Options = {
|
|
6
6
|
allowIndentation?: boolean;
|
|
7
|
+
maxTagOpeningWidth?: number;
|
|
7
8
|
parent?: Node;
|
|
8
9
|
indent?: number;
|
|
9
10
|
};
|
|
@@ -14,7 +15,7 @@ const NL = '\n'; // Newline
|
|
|
14
15
|
const OL = '1. '; // Ordered list
|
|
15
16
|
const UL = '- '; // Unordered list
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
+
const MAX_TAG_OPENING_WIDTH = 80;
|
|
18
19
|
|
|
19
20
|
const max = (a: number, b: number) => Math.max(a, b);
|
|
20
21
|
const increment = (o: Options, n = 2) => ({
|
|
@@ -55,7 +56,7 @@ function formatScalar(v: Value): string {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
function formatAnnotationValue(a: AttributeValue): string {
|
|
58
|
-
if (a.name === 'primary') return a.value;
|
|
59
|
+
if (a.name === 'primary') return formatScalar(a.value);
|
|
59
60
|
if (a.name === 'id' && typeof a.value === 'string') return '#' + a.value;
|
|
60
61
|
if (a.type === 'class') return '.' + a.name;
|
|
61
62
|
return `${a.name}=${formatScalar(a.value)}`;
|
|
@@ -196,20 +197,26 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
196
197
|
const open = OPEN + SPACE;
|
|
197
198
|
const tag = [open + n.tag, ...formatAttributes(n)];
|
|
198
199
|
const inlineTag = tag.join(SPACE);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
|
|
201
|
+
const isLongTagOpening =
|
|
202
|
+
inlineTag.length + open.length * 2 >
|
|
203
|
+
(o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
|
|
204
|
+
|
|
205
|
+
// {% tag attributes={...} %}
|
|
206
|
+
yield (isLongTagOpening
|
|
207
|
+
? tag.join(NL + SPACE.repeat(open.length) + indent)
|
|
208
|
+
: inlineTag) +
|
|
209
|
+
SPACE +
|
|
210
|
+
(n.children.length ? '' : '/') +
|
|
211
|
+
CLOSE;
|
|
212
|
+
|
|
205
213
|
if (n.children.length) {
|
|
206
214
|
yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
|
|
207
215
|
if (!n.inline) {
|
|
208
216
|
yield indent;
|
|
209
217
|
}
|
|
210
|
-
|
|
211
|
-
yield n.tag;
|
|
212
|
-
yield SPACE + CLOSE;
|
|
218
|
+
// {% /tag %}
|
|
219
|
+
yield OPEN + SPACE + '/' + n.tag + SPACE + CLOSE;
|
|
213
220
|
}
|
|
214
221
|
if (!n.inline) {
|
|
215
222
|
yield NL;
|
|
@@ -266,25 +273,36 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
266
273
|
break;
|
|
267
274
|
}
|
|
268
275
|
case 'table': {
|
|
269
|
-
const table = [...formatChildren(n, increment(no))] as any as
|
|
276
|
+
const table = [...formatChildren(n, increment(no))] as any as any[];
|
|
270
277
|
if (o.parent && o.parent.type === 'tag' && o.parent.tag === 'table') {
|
|
271
|
-
for (
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
278
|
+
for (let i = 0; i < table.length; i++) {
|
|
279
|
+
const row = table[i];
|
|
280
|
+
// format tags like "if" in the middle of a table list
|
|
281
|
+
if (typeof row === 'string') {
|
|
282
|
+
if (row.trim().length) {
|
|
283
|
+
yield NL;
|
|
284
|
+
yield row;
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
if (i !== 0) {
|
|
288
|
+
yield NL;
|
|
289
|
+
yield indent + '---';
|
|
290
|
+
}
|
|
291
|
+
for (let j = 0; j < row.length; j++) {
|
|
292
|
+
const d = row[j];
|
|
293
|
+
yield NL;
|
|
294
|
+
// TODO see if we should move trim() to `td`
|
|
295
|
+
yield indent + UL + d.trim();
|
|
296
|
+
}
|
|
280
297
|
}
|
|
281
298
|
}
|
|
299
|
+
yield NL;
|
|
282
300
|
} else {
|
|
283
301
|
yield NL;
|
|
284
|
-
const [head, ...rows] = table;
|
|
302
|
+
const [head, ...rows] = table as string[][];
|
|
285
303
|
|
|
286
304
|
const ml = table
|
|
287
|
-
.map((arr) => arr.map((s) => s.length).reduce(max))
|
|
305
|
+
.map((arr) => arr.map((s: string) => s.length).reduce(max))
|
|
288
306
|
.reduce(max);
|
|
289
307
|
|
|
290
308
|
yield* formatTableRow(head.map((h) => h + SPACE.repeat(ml - h.length)));
|
|
@@ -369,5 +387,5 @@ function* formatValue(
|
|
|
369
387
|
export default function format(v: Value, options?: Options): string {
|
|
370
388
|
let doc = '';
|
|
371
389
|
for (const s of formatValue(v, options)) doc += s;
|
|
372
|
-
return doc;
|
|
390
|
+
return doc.trimStart();
|
|
373
391
|
}
|
package/src/parser.test.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { any } from 'deep-assert';
|
|
|
7
7
|
|
|
8
8
|
describe('Markdown parser', function () {
|
|
9
9
|
const fence = '```';
|
|
10
|
-
const tokenizer = new Tokenizer();
|
|
10
|
+
const tokenizer = new Tokenizer({ allowComments: true });
|
|
11
11
|
|
|
12
12
|
function convert(example) {
|
|
13
13
|
const content = example.replace(/\n\s+/gm, '\n').trim();
|
|
@@ -636,4 +636,20 @@ describe('Markdown parser', function () {
|
|
|
636
636
|
`);
|
|
637
637
|
}).not.toThrow();
|
|
638
638
|
});
|
|
639
|
+
|
|
640
|
+
it('parsing comments', function () {
|
|
641
|
+
const example = convert(`
|
|
642
|
+
this is a test
|
|
643
|
+
|
|
644
|
+
<!-- foo -->
|
|
645
|
+
`);
|
|
646
|
+
|
|
647
|
+
expect(example).toDeepEqualSubset({
|
|
648
|
+
type: 'document',
|
|
649
|
+
children: [
|
|
650
|
+
{ type: 'paragraph' },
|
|
651
|
+
{ type: 'comment', attributes: { content: 'foo' } },
|
|
652
|
+
],
|
|
653
|
+
});
|
|
654
|
+
});
|
|
639
655
|
});
|
package/src/parser.ts
CHANGED
package/src/schema.ts
CHANGED
|
@@ -11,6 +11,7 @@ export const document: Schema = {
|
|
|
11
11
|
'tag',
|
|
12
12
|
'fence',
|
|
13
13
|
'blockquote',
|
|
14
|
+
'comment',
|
|
14
15
|
'list',
|
|
15
16
|
'hr',
|
|
16
17
|
],
|
|
@@ -189,6 +190,7 @@ export const inline: Schema = {
|
|
|
189
190
|
'image',
|
|
190
191
|
'hardbreak',
|
|
191
192
|
'softbreak',
|
|
193
|
+
'comment',
|
|
192
194
|
],
|
|
193
195
|
};
|
|
194
196
|
|
|
@@ -226,10 +228,16 @@ export const hardbreak: Schema = {
|
|
|
226
228
|
};
|
|
227
229
|
|
|
228
230
|
export const softbreak: Schema = {
|
|
229
|
-
transform(
|
|
231
|
+
transform() {
|
|
230
232
|
return ' ';
|
|
231
233
|
},
|
|
232
234
|
};
|
|
233
235
|
|
|
236
|
+
export const comment = {
|
|
237
|
+
attributes: {
|
|
238
|
+
content: { type: String, required: true },
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
234
242
|
export const error = {};
|
|
235
243
|
export const node = {};
|
package/src/tokenizer/index.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it/lib';
|
|
2
2
|
import annotations from './plugins/annotations';
|
|
3
3
|
import frontmatter from './plugins/frontmatter';
|
|
4
|
+
import comments from './plugins/comments';
|
|
4
5
|
import type Token from 'markdown-it/lib/token';
|
|
5
6
|
|
|
6
7
|
export default class Tokenizer {
|
|
7
8
|
private parser: MarkdownIt;
|
|
8
9
|
|
|
9
10
|
constructor(
|
|
10
|
-
config: MarkdownIt.Options & {
|
|
11
|
+
config: MarkdownIt.Options & {
|
|
12
|
+
allowIndentation?: boolean;
|
|
13
|
+
allowComments?: boolean;
|
|
14
|
+
} = {}
|
|
11
15
|
) {
|
|
12
16
|
this.parser = new MarkdownIt(config);
|
|
13
17
|
this.parser.use(annotations, 'annotations', {});
|
|
@@ -17,6 +21,8 @@ export default class Tokenizer {
|
|
|
17
21
|
// Disable indented `code_block` support https://spec.commonmark.org/0.30/#indented-code-block
|
|
18
22
|
'code',
|
|
19
23
|
]);
|
|
24
|
+
|
|
25
|
+
if (config.allowComments) this.parser.use(comments, 'comments', {});
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
tokenize(content: string): Token[] {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import Tokenizer from '..';
|
|
2
|
+
|
|
3
|
+
describe('MarkdownIt Comments plugin', function () {
|
|
4
|
+
const tokenizer = new Tokenizer({ allowComments: true });
|
|
5
|
+
|
|
6
|
+
function parse(example) {
|
|
7
|
+
const content = example.replace(/\n\s+/gm, '\n').trim();
|
|
8
|
+
return tokenizer.tokenize(content);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('inline comments', function () {
|
|
12
|
+
const output = [
|
|
13
|
+
{ type: 'paragraph_open' },
|
|
14
|
+
{
|
|
15
|
+
type: 'inline',
|
|
16
|
+
children: [
|
|
17
|
+
{ type: 'text', content: 'this is a test ' },
|
|
18
|
+
{ type: 'comment', content: 'example comment' },
|
|
19
|
+
{ type: 'text', content: ' foo' },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
{ type: 'paragraph_close' },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
it('simple inline comment', function () {
|
|
26
|
+
const example = parse(`
|
|
27
|
+
this is a test <!-- example comment --> foo
|
|
28
|
+
`);
|
|
29
|
+
|
|
30
|
+
expect(example).toDeepEqualSubset(output);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('inline comment with a newline', function () {
|
|
34
|
+
const example = parse(`
|
|
35
|
+
this is a test <!--
|
|
36
|
+
example comment
|
|
37
|
+
--> foo
|
|
38
|
+
`);
|
|
39
|
+
|
|
40
|
+
expect(example).toDeepEqualSubset(output);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('block comments', function () {
|
|
45
|
+
const output = [
|
|
46
|
+
{ type: 'paragraph_open' },
|
|
47
|
+
{ type: 'inline' },
|
|
48
|
+
{ type: 'paragraph_close' },
|
|
49
|
+
{ type: 'comment', content: 'example comment' },
|
|
50
|
+
{ type: 'paragraph_open' },
|
|
51
|
+
{ type: 'inline', content: 'foo' },
|
|
52
|
+
{ type: 'paragraph_close' },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
it('simple block comment after a paragraph', function () {
|
|
56
|
+
const example = parse(`
|
|
57
|
+
this is a test
|
|
58
|
+
|
|
59
|
+
<!--
|
|
60
|
+
example comment
|
|
61
|
+
-->
|
|
62
|
+
|
|
63
|
+
foo
|
|
64
|
+
`);
|
|
65
|
+
|
|
66
|
+
expect(example).toDeepEqualSubset(output);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('block comment with ending on same line as content', function () {
|
|
70
|
+
const example = parse(`
|
|
71
|
+
this is a test
|
|
72
|
+
|
|
73
|
+
<!--
|
|
74
|
+
example comment -->
|
|
75
|
+
|
|
76
|
+
foo
|
|
77
|
+
`);
|
|
78
|
+
|
|
79
|
+
expect(example).toDeepEqualSubset(output);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('block comment one one line', function () {
|
|
83
|
+
const example = parse(`
|
|
84
|
+
this is a test
|
|
85
|
+
|
|
86
|
+
<!-- example comment -->
|
|
87
|
+
|
|
88
|
+
foo
|
|
89
|
+
`);
|
|
90
|
+
|
|
91
|
+
expect(example).toDeepEqualSubset(output);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|