@markdoc/markdoc 0.5.9 → 0.5.11
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 +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6524 -6330
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +6493 -6299
- package/dist/index.mjs.map +4 -4
- package/dist/src/parser.d.ts +1 -2
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/tokenizer/index.d.ts +3 -3
- package/dist/src/tokenizer/index.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/annotations.d.ts +2 -2
- package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/comments.d.ts +2 -2
- package/dist/src/tokenizer/plugins/comments.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/frontmatter.d.ts +2 -2
- package/dist/src/tokenizer/plugins/frontmatter.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/link.d.ts +2 -2
- package/dist/src/tokenizer/plugins/link.d.ts.map +1 -1
- package/dist/src/types.d.ts +22 -0
- 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/index.ts +7 -3
- package/package.json +4 -8
- package/src/formatter.test.ts +55 -0
- package/src/formatter.ts +5 -5
- package/src/grammar/tag.d.ts +3 -1
- package/src/parser.ts +19 -13
- package/src/tokenizer/index.ts +7 -7
- package/src/tokenizer/plugins/annotations.test.ts +126 -0
- package/src/tokenizer/plugins/annotations.ts +33 -16
- package/src/tokenizer/plugins/comments.ts +4 -6
- package/src/tokenizer/plugins/frontmatter.ts +5 -6
- package/src/tokenizer/plugins/link.ts +9 -11
- package/src/types.ts +23 -0
- package/src/utils.ts +1 -1
- package/global.d.ts +0 -18
package/dist/src/parser.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Node from './ast/node';
|
|
2
|
-
import type { ParserArgs } from './types';
|
|
3
|
-
import type Token from 'markdown-it/lib/token';
|
|
2
|
+
import type { ParserArgs, Token } from './types';
|
|
4
3
|
export default function parser(tokens: Token[], args?: string | ParserArgs): Node;
|
|
5
4
|
//# sourceMappingURL=parser.d.ts.map
|
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;AAI9B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;AAI9B,OAAO,KAAK,EAA4B,UAAU,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAwM3E,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,QAoBzE"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import MarkdownIt from 'markdown-it
|
|
2
|
-
import type Token from '
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import type { Token } from '../types';
|
|
3
3
|
export type LinkPluginOptions = {
|
|
4
4
|
validatedProtocols: string[];
|
|
5
5
|
};
|
|
6
6
|
export default class Tokenizer {
|
|
7
7
|
private parser;
|
|
8
|
-
constructor(config?: MarkdownIt.
|
|
8
|
+
constructor(config?: MarkdownIt.MarkdownItOptions & {
|
|
9
9
|
allowIndentation?: boolean;
|
|
10
10
|
allowComments?: boolean;
|
|
11
11
|
allowLinkValidation?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAKrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,MAAM,iBAAiB,GAAG;IAAE,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEjE,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAwB;gBAGpC,MAAM,GAAE,UAAU,CAAC,iBAAiB,GAAG;QACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;KACtC;IAwBR,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE;CAGnC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type MarkdownIt from 'markdown-it
|
|
2
|
-
export default function plugin(md: MarkdownIt): void;
|
|
1
|
+
import type MarkdownIt from 'markdown-it';
|
|
2
|
+
export default function plugin(md: MarkdownIt.MarkdownIt): void;
|
|
3
3
|
//# sourceMappingURL=annotations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AA+I1C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,UAAU,QAMvD"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type MarkdownIt from 'markdown-it
|
|
2
|
-
export default function plugin(md: MarkdownIt): void;
|
|
1
|
+
import type MarkdownIt from 'markdown-it';
|
|
2
|
+
export default function plugin(md: MarkdownIt.MarkdownIt): void;
|
|
3
3
|
//# sourceMappingURL=comments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/comments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/comments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AA6C1C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,UAAU,QAGvD"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type MarkdownIt from 'markdown-it
|
|
2
|
-
export default function plugin(md: MarkdownIt): void;
|
|
1
|
+
import type MarkdownIt from 'markdown-it';
|
|
2
|
+
export default function plugin(md: MarkdownIt.MarkdownIt): void;
|
|
3
3
|
//# sourceMappingURL=frontmatter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAmC1C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,UAAU,QAEvD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type MarkdownIt from 'markdown-it
|
|
1
|
+
import type MarkdownIt from 'markdown-it';
|
|
2
2
|
import { LinkPluginOptions } from '..';
|
|
3
|
-
export default function plugin(md: MarkdownIt, options: LinkPluginOptions): void;
|
|
3
|
+
export default function plugin(md: MarkdownIt.MarkdownIt, options: LinkPluginOptions): void;
|
|
4
4
|
//# sourceMappingURL=link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAI1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAyBvC,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,EAAE,EAAE,UAAU,CAAC,UAAU,EACzB,OAAO,EAAE,iBAAiB,QAG3B"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -97,6 +97,28 @@ export type ValidationError = {
|
|
|
97
97
|
message: string;
|
|
98
98
|
location?: Location;
|
|
99
99
|
};
|
|
100
|
+
export type Token = {
|
|
101
|
+
type: string;
|
|
102
|
+
tag?: string;
|
|
103
|
+
attrs?: Array<[string, string | number]> | null;
|
|
104
|
+
map?: number[] | null;
|
|
105
|
+
nesting?: -1 | 0 | 1;
|
|
106
|
+
level?: number;
|
|
107
|
+
children?: Token[] | null;
|
|
108
|
+
content?: string;
|
|
109
|
+
markup?: string;
|
|
110
|
+
info?: string;
|
|
111
|
+
meta?: Record<string, any> | null;
|
|
112
|
+
block?: boolean;
|
|
113
|
+
hidden?: boolean;
|
|
114
|
+
errors?: ValidationError[];
|
|
115
|
+
position?: {
|
|
116
|
+
start?: number;
|
|
117
|
+
end?: number;
|
|
118
|
+
};
|
|
119
|
+
start?: number;
|
|
120
|
+
end?: number;
|
|
121
|
+
};
|
|
100
122
|
export type ValidateError = {
|
|
101
123
|
type: string;
|
|
102
124
|
lines: number[];
|
package/dist/src/types.d.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ACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAKnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC"}
|
package/dist/src/utils.d.ts
CHANGED
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,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAQrC,eAAO,MAAM,IAAI,OAAO,CAAC;AACzB,eAAO,MAAM,KAAK,OAAO,CAAC;AAE1B,eAAO,MAAM,gBAAgB,QAAqB,CAAC;AAEnD,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,MAAM,CAEhD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,CAEnD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAI,iBA0BpD;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,EAAE,WA0B3B;AAoBD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,KAAK,EAAE,CA+DjE"}
|
package/index.ts
CHANGED
|
@@ -14,9 +14,13 @@ import transforms from './src/transforms';
|
|
|
14
14
|
import { parseTags } from './src/utils';
|
|
15
15
|
import validator, { validateTree } from './src/validator';
|
|
16
16
|
|
|
17
|
-
import type {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
import type {
|
|
18
|
+
Config,
|
|
19
|
+
ParserArgs,
|
|
20
|
+
RenderableTreeNode,
|
|
21
|
+
Token,
|
|
22
|
+
ValidateError,
|
|
23
|
+
} from './src/types';
|
|
20
24
|
|
|
21
25
|
export * from './src/types';
|
|
22
26
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdoc/markdoc",
|
|
3
3
|
"author": "Ryan Paul",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.11",
|
|
5
5
|
"description": "A text markup language for documentation",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=14.7.0"
|
|
34
34
|
},
|
|
35
|
-
"optionalDependencies": {
|
|
36
|
-
"@types/markdown-it": "12.2.3",
|
|
37
|
-
"@types/linkify-it": "^3.0.1"
|
|
38
|
-
},
|
|
39
35
|
"peerDependencies": {
|
|
40
36
|
"@types/react": "*",
|
|
41
37
|
"react": "*"
|
|
@@ -49,10 +45,10 @@
|
|
|
49
45
|
}
|
|
50
46
|
},
|
|
51
47
|
"devDependencies": {
|
|
48
|
+
"@eslint/js": "^9.0.0",
|
|
52
49
|
"@types/jasmine": "^5.0.0",
|
|
53
50
|
"@types/node": "^18.0.0",
|
|
54
51
|
"@types/react": "^17.0.0",
|
|
55
|
-
"@eslint/js": "^9.0.0",
|
|
56
52
|
"deep-assert": "0.3.0",
|
|
57
53
|
"diff": "^4.0.4",
|
|
58
54
|
"esbuild": "0.25.0",
|
|
@@ -60,14 +56,14 @@
|
|
|
60
56
|
"globals": "^16.0.0",
|
|
61
57
|
"jasmine": "5.13.0",
|
|
62
58
|
"jest-diff": "^28.1.3",
|
|
63
|
-
"markdown-it": "
|
|
59
|
+
"markdown-it": "15.0.1",
|
|
64
60
|
"patch-package": "^8.0.0",
|
|
65
61
|
"pegjs": "0.11.0-master.b7b87ea",
|
|
66
62
|
"prettier": "^2.5.1",
|
|
67
|
-
"typescript-eslint": "^8.0.0",
|
|
68
63
|
"ts-eager": "2.0.2",
|
|
69
64
|
"typedoc": "0.28.18",
|
|
70
65
|
"typescript": "^5.0.0",
|
|
66
|
+
"typescript-eslint": "^8.0.0",
|
|
71
67
|
"yaml-js": "^0.2.3"
|
|
72
68
|
},
|
|
73
69
|
"overrides": {
|
package/src/formatter.test.ts
CHANGED
|
@@ -833,6 +833,61 @@ ${'`'.repeat(4)}
|
|
|
833
833
|
check(source, expected);
|
|
834
834
|
stable(expected);
|
|
835
835
|
});
|
|
836
|
+
it('lists in blockquotes', () => {
|
|
837
|
+
const source = `
|
|
838
|
+
> Intro:
|
|
839
|
+
>
|
|
840
|
+
> - One
|
|
841
|
+
> - Two
|
|
842
|
+
>
|
|
843
|
+
> 1. First
|
|
844
|
+
> 2. Second
|
|
845
|
+
>
|
|
846
|
+
> After`;
|
|
847
|
+
|
|
848
|
+
const expected = `
|
|
849
|
+
> Intro:
|
|
850
|
+
>
|
|
851
|
+
> - One
|
|
852
|
+
> - Two
|
|
853
|
+
>
|
|
854
|
+
> 1. First
|
|
855
|
+
> 1. Second
|
|
856
|
+
>
|
|
857
|
+
> After
|
|
858
|
+
`;
|
|
859
|
+
|
|
860
|
+
check(source, expected);
|
|
861
|
+
stable(expected);
|
|
862
|
+
});
|
|
863
|
+
it('nested blocks in blockquotes', () => {
|
|
864
|
+
const source = `
|
|
865
|
+
> - One
|
|
866
|
+
> - Nested
|
|
867
|
+
> - Two
|
|
868
|
+
>
|
|
869
|
+
> > Inner
|
|
870
|
+
> > quote
|
|
871
|
+
>
|
|
872
|
+
> \`\`\`js
|
|
873
|
+
> code();
|
|
874
|
+
> \`\`\`
|
|
875
|
+
`;
|
|
876
|
+
|
|
877
|
+
stable(source);
|
|
878
|
+
});
|
|
879
|
+
it('blockquotes with lists inside list items', () => {
|
|
880
|
+
const source = `
|
|
881
|
+
- Item
|
|
882
|
+
|
|
883
|
+
> Quote
|
|
884
|
+
>
|
|
885
|
+
> - One
|
|
886
|
+
> - Two
|
|
887
|
+
`;
|
|
888
|
+
|
|
889
|
+
stable(source);
|
|
890
|
+
});
|
|
836
891
|
it('skips over undefined variables', () => {
|
|
837
892
|
const sourceNode = new Markdoc.Ast.Node(
|
|
838
893
|
'tag',
|
package/src/formatter.ts
CHANGED
|
@@ -231,11 +231,11 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
231
231
|
break;
|
|
232
232
|
}
|
|
233
233
|
case 'blockquote': {
|
|
234
|
-
const prefix = '>' + SPACE;
|
|
235
|
-
|
|
236
|
-
.map((child) => format(child, no).
|
|
237
|
-
.
|
|
238
|
-
|
|
234
|
+
const prefix = NL + indent + '>' + SPACE;
|
|
235
|
+
const inner = n.children
|
|
236
|
+
.map((child) => format(child, { ...no, indent: 0 }).trim())
|
|
237
|
+
.join(NL + NL);
|
|
238
|
+
yield prefix + inner.split(NL).join(prefix) + NL;
|
|
239
239
|
break;
|
|
240
240
|
}
|
|
241
241
|
case 'hr': {
|
package/src/grammar/tag.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type MarkdownIt from 'markdown-it';
|
|
1
2
|
import type AstVariable from '../ast/variable';
|
|
2
3
|
import type AstFunction from '../ast/function';
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
type Token = MarkdownIt.Token;
|
|
4
6
|
|
|
5
7
|
type astTypes = {
|
|
6
8
|
Variable?: typeof AstVariable;
|
package/src/parser.ts
CHANGED
|
@@ -2,9 +2,7 @@ import Node from './ast/node';
|
|
|
2
2
|
import transforms from './transforms/index';
|
|
3
3
|
import { OPEN } from './utils';
|
|
4
4
|
|
|
5
|
-
import type { AttributeValue, ParserArgs } from './types';
|
|
6
|
-
|
|
7
|
-
import type Token from 'markdown-it/lib/token';
|
|
5
|
+
import type { AttributeValue, NodeType, ParserArgs, Token } from './types';
|
|
8
6
|
|
|
9
7
|
const mappings: Record<string, string> = {
|
|
10
8
|
ordered_list: 'list',
|
|
@@ -36,7 +34,8 @@ function annotate(node: Node, attributes: AttributeValue[]) {
|
|
|
36
34
|
function handleAttrs(token: Token, type: string) {
|
|
37
35
|
switch (type) {
|
|
38
36
|
case 'heading':
|
|
39
|
-
|
|
37
|
+
// heading_open tokens always have `tag` set (e.g. "h1"-"h6")
|
|
38
|
+
return { level: Number(token.tag!.replace('h', '')) };
|
|
40
39
|
case 'list': {
|
|
41
40
|
const attrs = token.attrs ? Object.fromEntries(token.attrs) : undefined;
|
|
42
41
|
const ordered = token.type.startsWith('ordered');
|
|
@@ -45,13 +44,13 @@ function handleAttrs(token: Token, type: string) {
|
|
|
45
44
|
: { ordered, marker: token.markup };
|
|
46
45
|
}
|
|
47
46
|
case 'link': {
|
|
48
|
-
const attrs = Object.fromEntries(token.attrs);
|
|
47
|
+
const attrs = Object.fromEntries(token.attrs ?? []);
|
|
49
48
|
return attrs.title
|
|
50
49
|
? { href: attrs.href, title: attrs.title }
|
|
51
50
|
: { href: attrs.href };
|
|
52
51
|
}
|
|
53
52
|
case 'image': {
|
|
54
|
-
const attrs = Object.fromEntries(token.attrs);
|
|
53
|
+
const attrs = Object.fromEntries(token.attrs ?? []);
|
|
55
54
|
return attrs.title
|
|
56
55
|
? { alt: token.content, src: attrs.src, title: attrs.title }
|
|
57
56
|
: { alt: token.content, src: attrs.src };
|
|
@@ -64,7 +63,8 @@ function handleAttrs(token: Token, type: string) {
|
|
|
64
63
|
case 'comment':
|
|
65
64
|
return { content: (token.meta || {}).variable || token.content };
|
|
66
65
|
case 'fence': {
|
|
67
|
-
|
|
66
|
+
// fence tokens always have `info` set (empty string if unused)
|
|
67
|
+
const [language] = token.info!.split(' ', 1);
|
|
68
68
|
return language === '' || language === OPEN
|
|
69
69
|
? { content: token.content }
|
|
70
70
|
: { content: token.content, language };
|
|
@@ -76,11 +76,12 @@ function handleAttrs(token: Token, type: string) {
|
|
|
76
76
|
|
|
77
77
|
let align;
|
|
78
78
|
if (attrs.style) {
|
|
79
|
-
|
|
79
|
+
const style = String(attrs.style);
|
|
80
|
+
if (style.includes('left')) {
|
|
80
81
|
align = 'left';
|
|
81
|
-
} else if (
|
|
82
|
+
} else if (style.includes('center')) {
|
|
82
83
|
align = 'center';
|
|
83
|
-
} else if (
|
|
84
|
+
} else if (style.includes('right')) {
|
|
84
85
|
align = 'right';
|
|
85
86
|
}
|
|
86
87
|
}
|
|
@@ -133,7 +134,7 @@ function handleToken(
|
|
|
133
134
|
errors.push({ id: 'parse-error', level: 'critical', message, location });
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
if (token.nesting < 0) {
|
|
137
|
+
if ((token.nesting ?? 0) < 0) {
|
|
137
138
|
if (parent.type === typeName && parent.tag === tag) {
|
|
138
139
|
if (parent.lines && token.map) parent.lines.push(...token.map);
|
|
139
140
|
return nodes.pop();
|
|
@@ -147,7 +148,12 @@ function handleToken(
|
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
const attrs = handleAttrs(token, typeName);
|
|
150
|
-
const node = new Node(
|
|
151
|
+
const node = new Node(
|
|
152
|
+
typeName as NodeType,
|
|
153
|
+
attrs,
|
|
154
|
+
undefined,
|
|
155
|
+
tag || undefined
|
|
156
|
+
);
|
|
151
157
|
const { position = {} } = token;
|
|
152
158
|
|
|
153
159
|
node.errors = errors;
|
|
@@ -179,7 +185,7 @@ function handleToken(
|
|
|
179
185
|
parent.slots[node.attributes.primary] = node;
|
|
180
186
|
else parent.push(node);
|
|
181
187
|
|
|
182
|
-
if (token.nesting > 0) nodes.push(node);
|
|
188
|
+
if ((token.nesting ?? 0) > 0) nodes.push(node);
|
|
183
189
|
|
|
184
190
|
if (!Array.isArray(token.children)) return;
|
|
185
191
|
|
package/src/tokenizer/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import MarkdownIt from 'markdown-it
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
2
|
import annotations from './plugins/annotations';
|
|
3
3
|
import frontmatter from './plugins/frontmatter';
|
|
4
4
|
import comments from './plugins/comments';
|
|
5
5
|
import link from './plugins/link';
|
|
6
|
-
import type Token from '
|
|
6
|
+
import type { Token } from '../types';
|
|
7
7
|
|
|
8
8
|
export type LinkPluginOptions = { validatedProtocols: string[] };
|
|
9
9
|
|
|
10
10
|
export default class Tokenizer {
|
|
11
|
-
private parser: MarkdownIt;
|
|
11
|
+
private parser: MarkdownIt.MarkdownIt;
|
|
12
12
|
|
|
13
13
|
constructor(
|
|
14
|
-
config: MarkdownIt.
|
|
14
|
+
config: MarkdownIt.MarkdownItOptions & {
|
|
15
15
|
allowIndentation?: boolean;
|
|
16
16
|
allowComments?: boolean;
|
|
17
17
|
allowLinkValidation?: boolean;
|
|
@@ -19,8 +19,8 @@ export default class Tokenizer {
|
|
|
19
19
|
} = {}
|
|
20
20
|
) {
|
|
21
21
|
this.parser = new MarkdownIt(config);
|
|
22
|
-
this.parser.use(annotations
|
|
23
|
-
this.parser.use(frontmatter
|
|
22
|
+
this.parser.use(annotations);
|
|
23
|
+
this.parser.use(frontmatter);
|
|
24
24
|
|
|
25
25
|
this.parser.disable([
|
|
26
26
|
'lheading',
|
|
@@ -28,7 +28,7 @@ export default class Tokenizer {
|
|
|
28
28
|
'code',
|
|
29
29
|
]);
|
|
30
30
|
|
|
31
|
-
if (config.allowComments) this.parser.use(comments
|
|
31
|
+
if (config.allowComments) this.parser.use(comments);
|
|
32
32
|
if (config.allowLinkValidation) {
|
|
33
33
|
// Set http and https as the default protocols to validate
|
|
34
34
|
this.parser.use(
|
|
@@ -167,6 +167,132 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
167
167
|
expect(example.length).toEqual(5);
|
|
168
168
|
expect(example[2].children.length).toEqual(1);
|
|
169
169
|
});
|
|
170
|
+
|
|
171
|
+
it('inside a blockquote', function () {
|
|
172
|
+
const example = parse(`
|
|
173
|
+
> {% test #foo .bar
|
|
174
|
+
> baz=1 %}
|
|
175
|
+
> This is a test
|
|
176
|
+
> {% /test %}
|
|
177
|
+
`);
|
|
178
|
+
|
|
179
|
+
expect(example).toDeepEqualSubset([
|
|
180
|
+
{ type: 'blockquote_open', nesting: 1 },
|
|
181
|
+
...basicExample,
|
|
182
|
+
{ type: 'blockquote_close', nesting: -1 },
|
|
183
|
+
]);
|
|
184
|
+
expect(example[1].map).toDeepEqual([0, 2]);
|
|
185
|
+
expect(example[2].map).toDeepEqual([2, 3]);
|
|
186
|
+
expect(example[5].map).toDeepEqual([3, 4]);
|
|
187
|
+
expect(example.length).toEqual(7);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('followed by content after the blockquote', function () {
|
|
191
|
+
const example = parse(`
|
|
192
|
+
> {% test #foo .bar
|
|
193
|
+
> baz=1 %}
|
|
194
|
+
> This is a test
|
|
195
|
+
> {% /test %}
|
|
196
|
+
After the blockquote
|
|
197
|
+
`);
|
|
198
|
+
|
|
199
|
+
expect(example).toDeepEqualSubset([
|
|
200
|
+
{ type: 'blockquote_open', nesting: 1 },
|
|
201
|
+
...basicExample,
|
|
202
|
+
{ type: 'blockquote_close', nesting: -1 },
|
|
203
|
+
{ type: 'paragraph_open', tag: 'p', nesting: 1 },
|
|
204
|
+
{
|
|
205
|
+
type: 'inline',
|
|
206
|
+
nesting: 0,
|
|
207
|
+
children: [
|
|
208
|
+
{ type: 'text', nesting: 0, content: 'After the blockquote' },
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
{ type: 'paragraph_close', tag: 'p', nesting: -1 },
|
|
212
|
+
]);
|
|
213
|
+
expect(example[1].map).toDeepEqual([0, 2]);
|
|
214
|
+
expect(example[5].map).toDeepEqual([3, 4]);
|
|
215
|
+
expect(example[7].map).toDeepEqual([4, 5]);
|
|
216
|
+
expect(example.length).toEqual(10);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('inside a list item', function () {
|
|
220
|
+
// Not dedented: list continuation depends on the indentation
|
|
221
|
+
const example = tokenizer.tokenize(`- {% test #foo .bar
|
|
222
|
+
baz=1 %}
|
|
223
|
+
This is a test
|
|
224
|
+
{% /test %}`);
|
|
225
|
+
|
|
226
|
+
expect(example).toDeepEqualSubset([
|
|
227
|
+
{ type: 'bullet_list_open', nesting: 1 },
|
|
228
|
+
{ type: 'list_item_open', nesting: 1 },
|
|
229
|
+
...basicExample,
|
|
230
|
+
{ type: 'list_item_close', nesting: -1 },
|
|
231
|
+
{ type: 'bullet_list_close', nesting: -1 },
|
|
232
|
+
]);
|
|
233
|
+
expect(example[2].map).toDeepEqual([0, 2]);
|
|
234
|
+
expect(example[3].map).toDeepEqual([2, 3]);
|
|
235
|
+
expect(example[6].map).toDeepEqual([3, 4]);
|
|
236
|
+
expect(example.length).toEqual(9);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('inside a list item inside a blockquote', function () {
|
|
240
|
+
const example = tokenizer.tokenize(`> - {% test #foo .bar
|
|
241
|
+
> baz=1 %}
|
|
242
|
+
> This is a test
|
|
243
|
+
> {% /test %}`);
|
|
244
|
+
|
|
245
|
+
expect(example).toDeepEqualSubset([
|
|
246
|
+
{ type: 'blockquote_open', nesting: 1 },
|
|
247
|
+
{ type: 'bullet_list_open', nesting: 1 },
|
|
248
|
+
{ type: 'list_item_open', nesting: 1 },
|
|
249
|
+
...basicExample,
|
|
250
|
+
{ type: 'list_item_close', nesting: -1 },
|
|
251
|
+
{ type: 'bullet_list_close', nesting: -1 },
|
|
252
|
+
{ type: 'blockquote_close', nesting: -1 },
|
|
253
|
+
]);
|
|
254
|
+
expect(example[3].map).toDeepEqual([0, 2]);
|
|
255
|
+
expect(example[4].map).toDeepEqual([2, 3]);
|
|
256
|
+
expect(example[7].map).toDeepEqual([3, 4]);
|
|
257
|
+
expect(example.length).toEqual(11);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('with a single-line container inside a blockquote', function () {
|
|
262
|
+
const example = parse(`
|
|
263
|
+
> {% test #foo .bar baz=1 %}
|
|
264
|
+
> This is a test
|
|
265
|
+
> {% /test %}
|
|
266
|
+
`);
|
|
267
|
+
|
|
268
|
+
expect(example).toDeepEqualSubset([
|
|
269
|
+
{ type: 'blockquote_open', nesting: 1 },
|
|
270
|
+
{
|
|
271
|
+
type: 'tag_open',
|
|
272
|
+
nesting: 1,
|
|
273
|
+
meta: {
|
|
274
|
+
attributes: [
|
|
275
|
+
{ type: 'attribute', name: 'id', value: 'foo' },
|
|
276
|
+
{ type: 'class', name: 'bar', value: true },
|
|
277
|
+
{ type: 'attribute', name: 'baz', value: 1 },
|
|
278
|
+
],
|
|
279
|
+
tag: 'test',
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{ type: 'paragraph_open', tag: 'p', nesting: 1 },
|
|
283
|
+
{
|
|
284
|
+
type: 'inline',
|
|
285
|
+
nesting: 0,
|
|
286
|
+
children: [{ type: 'text', nesting: 0, content: 'This is a test' }],
|
|
287
|
+
},
|
|
288
|
+
{ type: 'paragraph_close', tag: 'p', nesting: -1 },
|
|
289
|
+
{ type: 'tag_close', nesting: -1, meta: { tag: 'test' } },
|
|
290
|
+
{ type: 'blockquote_close', nesting: -1 },
|
|
291
|
+
]);
|
|
292
|
+
expect(example[1].map).toDeepEqual([0, 1]);
|
|
293
|
+
expect(example[2].map).toDeepEqual([1, 2]);
|
|
294
|
+
expect(example[5].map).toDeepEqual([2, 3]);
|
|
295
|
+
expect(example.length).toEqual(7);
|
|
170
296
|
});
|
|
171
297
|
|
|
172
298
|
describe('inline', function () {
|