@yozora/tokenizer-thematic-break 2.1.3 → 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 -127
- package/src/parse.ts +0 -15
- package/src/tokenizer.ts +0 -31
- package/src/types.ts +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-thematic-break",
|
|
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 thematicBreakMatch } from './match'
|
|
2
|
-
export { parse as thematicBreakParse } from './parse'
|
|
3
|
-
export { ThematicBreakTokenizer, ThematicBreakTokenizer as default } from './tokenizer'
|
|
4
|
-
export { uniqueName as ThematicBreakTokenizerName } from './types'
|
|
5
|
-
export type {
|
|
6
|
-
IThis as IThematicBreakHookContext,
|
|
7
|
-
IToken as IThematicBreakToken,
|
|
8
|
-
ITokenizerProps as IThematicBreakTokenizerProps,
|
|
9
|
-
} from './types'
|
package/src/match.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { ThematicBreakType } from '@yozora/ast'
|
|
2
|
-
import { AsciiCodePoint, isUnicodeWhitespaceCharacter } from '@yozora/character'
|
|
3
|
-
import type {
|
|
4
|
-
IBlockToken,
|
|
5
|
-
IMatchBlockHookCreator,
|
|
6
|
-
IPhrasingContentLine,
|
|
7
|
-
IResultOfEatAndInterruptPreviousSibling,
|
|
8
|
-
IResultOfEatOpener,
|
|
9
|
-
} from '@yozora/core-tokenizer'
|
|
10
|
-
import { calcEndPoint, calcStartPoint } from '@yozora/core-tokenizer'
|
|
11
|
-
import type { IThis, IToken, T } from './types'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A line consisting of 0-3 spaces of indentation, followed by a sequence of
|
|
15
|
-
* three or more matching -, _, or * characters, each followed optionally by
|
|
16
|
-
* any number of spaces or tabs, forms a thematic break.
|
|
17
|
-
*
|
|
18
|
-
* @see https://github.github.com/gfm/#thematic-break
|
|
19
|
-
*/
|
|
20
|
-
export const match: IMatchBlockHookCreator<T, IToken, IThis> = function () {
|
|
21
|
-
return {
|
|
22
|
-
isContainingBlock: false,
|
|
23
|
-
eatOpener,
|
|
24
|
-
eatAndInterruptPreviousSibling,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function eatOpener(line: Readonly<IPhrasingContentLine>): IResultOfEatOpener<T, IToken> {
|
|
28
|
-
/**
|
|
29
|
-
* Four spaces is too much
|
|
30
|
-
* @see https://github.github.com/gfm/#example-19
|
|
31
|
-
*/
|
|
32
|
-
if (line.countOfPrecedeSpaces >= 4) return null
|
|
33
|
-
|
|
34
|
-
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line
|
|
35
|
-
if (firstNonWhitespaceIndex + 2 >= endIndex) return null
|
|
36
|
-
|
|
37
|
-
let marker: number
|
|
38
|
-
let count = 0
|
|
39
|
-
let continuous = true
|
|
40
|
-
let hasPotentialInternalSpace = false
|
|
41
|
-
for (let i = firstNonWhitespaceIndex; i < endIndex; ++i) {
|
|
42
|
-
const c = nodePoints[i]
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Spaces are allowed between the characters
|
|
46
|
-
* Spaces are allowed at the end
|
|
47
|
-
* @see https://github.github.com/gfm/#example-21
|
|
48
|
-
* @see https://github.github.com/gfm/#example-22
|
|
49
|
-
* @see https://github.github.com/gfm/#example-23
|
|
50
|
-
* @see https://github.github.com/gfm/#example-24
|
|
51
|
-
*/
|
|
52
|
-
if (isUnicodeWhitespaceCharacter(c.codePoint)) {
|
|
53
|
-
hasPotentialInternalSpace = true
|
|
54
|
-
continue
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* As it is traversed from a non-empty character, if a blank character
|
|
59
|
-
* has been encountered before, it means that there is an internal space
|
|
60
|
-
*/
|
|
61
|
-
if (hasPotentialInternalSpace) {
|
|
62
|
-
continuous = false
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
switch (c.codePoint) {
|
|
66
|
-
/**
|
|
67
|
-
* A line consisting of 0-3 spaces of indentation, followed by a
|
|
68
|
-
* sequence of three or more matching '-', '_', or '*' characters,
|
|
69
|
-
* each followed optionally by any number of spaces or tabs, forms
|
|
70
|
-
* a thematic break
|
|
71
|
-
*/
|
|
72
|
-
case AsciiCodePoint.MINUS_SIGN:
|
|
73
|
-
case AsciiCodePoint.UNDERSCORE:
|
|
74
|
-
case AsciiCodePoint.ASTERISK: {
|
|
75
|
-
if (count <= 0) {
|
|
76
|
-
marker = c.codePoint
|
|
77
|
-
count += 1
|
|
78
|
-
break
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* It is required that all of the non-whitespace characters be the same
|
|
82
|
-
* @see https://github.github.com/gfm/#example-26
|
|
83
|
-
*/
|
|
84
|
-
if (c.codePoint !== marker!) return null
|
|
85
|
-
count += 1
|
|
86
|
-
break
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* No other characters may occur in the line
|
|
90
|
-
* @see https://github.github.com/gfm/#example-25
|
|
91
|
-
*/
|
|
92
|
-
default:
|
|
93
|
-
return null
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Not enough characters
|
|
99
|
-
* @see https://github.github.com/gfm/#example-16
|
|
100
|
-
*/
|
|
101
|
-
if (count < 3) return null
|
|
102
|
-
|
|
103
|
-
const token: IToken = {
|
|
104
|
-
nodeType: ThematicBreakType,
|
|
105
|
-
position: {
|
|
106
|
-
start: calcStartPoint(nodePoints, startIndex),
|
|
107
|
-
end: calcEndPoint(nodePoints, endIndex - 1),
|
|
108
|
-
},
|
|
109
|
-
marker: marker!,
|
|
110
|
-
continuous,
|
|
111
|
-
}
|
|
112
|
-
return { token, nextIndex: endIndex, saturated: true }
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function eatAndInterruptPreviousSibling(
|
|
116
|
-
line: Readonly<IPhrasingContentLine>,
|
|
117
|
-
prevSiblingToken: Readonly<IBlockToken>,
|
|
118
|
-
): IResultOfEatAndInterruptPreviousSibling<T, IToken> {
|
|
119
|
-
const result = eatOpener(line)
|
|
120
|
-
if (result == null) return null
|
|
121
|
-
return {
|
|
122
|
-
token: result.token,
|
|
123
|
-
nextIndex: result.nextIndex,
|
|
124
|
-
remainingSibling: prevSiblingToken,
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
package/src/parse.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ThematicBreakType } from '@yozora/ast'
|
|
2
|
-
import type { IParseBlockHookCreator } from '@yozora/core-tokenizer'
|
|
3
|
-
import type { INode, IThis, IToken, T } from './types'
|
|
4
|
-
|
|
5
|
-
export const parse: IParseBlockHookCreator<T, IToken, INode, IThis> = function (api) {
|
|
6
|
-
return {
|
|
7
|
-
parse: tokens =>
|
|
8
|
-
tokens.map(token => {
|
|
9
|
-
const node: INode = api.shouldReservePosition
|
|
10
|
-
? { type: ThematicBreakType, position: token.position }
|
|
11
|
-
: { type: ThematicBreakType }
|
|
12
|
-
return node
|
|
13
|
-
}),
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/tokenizer.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
IBlockTokenizer,
|
|
3
|
-
IMatchBlockHookCreator,
|
|
4
|
-
IParseBlockHookCreator,
|
|
5
|
-
} from '@yozora/core-tokenizer'
|
|
6
|
-
import { BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer'
|
|
7
|
-
import { match } from './match'
|
|
8
|
-
import { parse } from './parse'
|
|
9
|
-
import type { INode, IThis, IToken, ITokenizerProps, T } from './types'
|
|
10
|
-
import { uniqueName } from './types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Lexical Analyzer for ThematicBreak.
|
|
14
|
-
* @see https://github.github.com/gfm/#thematic-break
|
|
15
|
-
*/
|
|
16
|
-
export class ThematicBreakTokenizer
|
|
17
|
-
extends BaseBlockTokenizer<T, IToken, INode, IThis>
|
|
18
|
-
implements IBlockTokenizer<T, IToken, INode, IThis>
|
|
19
|
-
{
|
|
20
|
-
/* istanbul ignore next */
|
|
21
|
-
constructor(props: ITokenizerProps = {}) {
|
|
22
|
-
super({
|
|
23
|
-
name: props.name ?? uniqueName,
|
|
24
|
-
priority: props.priority ?? TokenizerPriority.ATOMIC,
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public override readonly match: IMatchBlockHookCreator<T, IToken, IThis> = match
|
|
29
|
-
|
|
30
|
-
public override readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis> = parse
|
|
31
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ThematicBreak, ThematicBreakType } from '@yozora/ast'
|
|
2
|
-
import type {
|
|
3
|
-
IBaseBlockTokenizerProps,
|
|
4
|
-
IPartialBlockToken,
|
|
5
|
-
ITokenizer,
|
|
6
|
-
} from '@yozora/core-tokenizer'
|
|
7
|
-
|
|
8
|
-
export type T = ThematicBreakType
|
|
9
|
-
export type INode = ThematicBreak
|
|
10
|
-
export const uniqueName = '@yozora/tokenizer-thematic-break'
|
|
11
|
-
|
|
12
|
-
export interface IToken extends IPartialBlockToken<T> {
|
|
13
|
-
/**
|
|
14
|
-
* CodePoint of '-' / '_' / '*'
|
|
15
|
-
*/
|
|
16
|
-
marker: number
|
|
17
|
-
/**
|
|
18
|
-
* Whether there are no internal spaces between marker characters
|
|
19
|
-
*/
|
|
20
|
-
continuous: boolean
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type IThis = ITokenizer
|
|
24
|
-
|
|
25
|
-
export type ITokenizerProps = Partial<IBaseBlockTokenizerProps>
|