@yozora/tokenizer-blockquote 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 +41 -28
- package/lib/esm/index.js +40 -29
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +27 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -47
- package/lib/types/types.d.ts +7 -6
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -6,31 +6,24 @@ var ast = require('@yozora/ast');
|
|
|
6
6
|
var character = require('@yozora/character');
|
|
7
7
|
var coreTokenizer = require('@yozora/core-tokenizer');
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
this.isContainingBlock = true;
|
|
19
|
-
}
|
|
20
|
-
eatOpener(line) {
|
|
9
|
+
const match = function () {
|
|
10
|
+
return {
|
|
11
|
+
isContainingBlock: true,
|
|
12
|
+
eatOpener,
|
|
13
|
+
eatAndInterruptPreviousSibling,
|
|
14
|
+
eatContinuationText,
|
|
15
|
+
};
|
|
16
|
+
function eatOpener(line) {
|
|
21
17
|
if (line.countOfPrecedeSpaces >= 4)
|
|
22
18
|
return null;
|
|
23
19
|
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
|
|
24
20
|
if (firstNonWhitespaceIndex >= endIndex ||
|
|
25
|
-
nodePoints[firstNonWhitespaceIndex].codePoint !==
|
|
26
|
-
character.AsciiCodePoint.CLOSE_ANGLE)
|
|
21
|
+
nodePoints[firstNonWhitespaceIndex].codePoint !== character.AsciiCodePoint.CLOSE_ANGLE)
|
|
27
22
|
return null;
|
|
28
23
|
let nextIndex = firstNonWhitespaceIndex + 1;
|
|
29
|
-
if (nextIndex < endIndex &&
|
|
30
|
-
character.isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
|
|
24
|
+
if (nextIndex < endIndex && character.isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
|
|
31
25
|
nextIndex += 1;
|
|
32
|
-
if (nextIndex < endIndex &&
|
|
33
|
-
nodePoints[nextIndex].codePoint === character.VirtualCodePoint.SPACE) {
|
|
26
|
+
if (nextIndex < endIndex && nodePoints[nextIndex].codePoint === character.VirtualCodePoint.SPACE) {
|
|
34
27
|
nextIndex += 1;
|
|
35
28
|
}
|
|
36
29
|
}
|
|
@@ -44,8 +37,8 @@ class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
44
37
|
};
|
|
45
38
|
return { token, nextIndex };
|
|
46
39
|
}
|
|
47
|
-
eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
48
|
-
const result =
|
|
40
|
+
function eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
41
|
+
const result = eatOpener(line);
|
|
49
42
|
if (result == null)
|
|
50
43
|
return null;
|
|
51
44
|
return {
|
|
@@ -54,12 +47,11 @@ class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
54
47
|
remainingSibling: prevSiblingToken,
|
|
55
48
|
};
|
|
56
49
|
}
|
|
57
|
-
eatContinuationText(line, token, parentToken) {
|
|
58
|
-
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces
|
|
50
|
+
function eatContinuationText(line, token, parentToken) {
|
|
51
|
+
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line;
|
|
59
52
|
if (countOfPrecedeSpaces >= 4 ||
|
|
60
53
|
firstNonWhitespaceIndex >= endIndex ||
|
|
61
|
-
nodePoints[firstNonWhitespaceIndex].codePoint !==
|
|
62
|
-
character.AsciiCodePoint.CLOSE_ANGLE) {
|
|
54
|
+
nodePoints[firstNonWhitespaceIndex].codePoint !== character.AsciiCodePoint.CLOSE_ANGLE) {
|
|
63
55
|
if (parentToken.nodeType === ast.BlockquoteType) {
|
|
64
56
|
return { status: 'opening', nextIndex: startIndex };
|
|
65
57
|
}
|
|
@@ -71,12 +63,33 @@ class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
71
63
|
: firstNonWhitespaceIndex + 1;
|
|
72
64
|
return { status: 'opening', nextIndex };
|
|
73
65
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const parse = function () {
|
|
69
|
+
return {
|
|
70
|
+
parse: (_token, children) => {
|
|
71
|
+
const node = { type: ast.BlockquoteType, children };
|
|
72
|
+
return node;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const uniqueName = '@yozora/tokenizer-blockquote';
|
|
78
|
+
|
|
79
|
+
class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
80
|
+
constructor(props = {}) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
super({
|
|
83
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
84
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_BLOCK,
|
|
85
|
+
});
|
|
86
|
+
this.match = match;
|
|
87
|
+
this.parse = parse;
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
exports.BlockquoteTokenizer = BlockquoteTokenizer;
|
|
81
92
|
exports.BlockquoteTokenizerName = uniqueName;
|
|
82
|
-
exports
|
|
93
|
+
exports.blockquoteMatch = match;
|
|
94
|
+
exports.blockquoteParse = parse;
|
|
95
|
+
exports["default"] = BlockquoteTokenizer;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
import { BlockquoteType } from '@yozora/ast';
|
|
2
2
|
import { AsciiCodePoint, isSpaceCharacter, VirtualCodePoint } from '@yozora/character';
|
|
3
|
-
import {
|
|
3
|
+
import { calcStartYastNodePoint, calcEndYastNodePoint, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
14
|
-
this.isContainingBlock = true;
|
|
15
|
-
}
|
|
16
|
-
eatOpener(line) {
|
|
5
|
+
const match = function () {
|
|
6
|
+
return {
|
|
7
|
+
isContainingBlock: true,
|
|
8
|
+
eatOpener,
|
|
9
|
+
eatAndInterruptPreviousSibling,
|
|
10
|
+
eatContinuationText,
|
|
11
|
+
};
|
|
12
|
+
function eatOpener(line) {
|
|
17
13
|
if (line.countOfPrecedeSpaces >= 4)
|
|
18
14
|
return null;
|
|
19
15
|
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
|
|
20
16
|
if (firstNonWhitespaceIndex >= endIndex ||
|
|
21
|
-
nodePoints[firstNonWhitespaceIndex].codePoint !==
|
|
22
|
-
AsciiCodePoint.CLOSE_ANGLE)
|
|
17
|
+
nodePoints[firstNonWhitespaceIndex].codePoint !== AsciiCodePoint.CLOSE_ANGLE)
|
|
23
18
|
return null;
|
|
24
19
|
let nextIndex = firstNonWhitespaceIndex + 1;
|
|
25
|
-
if (nextIndex < endIndex &&
|
|
26
|
-
isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
|
|
20
|
+
if (nextIndex < endIndex && isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
|
|
27
21
|
nextIndex += 1;
|
|
28
|
-
if (nextIndex < endIndex &&
|
|
29
|
-
nodePoints[nextIndex].codePoint === VirtualCodePoint.SPACE) {
|
|
22
|
+
if (nextIndex < endIndex && nodePoints[nextIndex].codePoint === VirtualCodePoint.SPACE) {
|
|
30
23
|
nextIndex += 1;
|
|
31
24
|
}
|
|
32
25
|
}
|
|
@@ -40,8 +33,8 @@ class BlockquoteTokenizer extends BaseBlockTokenizer {
|
|
|
40
33
|
};
|
|
41
34
|
return { token, nextIndex };
|
|
42
35
|
}
|
|
43
|
-
eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
44
|
-
const result =
|
|
36
|
+
function eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
37
|
+
const result = eatOpener(line);
|
|
45
38
|
if (result == null)
|
|
46
39
|
return null;
|
|
47
40
|
return {
|
|
@@ -50,12 +43,11 @@ class BlockquoteTokenizer extends BaseBlockTokenizer {
|
|
|
50
43
|
remainingSibling: prevSiblingToken,
|
|
51
44
|
};
|
|
52
45
|
}
|
|
53
|
-
eatContinuationText(line, token, parentToken) {
|
|
54
|
-
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces
|
|
46
|
+
function eatContinuationText(line, token, parentToken) {
|
|
47
|
+
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line;
|
|
55
48
|
if (countOfPrecedeSpaces >= 4 ||
|
|
56
49
|
firstNonWhitespaceIndex >= endIndex ||
|
|
57
|
-
nodePoints[firstNonWhitespaceIndex].codePoint !==
|
|
58
|
-
AsciiCodePoint.CLOSE_ANGLE) {
|
|
50
|
+
nodePoints[firstNonWhitespaceIndex].codePoint !== AsciiCodePoint.CLOSE_ANGLE) {
|
|
59
51
|
if (parentToken.nodeType === BlockquoteType) {
|
|
60
52
|
return { status: 'opening', nextIndex: startIndex };
|
|
61
53
|
}
|
|
@@ -67,10 +59,29 @@ class BlockquoteTokenizer extends BaseBlockTokenizer {
|
|
|
67
59
|
: firstNonWhitespaceIndex + 1;
|
|
68
60
|
return { status: 'opening', nextIndex };
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const parse = function () {
|
|
65
|
+
return {
|
|
66
|
+
parse: (_token, children) => {
|
|
67
|
+
const node = { type: BlockquoteType, children };
|
|
68
|
+
return node;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const uniqueName = '@yozora/tokenizer-blockquote';
|
|
74
|
+
|
|
75
|
+
class BlockquoteTokenizer extends BaseBlockTokenizer {
|
|
76
|
+
constructor(props = {}) {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
super({
|
|
79
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
80
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_BLOCK,
|
|
81
|
+
});
|
|
82
|
+
this.match = match;
|
|
83
|
+
this.parse = parse;
|
|
73
84
|
}
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
export { BlockquoteTokenizer, uniqueName as BlockquoteTokenizerName, BlockquoteTokenizer as default };
|
|
87
|
+
export { BlockquoteTokenizer, uniqueName as BlockquoteTokenizerName, match as blockquoteMatch, parse as blockquoteParse, BlockquoteTokenizer as default };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
export { match as blockquoteMatch } from './match';
|
|
2
|
+
export { parse as blockquoteParse } from './parse';
|
|
3
|
+
export { BlockquoteTokenizer, BlockquoteTokenizer as default } from './tokenizer';
|
|
3
4
|
export { uniqueName as BlockquoteTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default BlockquoteTokenizer;
|
|
5
|
+
export type { IHookContext as IBlockquoteHookContext, IToken as IBlockquoteToken, ITokenizerProps as IBlockquoteTokenizerProps, } from './types';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IHookContext, IToken, T } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A block quote marker consists of 0-3 spaces of initial indent, plus
|
|
5
|
+
* (a) the character > together with a following space, or
|
|
6
|
+
* (b) a single character > not followed by a space.
|
|
7
|
+
*
|
|
8
|
+
* The following rules define block quotes:
|
|
9
|
+
* - Basic case. If a string of lines Ls constitute a sequence of blocks Bs,
|
|
10
|
+
* then the result of prepending a block quote marker to the beginning of
|
|
11
|
+
* each line in Ls is a block quote containing Bs.
|
|
12
|
+
*
|
|
13
|
+
* - Laziness. If a string of lines Ls constitute a block quote with contents
|
|
14
|
+
* Bs, then the result of deleting the initial block quote marker from one
|
|
15
|
+
* or more lines in which the next non-whitespace character after the block
|
|
16
|
+
* quote marker is paragraph continuation text is a block quote with Bs as
|
|
17
|
+
* its content. Paragraph continuation text is text that will be parsed as
|
|
18
|
+
* part of the content of a paragraph, but does not occur at the beginning
|
|
19
|
+
* of the paragraph.
|
|
20
|
+
*
|
|
21
|
+
* - Consecutiveness. A document cannot contain two block quotes in a row
|
|
22
|
+
* unless there is a blank line between them.
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/syntax-tree/mdast#blockquote
|
|
25
|
+
* @see https://github.github.com/gfm/#block-quotes
|
|
26
|
+
*/
|
|
27
|
+
export declare const match: IMatchBlockHookCreator<T, IToken, IHookContext>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,54 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { PhrasingContentLine, ResultOfEatAndInterruptPreviousSibling, ResultOfEatContinuationText, ResultOfEatOpener, ResultOfParse, Tokenizer, TokenizerMatchBlockHook, TokenizerParseBlockHook, YastBlockToken } from '@yozora/core-tokenizer';
|
|
1
|
+
import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
3
2
|
import { BaseBlockTokenizer } from '@yozora/core-tokenizer';
|
|
4
|
-
import type {
|
|
3
|
+
import type { IHookContext, INode, IToken, ITokenizerProps, T } from './types';
|
|
5
4
|
/**
|
|
6
5
|
* Lexical Analyzer for Blockquote.
|
|
7
|
-
*
|
|
8
|
-
* A block quote marker consists of 0-3 spaces of initial indent, plus
|
|
9
|
-
* (a) the character > together with a following space, or
|
|
10
|
-
* (b) a single character > not followed by a space.
|
|
11
|
-
*
|
|
12
|
-
* The following rules define block quotes:
|
|
13
|
-
* - Basic case. If a string of lines Ls constitute a sequence of blocks Bs,
|
|
14
|
-
* then the result of prepending a block quote marker to the beginning of
|
|
15
|
-
* each line in Ls is a block quote containing Bs.
|
|
16
|
-
*
|
|
17
|
-
* - Laziness. If a string of lines Ls constitute a block quote with contents
|
|
18
|
-
* Bs, then the result of deleting the initial block quote marker from one
|
|
19
|
-
* or more lines in which the next non-whitespace character after the block
|
|
20
|
-
* quote marker is paragraph continuation text is a block quote with Bs as
|
|
21
|
-
* its content. Paragraph continuation text is text that will be parsed as
|
|
22
|
-
* part of the content of a paragraph, but does not occur at the beginning
|
|
23
|
-
* of the paragraph.
|
|
24
|
-
*
|
|
25
|
-
* - Consecutiveness. A document cannot contain two block quotes in a row
|
|
26
|
-
* unless there is a blank line between them.
|
|
27
|
-
*
|
|
28
6
|
* @see https://github.com/syntax-tree/mdast#blockquote
|
|
29
7
|
* @see https://github.github.com/gfm/#block-quotes
|
|
30
8
|
*/
|
|
31
|
-
export declare class BlockquoteTokenizer extends BaseBlockTokenizer
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* @override
|
|
36
|
-
* @see TokenizerMatchBlockHook
|
|
37
|
-
*/
|
|
38
|
-
eatOpener(line: Readonly<PhrasingContentLine>): ResultOfEatOpener<T, Token>;
|
|
39
|
-
/**
|
|
40
|
-
* @override
|
|
41
|
-
* @see TokenizerMatchBlockHook
|
|
42
|
-
*/
|
|
43
|
-
eatAndInterruptPreviousSibling(line: Readonly<PhrasingContentLine>, prevSiblingToken: Readonly<YastBlockToken>): ResultOfEatAndInterruptPreviousSibling<T, Token>;
|
|
44
|
-
/**
|
|
45
|
-
* @override
|
|
46
|
-
* @see TokenizerMatchBlockHook
|
|
47
|
-
*/
|
|
48
|
-
eatContinuationText(line: Readonly<PhrasingContentLine>, token: Token, parentToken: Readonly<YastBlockToken>): ResultOfEatContinuationText;
|
|
49
|
-
/**
|
|
50
|
-
* @override
|
|
51
|
-
* @see TokenizerParseBlockHook
|
|
52
|
-
*/
|
|
53
|
-
parseBlock(token: Readonly<Token>, children: YastNode[]): ResultOfParse<T, Node>;
|
|
9
|
+
export declare class BlockquoteTokenizer extends BaseBlockTokenizer<T, IToken, INode, IHookContext> implements IBlockTokenizer<T, IToken, INode, IHookContext> {
|
|
10
|
+
constructor(props?: ITokenizerProps);
|
|
11
|
+
readonly match: IMatchBlockHookCreator<T, IToken, IHookContext>;
|
|
12
|
+
readonly parse: IParseBlockHookCreator<T, IToken, INode, IHookContext>;
|
|
54
13
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { BlockquoteType, IBlockquote } from '@yozora/ast';
|
|
2
|
+
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, ITokenizer, IYastBlockToken } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = BlockquoteType;
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type INode = IBlockquote;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-blockquote";
|
|
6
|
-
export interface
|
|
6
|
+
export interface IToken extends IPartialYastBlockToken<T> {
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
children:
|
|
10
|
+
children: IYastBlockToken[];
|
|
11
11
|
}
|
|
12
|
-
export declare type
|
|
12
|
+
export declare type IHookContext = ITokenizer;
|
|
13
|
+
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-blockquote",
|
|
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
|
}
|