@yozora/tokenizer-fenced-block 1.2.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 +36 -26
- package/lib/esm/index.js +36 -27
- package/lib/types/index.d.ts +3 -4
- package/lib/types/match.d.ts +4 -0
- package/lib/types/tokenizer.d.ts +9 -24
- package/lib/types/types.d.ts +30 -9
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -5,43 +5,36 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var character = require('@yozora/character');
|
|
6
6
|
var coreTokenizer = require('@yozora/core-tokenizer');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.nodeType = props.nodeType;
|
|
18
|
-
this.markers = props.markers;
|
|
19
|
-
this.markersRequired = props.markersRequired;
|
|
20
|
-
this.checkInfoString = props.checkInfoString;
|
|
21
|
-
}
|
|
22
|
-
eatOpener(line) {
|
|
8
|
+
function match(_api) {
|
|
9
|
+
const { nodeType, markers, markersRequired, checkInfoString } = this;
|
|
10
|
+
return {
|
|
11
|
+
isContainingBlock: false,
|
|
12
|
+
eatOpener,
|
|
13
|
+
eatAndInterruptPreviousSibling,
|
|
14
|
+
eatContinuationText,
|
|
15
|
+
};
|
|
16
|
+
function eatOpener(line) {
|
|
23
17
|
if (line.countOfPrecedeSpaces >= 4)
|
|
24
18
|
return null;
|
|
25
19
|
const { endIndex, firstNonWhitespaceIndex } = line;
|
|
26
|
-
if (firstNonWhitespaceIndex +
|
|
20
|
+
if (firstNonWhitespaceIndex + markersRequired - 1 >= endIndex)
|
|
27
21
|
return null;
|
|
28
22
|
const { nodePoints, startIndex } = line;
|
|
29
23
|
const marker = nodePoints[firstNonWhitespaceIndex].codePoint;
|
|
30
|
-
if (
|
|
24
|
+
if (markers.indexOf(marker) < 0)
|
|
31
25
|
return null;
|
|
32
26
|
const i = coreTokenizer.eatOptionalCharacters(nodePoints, firstNonWhitespaceIndex + 1, endIndex, marker);
|
|
33
27
|
const countOfMark = i - firstNonWhitespaceIndex;
|
|
34
|
-
if (countOfMark <
|
|
28
|
+
if (countOfMark < markersRequired)
|
|
35
29
|
return null;
|
|
36
30
|
const [iLft, iRht] = character.calcTrimBoundaryOfCodePoints(nodePoints, i, endIndex);
|
|
37
31
|
const infoString = nodePoints.slice(iLft, iRht);
|
|
38
|
-
if (
|
|
39
|
-
!this.checkInfoString(infoString, marker, countOfMark)) {
|
|
32
|
+
if (checkInfoString != null && !checkInfoString(infoString, marker, countOfMark)) {
|
|
40
33
|
return null;
|
|
41
34
|
}
|
|
42
35
|
const nextIndex = endIndex;
|
|
43
36
|
const token = {
|
|
44
|
-
nodeType:
|
|
37
|
+
nodeType: nodeType,
|
|
45
38
|
position: {
|
|
46
39
|
start: coreTokenizer.calcStartYastNodePoint(nodePoints, startIndex),
|
|
47
40
|
end: coreTokenizer.calcEndYastNodePoint(nodePoints, nextIndex - 1),
|
|
@@ -54,8 +47,8 @@ class FencedBlockTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
54
47
|
};
|
|
55
48
|
return { token, nextIndex };
|
|
56
49
|
}
|
|
57
|
-
eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
58
|
-
const result =
|
|
50
|
+
function eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
51
|
+
const result = eatOpener(line);
|
|
59
52
|
if (result == null)
|
|
60
53
|
return null;
|
|
61
54
|
return {
|
|
@@ -64,8 +57,8 @@ class FencedBlockTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
64
57
|
remainingSibling: prevSiblingToken,
|
|
65
58
|
};
|
|
66
59
|
}
|
|
67
|
-
eatContinuationText(line, token) {
|
|
68
|
-
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces
|
|
60
|
+
function eatContinuationText(line, token) {
|
|
61
|
+
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line;
|
|
69
62
|
if (countOfPrecedeSpaces < 4 && firstNonWhitespaceIndex < endIndex) {
|
|
70
63
|
let i = coreTokenizer.eatOptionalCharacters(nodePoints, firstNonWhitespaceIndex, endIndex, token.marker);
|
|
71
64
|
const markerCount = i - firstNonWhitespaceIndex;
|
|
@@ -92,8 +85,25 @@ class FencedBlockTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
92
85
|
}
|
|
93
86
|
}
|
|
94
87
|
|
|
88
|
+
class FencedBlockTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
89
|
+
constructor(props) {
|
|
90
|
+
var _a;
|
|
91
|
+
super({
|
|
92
|
+
name: props.name,
|
|
93
|
+
priority: (_a = props.priority) !== null && _a !== void 0 ? _a : coreTokenizer.TokenizerPriority.FENCED_BLOCK,
|
|
94
|
+
});
|
|
95
|
+
this.markers = [];
|
|
96
|
+
this.match = match;
|
|
97
|
+
this.nodeType = props.nodeType;
|
|
98
|
+
this.markers = props.markers;
|
|
99
|
+
this.markersRequired = props.markersRequired;
|
|
100
|
+
this.checkInfoString = props.checkInfoString;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
95
104
|
const FencedBlockType = 'fencedBlock';
|
|
96
105
|
|
|
97
106
|
exports.FencedBlockTokenizer = FencedBlockTokenizer;
|
|
98
107
|
exports.FencedBlockType = FencedBlockType;
|
|
99
|
-
exports[
|
|
108
|
+
exports["default"] = FencedBlockTokenizer;
|
|
109
|
+
exports.fencedMatch = match;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,43 +1,36 @@
|
|
|
1
1
|
import { calcTrimBoundaryOfCodePoints, isSpaceCharacter } from '@yozora/character';
|
|
2
|
-
import {
|
|
2
|
+
import { eatOptionalCharacters, calcStartYastNodePoint, calcEndYastNodePoint, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.nodeType = props.nodeType;
|
|
14
|
-
this.markers = props.markers;
|
|
15
|
-
this.markersRequired = props.markersRequired;
|
|
16
|
-
this.checkInfoString = props.checkInfoString;
|
|
17
|
-
}
|
|
18
|
-
eatOpener(line) {
|
|
4
|
+
function match(_api) {
|
|
5
|
+
const { nodeType, markers, markersRequired, checkInfoString } = this;
|
|
6
|
+
return {
|
|
7
|
+
isContainingBlock: false,
|
|
8
|
+
eatOpener,
|
|
9
|
+
eatAndInterruptPreviousSibling,
|
|
10
|
+
eatContinuationText,
|
|
11
|
+
};
|
|
12
|
+
function eatOpener(line) {
|
|
19
13
|
if (line.countOfPrecedeSpaces >= 4)
|
|
20
14
|
return null;
|
|
21
15
|
const { endIndex, firstNonWhitespaceIndex } = line;
|
|
22
|
-
if (firstNonWhitespaceIndex +
|
|
16
|
+
if (firstNonWhitespaceIndex + markersRequired - 1 >= endIndex)
|
|
23
17
|
return null;
|
|
24
18
|
const { nodePoints, startIndex } = line;
|
|
25
19
|
const marker = nodePoints[firstNonWhitespaceIndex].codePoint;
|
|
26
|
-
if (
|
|
20
|
+
if (markers.indexOf(marker) < 0)
|
|
27
21
|
return null;
|
|
28
22
|
const i = eatOptionalCharacters(nodePoints, firstNonWhitespaceIndex + 1, endIndex, marker);
|
|
29
23
|
const countOfMark = i - firstNonWhitespaceIndex;
|
|
30
|
-
if (countOfMark <
|
|
24
|
+
if (countOfMark < markersRequired)
|
|
31
25
|
return null;
|
|
32
26
|
const [iLft, iRht] = calcTrimBoundaryOfCodePoints(nodePoints, i, endIndex);
|
|
33
27
|
const infoString = nodePoints.slice(iLft, iRht);
|
|
34
|
-
if (
|
|
35
|
-
!this.checkInfoString(infoString, marker, countOfMark)) {
|
|
28
|
+
if (checkInfoString != null && !checkInfoString(infoString, marker, countOfMark)) {
|
|
36
29
|
return null;
|
|
37
30
|
}
|
|
38
31
|
const nextIndex = endIndex;
|
|
39
32
|
const token = {
|
|
40
|
-
nodeType:
|
|
33
|
+
nodeType: nodeType,
|
|
41
34
|
position: {
|
|
42
35
|
start: calcStartYastNodePoint(nodePoints, startIndex),
|
|
43
36
|
end: calcEndYastNodePoint(nodePoints, nextIndex - 1),
|
|
@@ -50,8 +43,8 @@ class FencedBlockTokenizer extends BaseBlockTokenizer {
|
|
|
50
43
|
};
|
|
51
44
|
return { token, nextIndex };
|
|
52
45
|
}
|
|
53
|
-
eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
54
|
-
const result =
|
|
46
|
+
function eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
47
|
+
const result = eatOpener(line);
|
|
55
48
|
if (result == null)
|
|
56
49
|
return null;
|
|
57
50
|
return {
|
|
@@ -60,8 +53,8 @@ class FencedBlockTokenizer extends BaseBlockTokenizer {
|
|
|
60
53
|
remainingSibling: prevSiblingToken,
|
|
61
54
|
};
|
|
62
55
|
}
|
|
63
|
-
eatContinuationText(line, token) {
|
|
64
|
-
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces
|
|
56
|
+
function eatContinuationText(line, token) {
|
|
57
|
+
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line;
|
|
65
58
|
if (countOfPrecedeSpaces < 4 && firstNonWhitespaceIndex < endIndex) {
|
|
66
59
|
let i = eatOptionalCharacters(nodePoints, firstNonWhitespaceIndex, endIndex, token.marker);
|
|
67
60
|
const markerCount = i - firstNonWhitespaceIndex;
|
|
@@ -88,6 +81,22 @@ class FencedBlockTokenizer extends BaseBlockTokenizer {
|
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
83
|
|
|
84
|
+
class FencedBlockTokenizer extends BaseBlockTokenizer {
|
|
85
|
+
constructor(props) {
|
|
86
|
+
var _a;
|
|
87
|
+
super({
|
|
88
|
+
name: props.name,
|
|
89
|
+
priority: (_a = props.priority) !== null && _a !== void 0 ? _a : TokenizerPriority.FENCED_BLOCK,
|
|
90
|
+
});
|
|
91
|
+
this.markers = [];
|
|
92
|
+
this.match = match;
|
|
93
|
+
this.nodeType = props.nodeType;
|
|
94
|
+
this.markers = props.markers;
|
|
95
|
+
this.markersRequired = props.markersRequired;
|
|
96
|
+
this.checkInfoString = props.checkInfoString;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
const FencedBlockType = 'fencedBlock';
|
|
92
101
|
|
|
93
|
-
export { FencedBlockTokenizer, FencedBlockType, FencedBlockTokenizer as default };
|
|
102
|
+
export { FencedBlockTokenizer, FencedBlockType, FencedBlockTokenizer as default, match as fencedMatch };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export { FencedBlockTokenizer } from './tokenizer';
|
|
3
|
-
export type { Token as FencedBlockToken, TokenizerProps as FencedBlockTokenizerProps, } from './types';
|
|
1
|
+
export { match as fencedMatch } from './match';
|
|
2
|
+
export { FencedBlockTokenizer, FencedBlockTokenizer as default } from './tokenizer';
|
|
4
3
|
export { FencedBlockType } from './types';
|
|
5
|
-
export
|
|
4
|
+
export type { IFencedBlockHookContext, IToken as IFencedBlockToken, ITokenizerProps as IFencedBlockTokenizerProps, } from './types';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { YastNodeType } from '@yozora/ast';
|
|
2
|
+
import type { IMatchBlockHook, IMatchBlockPhaseApi } from '@yozora/core-tokenizer';
|
|
3
|
+
import type { IFencedBlockHookContext, IToken } from './types';
|
|
4
|
+
export declare function match<T extends YastNodeType = YastNodeType, IThis extends IFencedBlockHookContext<T> = IFencedBlockHookContext<T>>(this: IThis, _api: IMatchBlockPhaseApi): IMatchBlockHook<T, IToken<T>>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { YastNodeType } from '@yozora/ast';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { IYastNode, YastNodeType } from '@yozora/ast';
|
|
2
|
+
import type { ICodePoint } from '@yozora/character';
|
|
3
|
+
import type { IBlockTokenizer, IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
4
4
|
import { BaseBlockTokenizer } from '@yozora/core-tokenizer';
|
|
5
|
-
import type {
|
|
5
|
+
import type { IFencedBlockHookContext, IToken, ITokenizerProps } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* Lexical Matcher for FencedBlock.
|
|
8
8
|
*
|
|
@@ -13,26 +13,11 @@ import type { FencedBlockType, Token, TokenizerProps } from './types';
|
|
|
13
13
|
* @see https://github.com/syntax-tree/mdast#code
|
|
14
14
|
* @see https://github.github.com/gfm/#code-fence
|
|
15
15
|
*/
|
|
16
|
-
export declare class FencedBlockTokenizer<T extends YastNodeType =
|
|
17
|
-
readonly isContainingBlock: boolean;
|
|
16
|
+
export declare abstract class FencedBlockTokenizer<T extends YastNodeType = YastNodeType, INode extends IYastNode<T> = IYastNode<T>, IThis extends IFencedBlockHookContext<T> = IFencedBlockHookContext<T>> extends BaseBlockTokenizer<T, IToken<T>, INode, any> implements IBlockTokenizer<T, IToken<T>, INode, IThis> {
|
|
18
17
|
protected readonly nodeType: T;
|
|
19
|
-
protected readonly markers:
|
|
18
|
+
protected readonly markers: ICodePoint[];
|
|
20
19
|
protected readonly markersRequired: number;
|
|
21
|
-
protected readonly checkInfoString:
|
|
22
|
-
constructor(props:
|
|
23
|
-
|
|
24
|
-
* @override
|
|
25
|
-
* @see TokenizerMatchBlockHook
|
|
26
|
-
*/
|
|
27
|
-
eatOpener(line: Readonly<PhrasingContentLine>): ResultOfEatOpener<T, Token<T>>;
|
|
28
|
-
/**
|
|
29
|
-
* @override
|
|
30
|
-
* @see TokenizerMatchBlockHook
|
|
31
|
-
*/
|
|
32
|
-
eatAndInterruptPreviousSibling(line: Readonly<PhrasingContentLine>, prevSiblingToken: Readonly<YastBlockToken>): ResultOfEatAndInterruptPreviousSibling<T, Token<T>>;
|
|
33
|
-
/**
|
|
34
|
-
* @override
|
|
35
|
-
* @see TokenizerMatchBlockHook
|
|
36
|
-
*/
|
|
37
|
-
eatContinuationText(line: Readonly<PhrasingContentLine>, token: Token<T>): ResultOfEatContinuationText;
|
|
20
|
+
protected readonly checkInfoString: ITokenizerProps<T>['checkInfoString'];
|
|
21
|
+
constructor(props: ITokenizerProps<T>);
|
|
22
|
+
readonly match: IMatchBlockHookCreator<T, IToken<T>, IThis>;
|
|
38
23
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { YastNodeType } from '@yozora/ast';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { ICodePoint, INodePoint } from '@yozora/character';
|
|
3
|
+
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, IPhrasingContentLine, ITokenizer } from '@yozora/core-tokenizer';
|
|
4
4
|
export declare const FencedBlockType = "fencedBlock";
|
|
5
5
|
export declare type FencedBlockType = typeof FencedBlockType;
|
|
6
|
-
export interface
|
|
6
|
+
export interface IToken<T extends YastNodeType> extends IPartialYastBlockToken<T> {
|
|
7
7
|
/**
|
|
8
8
|
* Line indent of a fenced block.
|
|
9
9
|
*/
|
|
@@ -19,15 +19,36 @@ export interface Token<T extends YastNodeType> extends PartialYastBlockToken<T>
|
|
|
19
19
|
/**
|
|
20
20
|
* Lines to construct the contents of a paragraph.
|
|
21
21
|
*/
|
|
22
|
-
lines:
|
|
22
|
+
lines: IPhrasingContentLine[];
|
|
23
23
|
/**
|
|
24
24
|
* Meta info string
|
|
25
25
|
*/
|
|
26
|
-
infoString:
|
|
26
|
+
infoString: INodePoint[];
|
|
27
27
|
}
|
|
28
|
-
export interface
|
|
28
|
+
export interface IFencedBlockHookContext<T extends YastNodeType> extends ITokenizer {
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Type of special FencedBlock token and FencedBlock node.
|
|
31
|
+
*/
|
|
32
|
+
nodeType: T;
|
|
33
|
+
/**
|
|
34
|
+
* Available fence markers.
|
|
35
|
+
*/
|
|
36
|
+
markers: ICodePoint[];
|
|
37
|
+
/**
|
|
38
|
+
* The minimum amount required
|
|
39
|
+
*/
|
|
40
|
+
markersRequired: number;
|
|
41
|
+
/**
|
|
42
|
+
* Check if the info string is valid.
|
|
43
|
+
* @param infoString
|
|
44
|
+
* @param marker
|
|
45
|
+
* @param countOfMarker
|
|
46
|
+
*/
|
|
47
|
+
checkInfoString?(infoString: Readonly<INodePoint[]>, marker: ICodePoint, countOfMarker: number): boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface ITokenizerProps<T extends YastNodeType> extends Partial<IBaseBlockTokenizerProps> {
|
|
50
|
+
/**
|
|
51
|
+
* ITokenizer name.
|
|
31
52
|
*/
|
|
32
53
|
name: string;
|
|
33
54
|
/**
|
|
@@ -37,7 +58,7 @@ export interface TokenizerProps<T extends YastNodeType> extends Partial<BaseBloc
|
|
|
37
58
|
/**
|
|
38
59
|
* Available fence markers.
|
|
39
60
|
*/
|
|
40
|
-
markers:
|
|
61
|
+
markers: ICodePoint[];
|
|
41
62
|
/**
|
|
42
63
|
* The minimum amount required
|
|
43
64
|
*/
|
|
@@ -48,5 +69,5 @@ export interface TokenizerProps<T extends YastNodeType> extends Partial<BaseBloc
|
|
|
48
69
|
* @param marker
|
|
49
70
|
* @param countOfMarker
|
|
50
71
|
*/
|
|
51
|
-
checkInfoString?(infoString: Readonly<
|
|
72
|
+
checkInfoString?(infoString: Readonly<INodePoint[]>, marker: ICodePoint, countOfMarker: number): boolean;
|
|
52
73
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-fenced-block",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "guanghechen",
|
|
6
6
|
"url": "https://github.com/guanghechen/"
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"prepublishOnly": "cross-env ROLLUP_SHOULD_SOURCEMAP=false yarn build"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@yozora/ast": "^
|
|
38
|
-
"@yozora/character": "^
|
|
39
|
-
"@yozora/core-tokenizer": "^
|
|
37
|
+
"@yozora/ast": "^2.0.0-alpha.0",
|
|
38
|
+
"@yozora/character": "^2.0.0-alpha.0",
|
|
39
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
|
|
42
42
|
}
|