@yozora/tokenizer-thematic-break 1.3.0 → 2.0.0-alpha.3
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/README.md +4 -6
- package/lib/cjs/index.js +36 -18
- package/lib/esm/index.js +35 -19
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +10 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -25
- package/lib/types/types.d.ts +5 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -84,14 +84,14 @@ so you can use `YozoraParser` / `GfmExParser` / `GfmParser` directly.
|
|
|
84
84
|
registered in *YastParser* as a plugin-in before it can be used.
|
|
85
85
|
|
|
86
86
|
```typescript {4,9}
|
|
87
|
-
import {
|
|
87
|
+
import { DefaultParser } from '@yozora/core-parser'
|
|
88
88
|
import ParagraphTokenizer from '@yozora/tokenizer-paragraph'
|
|
89
89
|
import TextTokenizer from '@yozora/tokenizer-text'
|
|
90
90
|
import ThematicBreakTokenizer from '@yozora/tokenizer-thematic-break'
|
|
91
91
|
|
|
92
|
-
const parser = new
|
|
93
|
-
.
|
|
94
|
-
.
|
|
92
|
+
const parser = new DefaultParser()
|
|
93
|
+
.useFallbackTokenizer(new ParagraphTokenizer())
|
|
94
|
+
.useFallbackTokenizer(new TextTokenizer())
|
|
95
95
|
.useTokenizer(new ThematicBreakTokenizer())
|
|
96
96
|
|
|
97
97
|
// parse source markdown content
|
|
@@ -225,7 +225,6 @@ Name | Type | Required | Default
|
|
|
225
225
|
[@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
|
|
226
226
|
[@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
|
|
227
227
|
[@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
|
|
228
|
-
[@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
|
|
229
228
|
[@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
|
|
230
229
|
[@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
|
|
231
230
|
[@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
|
|
@@ -285,7 +284,6 @@ Name | Type | Required | Default
|
|
|
285
284
|
[doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
|
|
286
285
|
[doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
|
|
287
286
|
[doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
|
|
288
|
-
[doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
|
|
289
287
|
[doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
|
|
290
288
|
[doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
|
|
291
289
|
[doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
|
package/lib/cjs/index.js
CHANGED
|
@@ -6,18 +6,13 @@ 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
|
-
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
|
|
17
|
-
});
|
|
18
|
-
this.isContainingBlock = false;
|
|
19
|
-
}
|
|
20
|
-
eatOpener(line) {
|
|
9
|
+
const match = function () {
|
|
10
|
+
return {
|
|
11
|
+
isContainingBlock: false,
|
|
12
|
+
eatOpener,
|
|
13
|
+
eatAndInterruptPreviousSibling,
|
|
14
|
+
};
|
|
15
|
+
function eatOpener(line) {
|
|
21
16
|
if (line.countOfPrecedeSpaces >= 4)
|
|
22
17
|
return null;
|
|
23
18
|
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
|
|
@@ -67,8 +62,8 @@ class ThematicBreakTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
67
62
|
};
|
|
68
63
|
return { token, nextIndex: endIndex, saturated: true };
|
|
69
64
|
}
|
|
70
|
-
eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
71
|
-
const result =
|
|
65
|
+
function eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
66
|
+
const result = eatOpener(line);
|
|
72
67
|
if (result == null)
|
|
73
68
|
return null;
|
|
74
69
|
return {
|
|
@@ -77,12 +72,35 @@ class ThematicBreakTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
77
72
|
remainingSibling: prevSiblingToken,
|
|
78
73
|
};
|
|
79
74
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const parse = function (api) {
|
|
78
|
+
return {
|
|
79
|
+
parse: tokens => tokens.map(token => {
|
|
80
|
+
const node = api.shouldReservePosition
|
|
81
|
+
? { type: ast.ThematicBreakType, position: token.position }
|
|
82
|
+
: { type: ast.ThematicBreakType };
|
|
83
|
+
return node;
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const uniqueName = '@yozora/tokenizer-thematic-break';
|
|
89
|
+
|
|
90
|
+
class ThematicBreakTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
91
|
+
constructor(props = {}) {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
super({
|
|
94
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
95
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
|
|
96
|
+
});
|
|
97
|
+
this.match = match;
|
|
98
|
+
this.parse = parse;
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
exports.ThematicBreakTokenizer = ThematicBreakTokenizer;
|
|
87
103
|
exports.ThematicBreakTokenizerName = uniqueName;
|
|
88
|
-
exports[
|
|
104
|
+
exports["default"] = ThematicBreakTokenizer;
|
|
105
|
+
exports.thematicBreakMatch = match;
|
|
106
|
+
exports.thematicBreakParse = parse;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { ThematicBreakType } from '@yozora/ast';
|
|
2
2
|
import { isUnicodeWhitespaceCharacter, AsciiCodePoint } 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
|
-
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.ATOMIC,
|
|
13
|
-
});
|
|
14
|
-
this.isContainingBlock = false;
|
|
15
|
-
}
|
|
16
|
-
eatOpener(line) {
|
|
5
|
+
const match = function () {
|
|
6
|
+
return {
|
|
7
|
+
isContainingBlock: false,
|
|
8
|
+
eatOpener,
|
|
9
|
+
eatAndInterruptPreviousSibling,
|
|
10
|
+
};
|
|
11
|
+
function eatOpener(line) {
|
|
17
12
|
if (line.countOfPrecedeSpaces >= 4)
|
|
18
13
|
return null;
|
|
19
14
|
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
|
|
@@ -63,8 +58,8 @@ class ThematicBreakTokenizer extends BaseBlockTokenizer {
|
|
|
63
58
|
};
|
|
64
59
|
return { token, nextIndex: endIndex, saturated: true };
|
|
65
60
|
}
|
|
66
|
-
eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
67
|
-
const result =
|
|
61
|
+
function eatAndInterruptPreviousSibling(line, prevSiblingToken) {
|
|
62
|
+
const result = eatOpener(line);
|
|
68
63
|
if (result == null)
|
|
69
64
|
return null;
|
|
70
65
|
return {
|
|
@@ -73,10 +68,31 @@ class ThematicBreakTokenizer extends BaseBlockTokenizer {
|
|
|
73
68
|
remainingSibling: prevSiblingToken,
|
|
74
69
|
};
|
|
75
70
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const parse = function (api) {
|
|
74
|
+
return {
|
|
75
|
+
parse: tokens => tokens.map(token => {
|
|
76
|
+
const node = api.shouldReservePosition
|
|
77
|
+
? { type: ThematicBreakType, position: token.position }
|
|
78
|
+
: { type: ThematicBreakType };
|
|
79
|
+
return node;
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const uniqueName = '@yozora/tokenizer-thematic-break';
|
|
85
|
+
|
|
86
|
+
class ThematicBreakTokenizer extends BaseBlockTokenizer {
|
|
87
|
+
constructor(props = {}) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
super({
|
|
90
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
91
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.ATOMIC,
|
|
92
|
+
});
|
|
93
|
+
this.match = match;
|
|
94
|
+
this.parse = parse;
|
|
79
95
|
}
|
|
80
96
|
}
|
|
81
97
|
|
|
82
|
-
export { ThematicBreakTokenizer, uniqueName as ThematicBreakTokenizerName, ThematicBreakTokenizer as default };
|
|
98
|
+
export { ThematicBreakTokenizer, uniqueName as ThematicBreakTokenizerName, ThematicBreakTokenizer as default, match as thematicBreakMatch, parse as thematicBreakParse };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
export { match as thematicBreakMatch } from './match';
|
|
2
|
+
export { parse as thematicBreakParse } from './parse';
|
|
3
|
+
export { ThematicBreakTokenizer, ThematicBreakTokenizer as default } from './tokenizer';
|
|
3
4
|
export { uniqueName as ThematicBreakTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default ThematicBreakTokenizer;
|
|
5
|
+
export type { IThis as IThematicBreakHookContext, IToken as IThematicBreakToken, ITokenizerProps as IThematicBreakTokenizerProps, } from './types';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IThis, IToken, T } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A line consisting of 0-3 spaces of indentation, followed by a sequence of
|
|
5
|
+
* three or more matching -, _, or * characters, each followed optionally by
|
|
6
|
+
* any number of spaces or tabs, forms a thematic break.
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.github.com/gfm/#thematic-break
|
|
9
|
+
*/
|
|
10
|
+
export declare const match: IMatchBlockHookCreator<T, IToken, IThis>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
2
|
import { BaseBlockTokenizer } from '@yozora/core-tokenizer';
|
|
3
|
-
import type {
|
|
3
|
+
import type { INode, IThis, IToken, ITokenizerProps, T } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Lexical Analyzer for ThematicBreak.
|
|
6
|
-
*
|
|
7
|
-
* A line consisting of 0-3 spaces of indentation, followed by a sequence of
|
|
8
|
-
* three or more matching -, _, or * characters, each followed optionally by
|
|
9
|
-
* any number of spaces or tabs, forms a thematic break.
|
|
10
|
-
*
|
|
11
6
|
* @see https://github.github.com/gfm/#thematic-break
|
|
12
7
|
*/
|
|
13
|
-
export declare class ThematicBreakTokenizer extends BaseBlockTokenizer
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @override
|
|
18
|
-
* @see TokenizerMatchBlockHook
|
|
19
|
-
*/
|
|
20
|
-
eatOpener(line: Readonly<PhrasingContentLine>): ResultOfEatOpener<T, Token>;
|
|
21
|
-
/**
|
|
22
|
-
* @override
|
|
23
|
-
* @see TokenizerMatchBlockHook
|
|
24
|
-
*/
|
|
25
|
-
eatAndInterruptPreviousSibling(line: Readonly<PhrasingContentLine>, prevSiblingToken: Readonly<YastBlockToken>): ResultOfEatAndInterruptPreviousSibling<T, Token>;
|
|
26
|
-
/**
|
|
27
|
-
* @override
|
|
28
|
-
* @see TokenizerParseBlockHook
|
|
29
|
-
*/
|
|
30
|
-
parseBlock(): ResultOfParse<T, Node>;
|
|
8
|
+
export declare class ThematicBreakTokenizer extends BaseBlockTokenizer<T, IToken, INode, IThis> implements IBlockTokenizer<T, IToken, INode, IThis> {
|
|
9
|
+
constructor(props?: ITokenizerProps);
|
|
10
|
+
readonly match: IMatchBlockHookCreator<T, IToken, IThis>;
|
|
11
|
+
readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
|
|
31
12
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ThematicBreak, ThematicBreakType } from '@yozora/ast';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, ITokenizer } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = ThematicBreakType;
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type INode = ThematicBreak;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-thematic-break";
|
|
6
|
-
export interface
|
|
6
|
+
export interface IToken extends IPartialYastBlockToken<T> {
|
|
7
7
|
/**
|
|
8
8
|
* CodePoint of '-' / '_' / '*'
|
|
9
9
|
*/
|
|
@@ -13,4 +13,5 @@ export interface Token extends PartialYastBlockToken<T> {
|
|
|
13
13
|
*/
|
|
14
14
|
continuous: boolean;
|
|
15
15
|
}
|
|
16
|
-
export declare type
|
|
16
|
+
export declare type IThis = ITokenizer;
|
|
17
|
+
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-thematic-break",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
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.3",
|
|
39
|
+
"@yozora/character": "^2.0.0-alpha.3",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "9f274fc7487a8c1dd213405d92508f9a7621f730"
|
|
43
43
|
}
|