@yozora/tokenizer-delete 2.1.2 → 2.1.4
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/package.json +6 -6
- package/src/index.ts +0 -9
- package/src/match.ts +0 -98
- package/src/parse.ts +0 -17
- package/src/tokenizer.ts +0 -32
- package/src/types.ts +0 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-delete",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "guanghechen",
|
|
6
6
|
"url": "https://github.com/guanghechen/"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"lib/",
|
|
30
|
-
"
|
|
30
|
+
"lib/**/*.map",
|
|
31
31
|
"package.json",
|
|
32
32
|
"CHANGELOG.md",
|
|
33
33
|
"LICENSE",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"test": "cross-env TS_NODE_FILES=true NODE_OPTIONS=--experimental-vm-modules jest --config ../../jest.config.mjs --rootDir ."
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@yozora/ast": "^2.1.
|
|
43
|
-
"@yozora/character": "^2.1.
|
|
44
|
-
"@yozora/core-tokenizer": "^2.1.
|
|
42
|
+
"@yozora/ast": "^2.1.4",
|
|
43
|
+
"@yozora/character": "^2.1.4",
|
|
44
|
+
"@yozora/core-tokenizer": "^2.1.4"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "aa464ed1e3cd84892773a833910cfc53a556bf5f"
|
|
47
47
|
}
|
package/src/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { DeleteType } from '@yozora/ast'
|
|
2
|
-
import type { INodePoint } from '@yozora/character'
|
|
3
|
-
import { AsciiCodePoint, isWhitespaceCharacter } from '@yozora/character'
|
|
4
|
-
import type {
|
|
5
|
-
IInlineToken,
|
|
6
|
-
IMatchInlineHookCreator,
|
|
7
|
-
IResultOfProcessDelimiterPair,
|
|
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<IInlineToken>,
|
|
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
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Delete, DeleteType } from '@yozora/ast'
|
|
2
|
-
import type {
|
|
3
|
-
IBaseInlineTokenizerProps,
|
|
4
|
-
IPartialInlineToken,
|
|
5
|
-
ITokenDelimiter,
|
|
6
|
-
ITokenizer,
|
|
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 = IPartialInlineToken<T>
|
|
14
|
-
|
|
15
|
-
export type IDelimiter = ITokenDelimiter
|
|
16
|
-
|
|
17
|
-
export type IThis = ITokenizer
|
|
18
|
-
|
|
19
|
-
export type ITokenizerProps = Partial<IBaseInlineTokenizerProps>
|