@yozora/tokenizer-delete 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 +55 -47
- package/lib/esm/index.js +55 -47
- package/lib/types/index.d.ts +2 -4
- package/lib/types/tokenizer.d.ts +6 -20
- package/lib/types/types.d.ts +6 -6
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -15,60 +15,68 @@ class DeleteTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
15
15
|
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
16
16
|
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_INLINE,
|
|
17
17
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (i - _startIndex !== 1)
|
|
31
|
-
break;
|
|
32
|
-
let delimiterType = 'both';
|
|
33
|
-
const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1];
|
|
34
|
-
if (preceding != null && character.isWhitespaceCharacter(preceding.codePoint)) {
|
|
35
|
-
delimiterType = 'opener';
|
|
36
|
-
}
|
|
37
|
-
const following = i + 1 === endIndex ? null : nodePoints[i + 1];
|
|
38
|
-
if (following != null && character.isWhitespaceCharacter(following.codePoint)) {
|
|
39
|
-
if (delimiterType !== 'both')
|
|
18
|
+
this.match = api => {
|
|
19
|
+
return {
|
|
20
|
+
findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
|
|
21
|
+
processDelimiterPair,
|
|
22
|
+
};
|
|
23
|
+
function _findDelimiter(startIndex, endIndex) {
|
|
24
|
+
const nodePoints = api.getNodePoints();
|
|
25
|
+
for (let i = startIndex; i < endIndex; ++i) {
|
|
26
|
+
const c = nodePoints[i].codePoint;
|
|
27
|
+
switch (c) {
|
|
28
|
+
case character.AsciiCodePoint.BACKSLASH:
|
|
29
|
+
i += 1;
|
|
40
30
|
break;
|
|
41
|
-
|
|
31
|
+
case character.AsciiCodePoint.TILDE: {
|
|
32
|
+
const _startIndex = i;
|
|
33
|
+
i = coreTokenizer.eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
|
|
34
|
+
if (i - _startIndex !== 1)
|
|
35
|
+
break;
|
|
36
|
+
let delimiterType = 'both';
|
|
37
|
+
const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1];
|
|
38
|
+
if (preceding != null && character.isWhitespaceCharacter(preceding.codePoint)) {
|
|
39
|
+
delimiterType = 'opener';
|
|
40
|
+
}
|
|
41
|
+
const following = i + 1 === endIndex ? null : nodePoints[i + 1];
|
|
42
|
+
if (following != null && character.isWhitespaceCharacter(following.codePoint)) {
|
|
43
|
+
if (delimiterType !== 'both')
|
|
44
|
+
break;
|
|
45
|
+
delimiterType = 'closer';
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
type: delimiterType,
|
|
49
|
+
startIndex: _startIndex,
|
|
50
|
+
endIndex: i + 1,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
42
53
|
}
|
|
43
|
-
return {
|
|
44
|
-
type: delimiterType,
|
|
45
|
-
startIndex: _startIndex,
|
|
46
|
-
endIndex: i + 1,
|
|
47
|
-
};
|
|
48
54
|
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
58
|
+
internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
|
|
59
|
+
const token = {
|
|
60
|
+
nodeType: ast.DeleteType,
|
|
61
|
+
startIndex: openerDelimiter.startIndex,
|
|
62
|
+
endIndex: closerDelimiter.endIndex,
|
|
63
|
+
children: internalTokens,
|
|
64
|
+
};
|
|
65
|
+
return { tokens: [token] };
|
|
49
66
|
}
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
|
|
54
|
-
internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
|
|
55
|
-
const token = {
|
|
56
|
-
nodeType: ast.DeleteType,
|
|
57
|
-
startIndex: openerDelimiter.startIndex,
|
|
58
|
-
endIndex: closerDelimiter.endIndex,
|
|
59
|
-
children: internalTokens,
|
|
60
|
-
};
|
|
61
|
-
return { tokens: [token] };
|
|
62
|
-
}
|
|
63
|
-
parseInline(token, children) {
|
|
64
|
-
const result = {
|
|
65
|
-
type: ast.DeleteType,
|
|
66
|
-
children,
|
|
67
67
|
};
|
|
68
|
-
|
|
68
|
+
this.parse = () => ({
|
|
69
|
+
parse: (token, children) => {
|
|
70
|
+
const result = {
|
|
71
|
+
type: ast.DeleteType,
|
|
72
|
+
children,
|
|
73
|
+
};
|
|
74
|
+
return result;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
exports.DeleteTokenizer = DeleteTokenizer;
|
|
73
81
|
exports.DeleteTokenizerName = uniqueName;
|
|
74
|
-
exports[
|
|
82
|
+
exports["default"] = DeleteTokenizer;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeleteType } from '@yozora/ast';
|
|
2
2
|
import { AsciiCodePoint, isWhitespaceCharacter } from '@yozora/character';
|
|
3
|
-
import { BaseInlineTokenizer, TokenizerPriority, eatOptionalCharacters } from '@yozora/core-tokenizer';
|
|
3
|
+
import { BaseInlineTokenizer, TokenizerPriority, genFindDelimiter, eatOptionalCharacters } from '@yozora/core-tokenizer';
|
|
4
4
|
|
|
5
5
|
const uniqueName = '@yozora/tokenizer-delete';
|
|
6
6
|
|
|
@@ -11,57 +11,65 @@ class DeleteTokenizer extends BaseInlineTokenizer {
|
|
|
11
11
|
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
12
12
|
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_INLINE,
|
|
13
13
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (i - _startIndex !== 1)
|
|
27
|
-
break;
|
|
28
|
-
let delimiterType = 'both';
|
|
29
|
-
const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1];
|
|
30
|
-
if (preceding != null && isWhitespaceCharacter(preceding.codePoint)) {
|
|
31
|
-
delimiterType = 'opener';
|
|
32
|
-
}
|
|
33
|
-
const following = i + 1 === endIndex ? null : nodePoints[i + 1];
|
|
34
|
-
if (following != null && isWhitespaceCharacter(following.codePoint)) {
|
|
35
|
-
if (delimiterType !== 'both')
|
|
14
|
+
this.match = api => {
|
|
15
|
+
return {
|
|
16
|
+
findDelimiter: () => genFindDelimiter(_findDelimiter),
|
|
17
|
+
processDelimiterPair,
|
|
18
|
+
};
|
|
19
|
+
function _findDelimiter(startIndex, endIndex) {
|
|
20
|
+
const nodePoints = api.getNodePoints();
|
|
21
|
+
for (let i = startIndex; i < endIndex; ++i) {
|
|
22
|
+
const c = nodePoints[i].codePoint;
|
|
23
|
+
switch (c) {
|
|
24
|
+
case AsciiCodePoint.BACKSLASH:
|
|
25
|
+
i += 1;
|
|
36
26
|
break;
|
|
37
|
-
|
|
27
|
+
case AsciiCodePoint.TILDE: {
|
|
28
|
+
const _startIndex = i;
|
|
29
|
+
i = eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
|
|
30
|
+
if (i - _startIndex !== 1)
|
|
31
|
+
break;
|
|
32
|
+
let delimiterType = 'both';
|
|
33
|
+
const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1];
|
|
34
|
+
if (preceding != null && isWhitespaceCharacter(preceding.codePoint)) {
|
|
35
|
+
delimiterType = 'opener';
|
|
36
|
+
}
|
|
37
|
+
const following = i + 1 === endIndex ? null : nodePoints[i + 1];
|
|
38
|
+
if (following != null && isWhitespaceCharacter(following.codePoint)) {
|
|
39
|
+
if (delimiterType !== 'both')
|
|
40
|
+
break;
|
|
41
|
+
delimiterType = 'closer';
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
type: delimiterType,
|
|
45
|
+
startIndex: _startIndex,
|
|
46
|
+
endIndex: i + 1,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
38
49
|
}
|
|
39
|
-
return {
|
|
40
|
-
type: delimiterType,
|
|
41
|
-
startIndex: _startIndex,
|
|
42
|
-
endIndex: i + 1,
|
|
43
|
-
};
|
|
44
50
|
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
54
|
+
internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
|
|
55
|
+
const token = {
|
|
56
|
+
nodeType: DeleteType,
|
|
57
|
+
startIndex: openerDelimiter.startIndex,
|
|
58
|
+
endIndex: closerDelimiter.endIndex,
|
|
59
|
+
children: internalTokens,
|
|
60
|
+
};
|
|
61
|
+
return { tokens: [token] };
|
|
45
62
|
}
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
|
|
50
|
-
internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
|
|
51
|
-
const token = {
|
|
52
|
-
nodeType: DeleteType,
|
|
53
|
-
startIndex: openerDelimiter.startIndex,
|
|
54
|
-
endIndex: closerDelimiter.endIndex,
|
|
55
|
-
children: internalTokens,
|
|
56
|
-
};
|
|
57
|
-
return { tokens: [token] };
|
|
58
|
-
}
|
|
59
|
-
parseInline(token, children) {
|
|
60
|
-
const result = {
|
|
61
|
-
type: DeleteType,
|
|
62
|
-
children,
|
|
63
63
|
};
|
|
64
|
-
|
|
64
|
+
this.parse = () => ({
|
|
65
|
+
parse: (token, children) => {
|
|
66
|
+
const result = {
|
|
67
|
+
type: DeleteType,
|
|
68
|
+
children,
|
|
69
|
+
};
|
|
70
|
+
return result;
|
|
71
|
+
},
|
|
72
|
+
});
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export { DeleteTokenizer } from './tokenizer';
|
|
1
|
+
export { DeleteTokenizer, DeleteTokenizer as default } from './tokenizer';
|
|
3
2
|
export { uniqueName as DeleteTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default DeleteTokenizer;
|
|
3
|
+
export type { IToken as IDeleteToken, ITokenizerProps as IDeleteTokenizerProps } from './types';
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { MatchInlinePhaseApi, ResultOfProcessDelimiterPair, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook, YastInlineToken } from '@yozora/core-tokenizer';
|
|
1
|
+
import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
|
|
3
2
|
import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
|
|
4
|
-
import type {
|
|
3
|
+
import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
|
|
5
4
|
/**
|
|
6
5
|
* Lexical Analyzer for Delete.
|
|
7
6
|
*
|
|
@@ -10,21 +9,8 @@ import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
|
|
|
10
9
|
* @see https://github.com/syntax-tree/mdast#delete
|
|
11
10
|
* @see https://github.github.com/gfm/#strikethrough-extension-
|
|
12
11
|
*/
|
|
13
|
-
export declare class DeleteTokenizer extends BaseInlineTokenizer<
|
|
14
|
-
constructor(props?:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @see BaseInlineTokenizer
|
|
18
|
-
*/
|
|
19
|
-
protected _findDelimiter(startIndex: number, endIndex: number, api: Readonly<MatchInlinePhaseApi>): Delimiter | null;
|
|
20
|
-
/**
|
|
21
|
-
* @override
|
|
22
|
-
* @see TokenizerMatchInlineHook
|
|
23
|
-
*/
|
|
24
|
-
processDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, api: Readonly<MatchInlinePhaseApi>): ResultOfProcessDelimiterPair<T, Token, Delimiter>;
|
|
25
|
-
/**
|
|
26
|
-
* @override
|
|
27
|
-
* @see TokenizerParseInlineHook
|
|
28
|
-
*/
|
|
29
|
-
parseInline(token: Token, children: YastNode[]): Node;
|
|
12
|
+
export declare class DeleteTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
|
|
13
|
+
constructor(props?: ITokenizerProps);
|
|
14
|
+
readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
|
|
15
|
+
readonly parse: IParseInlineHookCreator<T, IToken, INode>;
|
|
30
16
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { DeleteType, IDelete } from '@yozora/ast';
|
|
2
|
+
import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = DeleteType;
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type INode = IDelete;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-delete";
|
|
6
|
-
export declare type
|
|
7
|
-
export declare type
|
|
8
|
-
export declare type
|
|
6
|
+
export declare type IToken = IPartialYastInlineToken<T>;
|
|
7
|
+
export declare type IDelimiter = IYastTokenDelimiter;
|
|
8
|
+
export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-delete",
|
|
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/character": "^
|
|
40
|
-
"@yozora/core-tokenizer": "^
|
|
38
|
+
"@yozora/ast": "^2.0.0-alpha.0",
|
|
39
|
+
"@yozora/character": "^2.0.0-alpha.0",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
|
|
43
43
|
}
|