@yozora/tokenizer-delete 2.0.4 → 2.0.5
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 → index.cjs} +5 -6
- package/lib/esm/{index.js → index.mjs} +4 -5
- package/lib/types/index.d.ts +6 -6
- package/package.json +18 -14
- package/src/index.ts +9 -0
- package/src/match.ts +98 -0
- package/src/parse.ts +17 -0
- package/src/tokenizer.ts +32 -0
- package/src/types.ts +19 -0
|
@@ -73,18 +73,17 @@ const uniqueName = '@yozora/tokenizer-delete';
|
|
|
73
73
|
|
|
74
74
|
class DeleteTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
75
75
|
constructor(props = {}) {
|
|
76
|
-
var _a, _b;
|
|
77
76
|
super({
|
|
78
|
-
name:
|
|
79
|
-
priority:
|
|
77
|
+
name: props.name ?? uniqueName,
|
|
78
|
+
priority: props.priority ?? coreTokenizer.TokenizerPriority.CONTAINING_INLINE,
|
|
80
79
|
});
|
|
81
|
-
this.match = match;
|
|
82
|
-
this.parse = parse;
|
|
83
80
|
}
|
|
81
|
+
match = match;
|
|
82
|
+
parse = parse;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
exports.DeleteTokenizer = DeleteTokenizer;
|
|
87
86
|
exports.DeleteTokenizerName = uniqueName;
|
|
88
|
-
exports
|
|
87
|
+
exports.default = DeleteTokenizer;
|
|
89
88
|
exports.deleteMatch = match;
|
|
90
89
|
exports.deleteParse = parse;
|
|
@@ -69,14 +69,13 @@ const uniqueName = '@yozora/tokenizer-delete';
|
|
|
69
69
|
|
|
70
70
|
class DeleteTokenizer extends BaseInlineTokenizer {
|
|
71
71
|
constructor(props = {}) {
|
|
72
|
-
var _a, _b;
|
|
73
72
|
super({
|
|
74
|
-
name:
|
|
75
|
-
priority:
|
|
73
|
+
name: props.name ?? uniqueName,
|
|
74
|
+
priority: props.priority ?? TokenizerPriority.CONTAINING_INLINE,
|
|
76
75
|
});
|
|
77
|
-
this.match = match;
|
|
78
|
-
this.parse = parse;
|
|
79
76
|
}
|
|
77
|
+
match = match;
|
|
78
|
+
parse = parse;
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
export { DeleteTokenizer, uniqueName as DeleteTokenizerName, DeleteTokenizer as default, match as deleteMatch, parse as deleteParse };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IPartialYastInlineToken, ITokenizer, IBaseInlineTokenizerProps, IYastTokenDelimiter, IMatchInlineHookCreator, IParseInlineHookCreator, BaseInlineTokenizer, IInlineTokenizer } from '@yozora/core-tokenizer';
|
|
2
2
|
import { DeleteType, Delete } from '@yozora/ast';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type T = DeleteType;
|
|
5
|
+
type INode = Delete;
|
|
6
6
|
declare const uniqueName = "@yozora/tokenizer-delete";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
type IToken = IPartialYastInlineToken<T>;
|
|
8
|
+
type IDelimiter = IYastTokenDelimiter;
|
|
9
|
+
type IThis = ITokenizer;
|
|
10
|
+
type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Strikethrough text is any text wrapped in two tildes (~).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-delete",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "guanghechen",
|
|
6
6
|
"url": "https://github.com/guanghechen/"
|
|
@@ -11,33 +11,37 @@
|
|
|
11
11
|
"directory": "tokenizers/delete"
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://github.com/yozorajs/yozora/tree/release-2.x.x/tokenizers/delete",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
"types": "./lib/types/index.d.ts",
|
|
17
|
+
"import": "./lib/esm/index.mjs",
|
|
18
|
+
"require": "./lib/cjs/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"source": "./src/index.ts",
|
|
21
|
+
"types": "./lib/types/index.d.ts",
|
|
22
|
+
"main": "./lib/cjs/index.cjs",
|
|
23
|
+
"module": "./lib/esm/index.mjs",
|
|
18
24
|
"license": "MIT",
|
|
19
25
|
"engines": {
|
|
20
26
|
"node": ">= 16.0.0"
|
|
21
27
|
},
|
|
22
28
|
"files": [
|
|
23
29
|
"lib/",
|
|
24
|
-
"
|
|
25
|
-
"!lib/**/*.d.ts.map",
|
|
30
|
+
"src/",
|
|
26
31
|
"package.json",
|
|
27
32
|
"CHANGELOG.md",
|
|
28
33
|
"LICENSE",
|
|
29
34
|
"README.md"
|
|
30
35
|
],
|
|
31
36
|
"scripts": {
|
|
32
|
-
"build": "cross-env NODE_ENV=production rollup -c ../../rollup.config.
|
|
33
|
-
"prebuild": "rimraf lib/",
|
|
37
|
+
"build": "rimraf lib/ && cross-env NODE_ENV=production rollup -c ../../rollup.config.mjs",
|
|
34
38
|
"prepublishOnly": "cross-env ROLLUP_SHOULD_SOURCEMAP=false yarn build",
|
|
35
|
-
"test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.
|
|
39
|
+
"test": "cross-env TS_NODE_FILES=true NODE_OPTIONS=--experimental-vm-modules jest --config ../../jest.config.mjs --rootDir ."
|
|
36
40
|
},
|
|
37
41
|
"dependencies": {
|
|
38
|
-
"@yozora/ast": "^2.0.
|
|
39
|
-
"@yozora/character": "^2.0.
|
|
40
|
-
"@yozora/core-tokenizer": "^2.0.
|
|
42
|
+
"@yozora/ast": "^2.0.5",
|
|
43
|
+
"@yozora/character": "^2.0.5",
|
|
44
|
+
"@yozora/core-tokenizer": "^2.0.5"
|
|
41
45
|
},
|
|
42
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "7ba3bab49fe65cf2f57082c0503af73da9356cf0"
|
|
43
47
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { match as deleteMatch } from './match'
|
|
2
|
+
export { parse as deleteParse } from './parse'
|
|
3
|
+
export { DeleteTokenizer, DeleteTokenizer as default } from './tokenizer'
|
|
4
|
+
export { uniqueName as DeleteTokenizerName } from './types'
|
|
5
|
+
export type {
|
|
6
|
+
IThis as IDeleteHookContext,
|
|
7
|
+
IToken as IDeleteToken,
|
|
8
|
+
ITokenizerProps as IDeleteTokenizerProps,
|
|
9
|
+
} from './types'
|
package/src/match.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { DeleteType } from '@yozora/ast'
|
|
2
|
+
import type { INodePoint } from '@yozora/character'
|
|
3
|
+
import { AsciiCodePoint, isWhitespaceCharacter } from '@yozora/character'
|
|
4
|
+
import type {
|
|
5
|
+
IMatchInlineHookCreator,
|
|
6
|
+
IResultOfProcessDelimiterPair,
|
|
7
|
+
IYastInlineToken,
|
|
8
|
+
} from '@yozora/core-tokenizer'
|
|
9
|
+
import { eatOptionalCharacters, genFindDelimiter } from '@yozora/core-tokenizer'
|
|
10
|
+
import type { IDelimiter, IThis, IToken, T } from './types'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Strikethrough text is any text wrapped in two tildes (~).
|
|
14
|
+
*
|
|
15
|
+
* @see https://github.com/syntax-tree/mdast#delete
|
|
16
|
+
* @see https://github.github.com/gfm/#strikethrough-extension-
|
|
17
|
+
*/
|
|
18
|
+
export const match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis> = function (api) {
|
|
19
|
+
return {
|
|
20
|
+
findDelimiter: () => genFindDelimiter<IDelimiter>(_findDelimiter),
|
|
21
|
+
processDelimiterPair,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _findDelimiter(startIndex: number, endIndex: number): IDelimiter | null {
|
|
25
|
+
const nodePoints: ReadonlyArray<INodePoint> = api.getNodePoints()
|
|
26
|
+
for (let i = startIndex; i < endIndex; ++i) {
|
|
27
|
+
const c = nodePoints[i].codePoint
|
|
28
|
+
switch (c) {
|
|
29
|
+
// Escape backslash
|
|
30
|
+
case AsciiCodePoint.BACKSLASH:
|
|
31
|
+
i += 1
|
|
32
|
+
break
|
|
33
|
+
/**
|
|
34
|
+
* Strike through text is any text wrapped in two tildes '~'
|
|
35
|
+
* @see https://github.github.com/gfm/#strikethrough-extension-
|
|
36
|
+
*/
|
|
37
|
+
case AsciiCodePoint.TILDE: {
|
|
38
|
+
const _startIndex = i
|
|
39
|
+
i = eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1
|
|
40
|
+
if (i - _startIndex !== 1) break
|
|
41
|
+
|
|
42
|
+
let delimiterType: IDelimiter['type'] = 'both'
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* If the preceding character is a whitespace, it cannot be used as a
|
|
46
|
+
* closer delimiter
|
|
47
|
+
*/
|
|
48
|
+
const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1]
|
|
49
|
+
if (preceding != null && isWhitespaceCharacter(preceding.codePoint)) {
|
|
50
|
+
delimiterType = 'opener'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* If the following character is a whitespace, it cannot be used as a
|
|
55
|
+
* opener delimiter
|
|
56
|
+
*/
|
|
57
|
+
const following = i + 1 === endIndex ? null : nodePoints[i + 1]
|
|
58
|
+
if (following != null && isWhitespaceCharacter(following.codePoint)) {
|
|
59
|
+
/**
|
|
60
|
+
* If it can neither be used as a opener or closer delimiter, it
|
|
61
|
+
* is not a valid delimiter
|
|
62
|
+
*/
|
|
63
|
+
if (delimiterType !== 'both') break
|
|
64
|
+
delimiterType = 'closer'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
type: delimiterType,
|
|
69
|
+
startIndex: _startIndex,
|
|
70
|
+
endIndex: i + 1,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function processDelimiterPair(
|
|
79
|
+
openerDelimiter: IDelimiter,
|
|
80
|
+
closerDelimiter: IDelimiter,
|
|
81
|
+
internalTokens: ReadonlyArray<IYastInlineToken>,
|
|
82
|
+
): IResultOfProcessDelimiterPair<T, IToken, IDelimiter> {
|
|
83
|
+
// eslint-disable-next-line no-param-reassign
|
|
84
|
+
internalTokens = api.resolveInternalTokens(
|
|
85
|
+
internalTokens,
|
|
86
|
+
openerDelimiter.endIndex,
|
|
87
|
+
closerDelimiter.startIndex,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
const token: IToken = {
|
|
91
|
+
nodeType: DeleteType,
|
|
92
|
+
startIndex: openerDelimiter.startIndex,
|
|
93
|
+
endIndex: closerDelimiter.endIndex,
|
|
94
|
+
children: internalTokens,
|
|
95
|
+
}
|
|
96
|
+
return { tokens: [token] }
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/parse.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Node } from '@yozora/ast'
|
|
2
|
+
import { DeleteType } from '@yozora/ast'
|
|
3
|
+
import type { IParseInlineHookCreator } from '@yozora/core-tokenizer'
|
|
4
|
+
import type { INode, IThis, IToken, T } from './types'
|
|
5
|
+
|
|
6
|
+
export const parse: IParseInlineHookCreator<T, IToken, INode, IThis> = function (api) {
|
|
7
|
+
return {
|
|
8
|
+
parse: tokens =>
|
|
9
|
+
tokens.map(token => {
|
|
10
|
+
const children: Node[] = api.parseInlineTokens(token.children)
|
|
11
|
+
const node: INode = api.shouldReservePosition
|
|
12
|
+
? { type: DeleteType, position: api.calcPosition(token), children }
|
|
13
|
+
: { type: DeleteType, children }
|
|
14
|
+
return node
|
|
15
|
+
}),
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/tokenizer.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IInlineTokenizer,
|
|
3
|
+
IMatchInlineHookCreator,
|
|
4
|
+
IParseInlineHookCreator,
|
|
5
|
+
} from '@yozora/core-tokenizer'
|
|
6
|
+
import { BaseInlineTokenizer, TokenizerPriority } from '@yozora/core-tokenizer'
|
|
7
|
+
import { match } from './match'
|
|
8
|
+
import { parse } from './parse'
|
|
9
|
+
import type { IDelimiter, INode, IThis, IToken, ITokenizerProps, T } from './types'
|
|
10
|
+
import { uniqueName } from './types'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Lexical Analyzer for Delete.
|
|
14
|
+
* @see https://github.com/syntax-tree/mdast#delete
|
|
15
|
+
* @see https://github.github.com/gfm/#strikethrough-extension-
|
|
16
|
+
*/
|
|
17
|
+
export class DeleteTokenizer
|
|
18
|
+
extends BaseInlineTokenizer<T, IDelimiter, IToken, INode, IThis>
|
|
19
|
+
implements IInlineTokenizer<T, IDelimiter, IToken, INode, IThis>
|
|
20
|
+
{
|
|
21
|
+
/* istanbul ignore next */
|
|
22
|
+
constructor(props: ITokenizerProps = {}) {
|
|
23
|
+
super({
|
|
24
|
+
name: props.name ?? uniqueName,
|
|
25
|
+
priority: props.priority ?? TokenizerPriority.CONTAINING_INLINE,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public override readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis> = match
|
|
30
|
+
|
|
31
|
+
public override readonly parse: IParseInlineHookCreator<T, IToken, INode, IThis> = parse
|
|
32
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Delete, DeleteType } from '@yozora/ast'
|
|
2
|
+
import type {
|
|
3
|
+
IBaseInlineTokenizerProps,
|
|
4
|
+
IPartialYastInlineToken,
|
|
5
|
+
ITokenizer,
|
|
6
|
+
IYastTokenDelimiter,
|
|
7
|
+
} from '@yozora/core-tokenizer'
|
|
8
|
+
|
|
9
|
+
export type T = DeleteType
|
|
10
|
+
export type INode = Delete
|
|
11
|
+
export const uniqueName = '@yozora/tokenizer-delete'
|
|
12
|
+
|
|
13
|
+
export type IToken = IPartialYastInlineToken<T>
|
|
14
|
+
|
|
15
|
+
export type IDelimiter = IYastTokenDelimiter
|
|
16
|
+
|
|
17
|
+
export type IThis = ITokenizer
|
|
18
|
+
|
|
19
|
+
export type ITokenizerProps = Partial<IBaseInlineTokenizerProps>
|