@yozora/tokenizer-blockquote 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 -133
- package/src/parse.ts +0 -17
- package/src/tokenizer.ts +0 -32
- package/src/types.ts +0 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-blockquote",
|
|
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 blockquoteMatch } from './match'
|
|
2
|
-
export { parse as blockquoteParse } from './parse'
|
|
3
|
-
export { BlockquoteTokenizer, BlockquoteTokenizer as default } from './tokenizer'
|
|
4
|
-
export { uniqueName as BlockquoteTokenizerName } from './types'
|
|
5
|
-
export type {
|
|
6
|
-
IThis as IBlockquoteHookContext,
|
|
7
|
-
IToken as IBlockquoteToken,
|
|
8
|
-
ITokenizerProps as IBlockquoteTokenizerProps,
|
|
9
|
-
} from './types'
|
package/src/match.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { BlockquoteType } from '@yozora/ast'
|
|
2
|
-
import { AsciiCodePoint, VirtualCodePoint, isSpaceCharacter } from '@yozora/character'
|
|
3
|
-
import type {
|
|
4
|
-
IBlockToken,
|
|
5
|
-
IMatchBlockHookCreator,
|
|
6
|
-
IPhrasingContentLine,
|
|
7
|
-
IResultOfEatAndInterruptPreviousSibling,
|
|
8
|
-
IResultOfEatContinuationText,
|
|
9
|
-
IResultOfEatOpener,
|
|
10
|
-
} from '@yozora/core-tokenizer'
|
|
11
|
-
import { calcEndPoint, calcStartPoint } from '@yozora/core-tokenizer'
|
|
12
|
-
import type { IThis, IToken, T } from './types'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A block quote marker consists of 0-3 spaces of initial indent, plus
|
|
16
|
-
* (a) the character > together with a following space, or
|
|
17
|
-
* (b) a single character > not followed by a space.
|
|
18
|
-
*
|
|
19
|
-
* The following rules define block quotes:
|
|
20
|
-
* - Basic case. If a string of lines Ls constitute a sequence of blocks Bs,
|
|
21
|
-
* then the result of prepending a block quote marker to the beginning of
|
|
22
|
-
* each line in Ls is a block quote containing Bs.
|
|
23
|
-
*
|
|
24
|
-
* - Laziness. If a string of lines Ls constitute a block quote with contents
|
|
25
|
-
* Bs, then the result of deleting the initial block quote marker from one
|
|
26
|
-
* or more lines in which the next non-whitespace character after the block
|
|
27
|
-
* quote marker is paragraph continuation text is a block quote with Bs as
|
|
28
|
-
* its content. Paragraph continuation text is text that will be parsed as
|
|
29
|
-
* part of the content of a paragraph, but does not occur at the beginning
|
|
30
|
-
* of the paragraph.
|
|
31
|
-
*
|
|
32
|
-
* - Consecutiveness. A document cannot contain two block quotes in a row
|
|
33
|
-
* unless there is a blank line between them.
|
|
34
|
-
*
|
|
35
|
-
* @see https://github.com/syntax-tree/mdast#blockquote
|
|
36
|
-
* @see https://github.github.com/gfm/#block-quotes
|
|
37
|
-
*/
|
|
38
|
-
export const match: IMatchBlockHookCreator<T, IToken, IThis> = function () {
|
|
39
|
-
return {
|
|
40
|
-
isContainingBlock: true,
|
|
41
|
-
eatOpener,
|
|
42
|
-
eatAndInterruptPreviousSibling,
|
|
43
|
-
eatContinuationText,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function eatOpener(line: Readonly<IPhrasingContentLine>): IResultOfEatOpener<T, IToken> {
|
|
47
|
-
/**
|
|
48
|
-
* The '>' characters can be indented 1-3 spaces
|
|
49
|
-
* @see https://github.github.com/gfm/#example-209
|
|
50
|
-
*/
|
|
51
|
-
if (line.countOfPrecedeSpaces >= 4) return null
|
|
52
|
-
|
|
53
|
-
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line
|
|
54
|
-
if (
|
|
55
|
-
firstNonWhitespaceIndex >= endIndex ||
|
|
56
|
-
nodePoints[firstNonWhitespaceIndex].codePoint !== AsciiCodePoint.CLOSE_ANGLE
|
|
57
|
-
)
|
|
58
|
-
return null
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* A block quote marker consists of 0-3 spaces of initial indent, plus
|
|
62
|
-
* (a) the character > together with a following space, or
|
|
63
|
-
* (b) a single character > not followed by a space.
|
|
64
|
-
* @see https://github.github.com/gfm/#block-quote-marker
|
|
65
|
-
*/
|
|
66
|
-
let nextIndex = firstNonWhitespaceIndex + 1
|
|
67
|
-
if (nextIndex < endIndex && isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
|
|
68
|
-
nextIndex += 1
|
|
69
|
-
/**
|
|
70
|
-
* When the '>' followed by a tab, it is treated as if it were expanded
|
|
71
|
-
* into three spaces.
|
|
72
|
-
* @see https://github.github.com/gfm/#example-6
|
|
73
|
-
*/
|
|
74
|
-
if (nextIndex < endIndex && nodePoints[nextIndex].codePoint === VirtualCodePoint.SPACE) {
|
|
75
|
-
nextIndex += 1
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const token: IToken = {
|
|
80
|
-
nodeType: BlockquoteType,
|
|
81
|
-
position: {
|
|
82
|
-
start: calcStartPoint(nodePoints, startIndex),
|
|
83
|
-
end: calcEndPoint(nodePoints, nextIndex - 1),
|
|
84
|
-
},
|
|
85
|
-
children: [],
|
|
86
|
-
}
|
|
87
|
-
return { token, nextIndex }
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function eatAndInterruptPreviousSibling(
|
|
91
|
-
line: Readonly<IPhrasingContentLine>,
|
|
92
|
-
prevSiblingToken: Readonly<IBlockToken>,
|
|
93
|
-
): IResultOfEatAndInterruptPreviousSibling<T, IToken> {
|
|
94
|
-
const result = eatOpener(line)
|
|
95
|
-
if (result == null) return null
|
|
96
|
-
return {
|
|
97
|
-
token: result.token,
|
|
98
|
-
nextIndex: result.nextIndex,
|
|
99
|
-
remainingSibling: prevSiblingToken,
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function eatContinuationText(
|
|
104
|
-
line: Readonly<IPhrasingContentLine>,
|
|
105
|
-
token: IToken,
|
|
106
|
-
parentToken: Readonly<IBlockToken>,
|
|
107
|
-
): IResultOfEatContinuationText {
|
|
108
|
-
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
countOfPrecedeSpaces >= 4 ||
|
|
112
|
-
firstNonWhitespaceIndex >= endIndex ||
|
|
113
|
-
nodePoints[firstNonWhitespaceIndex].codePoint !== AsciiCodePoint.CLOSE_ANGLE
|
|
114
|
-
) {
|
|
115
|
-
/**
|
|
116
|
-
* It is a consequence of the Laziness rule that any number of initial
|
|
117
|
-
* `>`s may be omitted on a continuation line of a nested block quote
|
|
118
|
-
* @see https://github.github.com/gfm/#example-229
|
|
119
|
-
*/
|
|
120
|
-
if (parentToken.nodeType === BlockquoteType) {
|
|
121
|
-
return { status: 'opening', nextIndex: startIndex }
|
|
122
|
-
}
|
|
123
|
-
return { status: 'notMatched' }
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const nextIndex =
|
|
127
|
-
firstNonWhitespaceIndex + 1 < endIndex &&
|
|
128
|
-
isSpaceCharacter(nodePoints[firstNonWhitespaceIndex + 1].codePoint)
|
|
129
|
-
? firstNonWhitespaceIndex + 2
|
|
130
|
-
: firstNonWhitespaceIndex + 1
|
|
131
|
-
return { status: 'opening', nextIndex }
|
|
132
|
-
}
|
|
133
|
-
}
|
package/src/parse.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Node } from '@yozora/ast'
|
|
2
|
-
import { BlockquoteType } from '@yozora/ast'
|
|
3
|
-
import type { IParseBlockHookCreator } from '@yozora/core-tokenizer'
|
|
4
|
-
import type { INode, IThis, IToken, T } from './types'
|
|
5
|
-
|
|
6
|
-
export const parse: IParseBlockHookCreator<T, IToken, INode, IThis> = function (api) {
|
|
7
|
-
return {
|
|
8
|
-
parse: tokens =>
|
|
9
|
-
tokens.map(token => {
|
|
10
|
-
const children: Node[] = api.parseBlockTokens(token.children)
|
|
11
|
-
const node: INode = api.shouldReservePosition
|
|
12
|
-
? { type: BlockquoteType, position: token.position, children }
|
|
13
|
-
: { type: BlockquoteType, children }
|
|
14
|
-
return node
|
|
15
|
-
}),
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/tokenizer.ts
DELETED
|
@@ -1,32 +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 Blockquote.
|
|
14
|
-
* @see https://github.com/syntax-tree/mdast#blockquote
|
|
15
|
-
* @see https://github.github.com/gfm/#block-quotes
|
|
16
|
-
*/
|
|
17
|
-
export class BlockquoteTokenizer
|
|
18
|
-
extends BaseBlockTokenizer<T, IToken, INode, IThis>
|
|
19
|
-
implements IBlockTokenizer<T, 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_BLOCK,
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public override readonly match: IMatchBlockHookCreator<T, IToken, IThis> = match
|
|
30
|
-
|
|
31
|
-
public override readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis> = parse
|
|
32
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Blockquote, BlockquoteType } from '@yozora/ast'
|
|
2
|
-
import type {
|
|
3
|
-
IBaseBlockTokenizerProps,
|
|
4
|
-
IBlockToken,
|
|
5
|
-
IPartialBlockToken,
|
|
6
|
-
ITokenizer,
|
|
7
|
-
} from '@yozora/core-tokenizer'
|
|
8
|
-
|
|
9
|
-
export type T = BlockquoteType
|
|
10
|
-
export type INode = Blockquote
|
|
11
|
-
export const uniqueName = '@yozora/tokenizer-blockquote'
|
|
12
|
-
|
|
13
|
-
export interface IToken extends IPartialBlockToken<T> {
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
children: IBlockToken[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type IThis = ITokenizer
|
|
21
|
-
|
|
22
|
-
export type ITokenizerProps = Partial<IBaseBlockTokenizerProps>
|