@yozora/tokenizer-indented-code 2.0.0-alpha.0 → 2.0.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/README.md +4 -6
- package/lib/cjs/index.js +26 -24
- package/lib/esm/index.js +27 -25
- package/lib/types/index.d.ts +1 -1
- package/lib/types/match.d.ts +2 -2
- package/lib/types/parse.d.ts +2 -2
- package/lib/types/tokenizer.d.ts +4 -4
- package/lib/types/types.d.ts +3 -3
- 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 IndentedCodeTokenizer from '@yozora/tokenizer-indented-code'
|
|
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 IndentedCodeTokenizer())
|
|
96
96
|
|
|
97
97
|
// parse source markdown content
|
|
@@ -231,7 +231,6 @@ Name | Type | Required | Default
|
|
|
231
231
|
[@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
|
|
232
232
|
[@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
|
|
233
233
|
[@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
|
|
234
|
-
[@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
|
|
235
234
|
[@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
|
|
236
235
|
[@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
|
|
237
236
|
[@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
|
|
@@ -291,7 +290,6 @@ Name | Type | Required | Default
|
|
|
291
290
|
[doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
|
|
292
291
|
[doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
|
|
293
292
|
[doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
|
|
294
|
-
[doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
|
|
295
293
|
[doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
|
|
296
294
|
[doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
|
|
297
295
|
[doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
|
package/lib/cjs/index.js
CHANGED
|
@@ -30,8 +30,8 @@ const match = function () {
|
|
|
30
30
|
const token = {
|
|
31
31
|
nodeType: ast.CodeType,
|
|
32
32
|
position: {
|
|
33
|
-
start: coreTokenizer.
|
|
34
|
-
end: coreTokenizer.
|
|
33
|
+
start: coreTokenizer.calcStartPoint(nodePoints, startIndex),
|
|
34
|
+
end: coreTokenizer.calcEndPoint(nodePoints, nextIndex - 1),
|
|
35
35
|
},
|
|
36
36
|
lines: [
|
|
37
37
|
{
|
|
@@ -61,28 +61,30 @@ const match = function () {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
const parse = ()
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
})
|
|
64
|
+
const parse = function (api) {
|
|
65
|
+
return {
|
|
66
|
+
parse: tokens => tokens.map(token => {
|
|
67
|
+
const { lines } = token;
|
|
68
|
+
let startLineIndex = 0, endLineIndex = lines.length;
|
|
69
|
+
for (; startLineIndex < endLineIndex; ++startLineIndex) {
|
|
70
|
+
const line = lines[startLineIndex];
|
|
71
|
+
if (line.firstNonWhitespaceIndex < line.endIndex)
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
for (; startLineIndex < endLineIndex; --endLineIndex) {
|
|
75
|
+
const line = lines[endLineIndex - 1];
|
|
76
|
+
if (line.firstNonWhitespaceIndex < line.endIndex)
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
const contents = coreTokenizer.mergeContentLinesFaithfully(lines, startLineIndex, endLineIndex);
|
|
80
|
+
const value = character.calcStringFromNodePoints(contents);
|
|
81
|
+
const node = api.shouldReservePosition
|
|
82
|
+
? { type: ast.CodeType, position: token.position, value }
|
|
83
|
+
: { type: ast.CodeType, value };
|
|
84
|
+
return node;
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
87
|
+
};
|
|
86
88
|
|
|
87
89
|
const uniqueName = '@yozora/tokenizer-indented-code';
|
|
88
90
|
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CodeType } from '@yozora/ast';
|
|
2
2
|
import { AsciiCodePoint, VirtualCodePoint, calcStringFromNodePoints } from '@yozora/character';
|
|
3
|
-
import {
|
|
3
|
+
import { calcStartPoint, calcEndPoint, mergeContentLinesFaithfully, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
4
4
|
|
|
5
5
|
const match = function () {
|
|
6
6
|
return {
|
|
@@ -26,8 +26,8 @@ const match = function () {
|
|
|
26
26
|
const token = {
|
|
27
27
|
nodeType: CodeType,
|
|
28
28
|
position: {
|
|
29
|
-
start:
|
|
30
|
-
end:
|
|
29
|
+
start: calcStartPoint(nodePoints, startIndex),
|
|
30
|
+
end: calcEndPoint(nodePoints, nextIndex - 1),
|
|
31
31
|
},
|
|
32
32
|
lines: [
|
|
33
33
|
{
|
|
@@ -57,28 +57,30 @@ const match = function () {
|
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const parse = ()
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
60
|
+
const parse = function (api) {
|
|
61
|
+
return {
|
|
62
|
+
parse: tokens => tokens.map(token => {
|
|
63
|
+
const { lines } = token;
|
|
64
|
+
let startLineIndex = 0, endLineIndex = lines.length;
|
|
65
|
+
for (; startLineIndex < endLineIndex; ++startLineIndex) {
|
|
66
|
+
const line = lines[startLineIndex];
|
|
67
|
+
if (line.firstNonWhitespaceIndex < line.endIndex)
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
for (; startLineIndex < endLineIndex; --endLineIndex) {
|
|
71
|
+
const line = lines[endLineIndex - 1];
|
|
72
|
+
if (line.firstNonWhitespaceIndex < line.endIndex)
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
const contents = mergeContentLinesFaithfully(lines, startLineIndex, endLineIndex);
|
|
76
|
+
const value = calcStringFromNodePoints(contents);
|
|
77
|
+
const node = api.shouldReservePosition
|
|
78
|
+
? { type: CodeType, position: token.position, value }
|
|
79
|
+
: { type: CodeType, value };
|
|
80
|
+
return node;
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
};
|
|
82
84
|
|
|
83
85
|
const uniqueName = '@yozora/tokenizer-indented-code';
|
|
84
86
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { match as indentedCodeMatch } from './match';
|
|
|
2
2
|
export { parse as indentedCodeParse } from './parse';
|
|
3
3
|
export { IndentedCodeTokenizer, IndentedCodeTokenizer as default } from './tokenizer';
|
|
4
4
|
export { uniqueName as IndentedCodeTokenizerName } from './types';
|
|
5
|
-
export type {
|
|
5
|
+
export type { IThis as IIndentedCodeHookContext, IToken as IIndentedCodeToken, ITokenizerProps as IIndentedCodeTokenizerProps, } from './types';
|
package/lib/types/match.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IThis, IToken, T } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* An indented code block is composed of one or more indented chunks
|
|
5
5
|
* separated by blank lines. An indented chunk is a sequence of non-blank
|
|
@@ -9,4 +9,4 @@ import type { IHookContext, IToken, T } from './types';
|
|
|
9
9
|
*
|
|
10
10
|
* @see https://github.github.com/gfm/#indented-code-block
|
|
11
11
|
*/
|
|
12
|
-
export declare const match: IMatchBlockHookCreator<T, IToken,
|
|
12
|
+
export declare const match: IMatchBlockHookCreator<T, IToken, IThis>;
|
package/lib/types/parse.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const parse: IParseBlockHookCreator<T, IToken, INode,
|
|
2
|
+
import type { INode, IThis, IToken, T } from './types';
|
|
3
|
+
export declare const parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
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 IndentedCode.
|
|
6
6
|
* @see https://github.github.com/gfm/#indented-code-block
|
|
7
7
|
*/
|
|
8
|
-
export declare class IndentedCodeTokenizer extends BaseBlockTokenizer<T, IToken, INode,
|
|
8
|
+
export declare class IndentedCodeTokenizer extends BaseBlockTokenizer<T, IToken, INode, IThis> implements IBlockTokenizer<T, IToken, INode, IThis> {
|
|
9
9
|
constructor(props?: ITokenizerProps);
|
|
10
|
-
readonly match: IMatchBlockHookCreator<T, IToken,
|
|
11
|
-
readonly parse: IParseBlockHookCreator<T, IToken, INode,
|
|
10
|
+
readonly match: IMatchBlockHookCreator<T, IToken, IThis>;
|
|
11
|
+
readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
|
|
12
12
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Code, CodeType } from '@yozora/ast';
|
|
2
2
|
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, IPhrasingContentLine, ITokenizer } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = CodeType;
|
|
4
|
-
export declare type INode =
|
|
4
|
+
export declare type INode = Code;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-indented-code";
|
|
6
6
|
export interface IToken extends IPartialYastBlockToken<T> {
|
|
7
7
|
/**
|
|
@@ -9,5 +9,5 @@ export interface IToken extends IPartialYastBlockToken<T> {
|
|
|
9
9
|
*/
|
|
10
10
|
lines: IPhrasingContentLine[];
|
|
11
11
|
}
|
|
12
|
-
export declare type
|
|
12
|
+
export declare type IThis = ITokenizer;
|
|
13
13
|
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-indented-code",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.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": "^2.0.0
|
|
39
|
-
"@yozora/character": "^2.0.0
|
|
40
|
-
"@yozora/core-tokenizer": "^2.0.0
|
|
38
|
+
"@yozora/ast": "^2.0.0",
|
|
39
|
+
"@yozora/character": "^2.0.0",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "65e99d1709fdd1c918465dce6b1e91de96bdab5e"
|
|
43
43
|
}
|