@yozora/tokenizer-list 1.3.0 → 2.0.0-alpha.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/lib/cjs/index.js +42 -26
- package/lib/esm/index.js +41 -25
- package/lib/types/index.d.ts +2 -4
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/postMatch.d.ts +10 -0
- package/lib/types/tokenizer.d.ts +7 -16
- package/lib/types/types.d.ts +9 -8
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -2,21 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var ast = require('@yozora/ast');
|
|
6
5
|
var coreTokenizer = require('@yozora/core-tokenizer');
|
|
6
|
+
var ast = require('@yozora/ast');
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const parse = function () {
|
|
9
|
+
return {
|
|
10
|
+
parse: (token, children) => {
|
|
11
|
+
const node = {
|
|
12
|
+
type: ast.ListType,
|
|
13
|
+
ordered: token.ordered,
|
|
14
|
+
orderType: token.orderType,
|
|
15
|
+
start: token.start,
|
|
16
|
+
marker: token.marker,
|
|
17
|
+
spread: token.spread,
|
|
18
|
+
children: children,
|
|
19
|
+
};
|
|
20
|
+
return node;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
9
24
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
15
|
-
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_BLOCK,
|
|
16
|
-
});
|
|
17
|
-
this.isContainingBlock = true;
|
|
18
|
-
}
|
|
19
|
-
transformMatch(tokens, api) {
|
|
25
|
+
const postMatch = function (api) {
|
|
26
|
+
const { name: _tokenizer } = this;
|
|
27
|
+
return { transformMatch };
|
|
28
|
+
function transformMatch(tokens) {
|
|
20
29
|
const results = [];
|
|
21
30
|
let listItems = [];
|
|
22
31
|
const resolveList = () => {
|
|
@@ -39,8 +48,7 @@ class ListTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
39
48
|
let previousItem = listItems[0];
|
|
40
49
|
for (let i = 1; i < listItems.length; ++i) {
|
|
41
50
|
const currentItem = listItems[i];
|
|
42
|
-
if (previousItem.position.end.line + 1 <
|
|
43
|
-
currentItem.position.start.line) {
|
|
51
|
+
if (previousItem.position.end.line + 1 < currentItem.position.start.line) {
|
|
44
52
|
spread = true;
|
|
45
53
|
break;
|
|
46
54
|
}
|
|
@@ -48,7 +56,7 @@ class ListTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
const list = {
|
|
51
|
-
_tokenizer
|
|
59
|
+
_tokenizer,
|
|
52
60
|
nodeType: ast.ListType,
|
|
53
61
|
ordered: listItems[0].ordered,
|
|
54
62
|
orderType: listItems[0].orderType,
|
|
@@ -97,20 +105,28 @@ class ListTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
97
105
|
resolveList();
|
|
98
106
|
return results;
|
|
99
107
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const uniqueName = '@yozora/tokenizer-list';
|
|
111
|
+
|
|
112
|
+
class ListTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
113
|
+
constructor(props = {}) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
super({
|
|
116
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
117
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_BLOCK,
|
|
118
|
+
});
|
|
119
|
+
this.match = () => {
|
|
120
|
+
return {
|
|
121
|
+
isContainingBlock: true,
|
|
122
|
+
eatOpener: () => null,
|
|
123
|
+
};
|
|
109
124
|
};
|
|
110
|
-
|
|
125
|
+
this.postMatch = postMatch;
|
|
126
|
+
this.parse = parse;
|
|
111
127
|
}
|
|
112
128
|
}
|
|
113
129
|
|
|
114
130
|
exports.ListTokenizer = ListTokenizer;
|
|
115
131
|
exports.ListTokenizerName = uniqueName;
|
|
116
|
-
exports[
|
|
132
|
+
exports["default"] = ListTokenizer;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import { ListItemType, ListType } from '@yozora/ast';
|
|
2
1
|
import { BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
2
|
+
import { ListType, ListItemType } from '@yozora/ast';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const parse = function () {
|
|
5
|
+
return {
|
|
6
|
+
parse: (token, children) => {
|
|
7
|
+
const node = {
|
|
8
|
+
type: ListType,
|
|
9
|
+
ordered: token.ordered,
|
|
10
|
+
orderType: token.orderType,
|
|
11
|
+
start: token.start,
|
|
12
|
+
marker: token.marker,
|
|
13
|
+
spread: token.spread,
|
|
14
|
+
children: children,
|
|
15
|
+
};
|
|
16
|
+
return node;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
5
20
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
11
|
-
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_BLOCK,
|
|
12
|
-
});
|
|
13
|
-
this.isContainingBlock = true;
|
|
14
|
-
}
|
|
15
|
-
transformMatch(tokens, api) {
|
|
21
|
+
const postMatch = function (api) {
|
|
22
|
+
const { name: _tokenizer } = this;
|
|
23
|
+
return { transformMatch };
|
|
24
|
+
function transformMatch(tokens) {
|
|
16
25
|
const results = [];
|
|
17
26
|
let listItems = [];
|
|
18
27
|
const resolveList = () => {
|
|
@@ -35,8 +44,7 @@ class ListTokenizer extends BaseBlockTokenizer {
|
|
|
35
44
|
let previousItem = listItems[0];
|
|
36
45
|
for (let i = 1; i < listItems.length; ++i) {
|
|
37
46
|
const currentItem = listItems[i];
|
|
38
|
-
if (previousItem.position.end.line + 1 <
|
|
39
|
-
currentItem.position.start.line) {
|
|
47
|
+
if (previousItem.position.end.line + 1 < currentItem.position.start.line) {
|
|
40
48
|
spread = true;
|
|
41
49
|
break;
|
|
42
50
|
}
|
|
@@ -44,7 +52,7 @@ class ListTokenizer extends BaseBlockTokenizer {
|
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
const list = {
|
|
47
|
-
_tokenizer
|
|
55
|
+
_tokenizer,
|
|
48
56
|
nodeType: ListType,
|
|
49
57
|
ordered: listItems[0].ordered,
|
|
50
58
|
orderType: listItems[0].orderType,
|
|
@@ -93,17 +101,25 @@ class ListTokenizer extends BaseBlockTokenizer {
|
|
|
93
101
|
resolveList();
|
|
94
102
|
return results;
|
|
95
103
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const uniqueName = '@yozora/tokenizer-list';
|
|
107
|
+
|
|
108
|
+
class ListTokenizer extends BaseBlockTokenizer {
|
|
109
|
+
constructor(props = {}) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
super({
|
|
112
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
113
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_BLOCK,
|
|
114
|
+
});
|
|
115
|
+
this.match = () => {
|
|
116
|
+
return {
|
|
117
|
+
isContainingBlock: true,
|
|
118
|
+
eatOpener: () => null,
|
|
119
|
+
};
|
|
105
120
|
};
|
|
106
|
-
|
|
121
|
+
this.postMatch = postMatch;
|
|
122
|
+
this.parse = parse;
|
|
107
123
|
}
|
|
108
124
|
}
|
|
109
125
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export { ListTokenizer } from './tokenizer';
|
|
1
|
+
export { ListTokenizer, ListTokenizer as default } from './tokenizer';
|
|
3
2
|
export { uniqueName as ListTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default ListTokenizer;
|
|
3
|
+
export type { IToken as IListToken, ITokenizerProps as IListTokenizerProps } from './types';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IPostMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IHookContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A list is a sequence of one or more list items of the same type.
|
|
5
|
+
* The list items may be separated by any number of blank lines.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/syntax-tree/mdast#list
|
|
8
|
+
* @see https://github.github.com/gfm/#list
|
|
9
|
+
*/
|
|
10
|
+
export declare const postMatch: IPostMatchBlockHookCreator<IHookContext>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { PostMatchBlockPhaseApi, ResultOfParse, Tokenizer, TokenizerParseBlockHook, TokenizerPostMatchBlockHook, YastBlockToken } from '@yozora/core-tokenizer';
|
|
1
|
+
import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator, IPostMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
3
2
|
import { BaseBlockTokenizer } from '@yozora/core-tokenizer';
|
|
4
|
-
import type {
|
|
3
|
+
import type { IHookContext, INode, IToken, ITokenizerProps, T } from './types';
|
|
5
4
|
/**
|
|
6
5
|
* Params for constructing ListTokenizer
|
|
7
6
|
*/
|
|
@@ -16,17 +15,9 @@ export interface ListTokenizerProps {
|
|
|
16
15
|
* @see https://github.com/syntax-tree/mdast#list
|
|
17
16
|
* @see https://github.github.com/gfm/#list
|
|
18
17
|
*/
|
|
19
|
-
export declare class ListTokenizer extends BaseBlockTokenizer
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* @see TokenizerPostMatchBlockHook
|
|
25
|
-
*/
|
|
26
|
-
transformMatch(tokens: ReadonlyArray<YastBlockToken>, api: PostMatchBlockPhaseApi): YastBlockToken[];
|
|
27
|
-
/**
|
|
28
|
-
* @override
|
|
29
|
-
* @see TokenizerParseBlockHook
|
|
30
|
-
*/
|
|
31
|
-
parseBlock(token: Readonly<Token>, children: YastNode[]): ResultOfParse<T, Node>;
|
|
18
|
+
export declare class ListTokenizer extends BaseBlockTokenizer<T, IToken, INode, IHookContext> implements IBlockTokenizer<T, IToken, INode, IHookContext> {
|
|
19
|
+
constructor(props?: ITokenizerProps);
|
|
20
|
+
readonly match: IMatchBlockHookCreator<T, IToken, IHookContext>;
|
|
21
|
+
readonly postMatch: IPostMatchBlockHookCreator<IHookContext>;
|
|
22
|
+
readonly parse: IParseBlockHookCreator<T, IToken, INode, IHookContext>;
|
|
32
23
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { IList, ListType } from '@yozora/ast';
|
|
2
|
+
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, ITokenizer, IYastBlockToken } from '@yozora/core-tokenizer';
|
|
3
|
+
import type { IListItemToken as IListItemToken0 } from '@yozora/tokenizer-list-item';
|
|
4
4
|
export declare type T = ListType;
|
|
5
|
-
export declare type
|
|
5
|
+
export declare type INode = IList;
|
|
6
6
|
export declare const uniqueName = "@yozora/tokenizer-list";
|
|
7
|
-
export declare type
|
|
8
|
-
export interface
|
|
7
|
+
export declare type IListItemToken = IListItemToken0 & IYastBlockToken;
|
|
8
|
+
export interface IToken extends IPartialYastBlockToken<T> {
|
|
9
9
|
/**
|
|
10
10
|
* Is it an ordered list item.
|
|
11
11
|
*/
|
|
@@ -30,6 +30,7 @@ export interface Token extends PartialYastBlockToken<T> {
|
|
|
30
30
|
/**
|
|
31
31
|
* List items.
|
|
32
32
|
*/
|
|
33
|
-
children:
|
|
33
|
+
children: IListItemToken[];
|
|
34
34
|
}
|
|
35
|
-
export declare type
|
|
35
|
+
export declare type IHookContext = ITokenizer;
|
|
36
|
+
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-list",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "guanghechen",
|
|
6
6
|
"url": "https://github.com/guanghechen/"
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@yozora/ast": "^
|
|
39
|
-
"@yozora/core-tokenizer": "^
|
|
40
|
-
"@yozora/tokenizer-list-item": "^
|
|
38
|
+
"@yozora/ast": "^2.0.0-alpha.0",
|
|
39
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.0",
|
|
40
|
+
"@yozora/tokenizer-list-item": "^2.0.0-alpha.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
|
|
43
43
|
}
|