@yozora/tokenizer-admonition 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 +57 -44
- package/lib/esm/index.js +56 -45
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +11 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -22
- package/lib/types/types.d.ts +8 -7
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -2,18 +2,68 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var FencedBlockTokenizer = require('@yozora/tokenizer-fenced-block');
|
|
5
6
|
var ast = require('@yozora/ast');
|
|
6
7
|
var character = require('@yozora/character');
|
|
7
8
|
var coreTokenizer = require('@yozora/core-tokenizer');
|
|
8
|
-
var FencedBlockTokenizer = require('@yozora/tokenizer-fenced-block');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
11
|
|
|
12
12
|
var FencedBlockTokenizer__default = /*#__PURE__*/_interopDefaultLegacy(FencedBlockTokenizer);
|
|
13
13
|
|
|
14
|
+
const match = function (api) {
|
|
15
|
+
const hook = FencedBlockTokenizer.fencedMatch.call(this, api);
|
|
16
|
+
return Object.assign(Object.assign({}, hook), { isContainingBlock: true, onClose });
|
|
17
|
+
function onClose(token) {
|
|
18
|
+
const children = api.rollbackPhrasingLines(token.lines);
|
|
19
|
+
token.children = children;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const parse = function (api) {
|
|
24
|
+
return {
|
|
25
|
+
parse: (token, children) => {
|
|
26
|
+
const infoString = token.infoString;
|
|
27
|
+
let i = 0;
|
|
28
|
+
const keyword = [];
|
|
29
|
+
for (; i < infoString.length; ++i) {
|
|
30
|
+
const p = infoString[i];
|
|
31
|
+
if (character.isUnicodeWhitespaceCharacter(p.codePoint))
|
|
32
|
+
break;
|
|
33
|
+
keyword.push(p);
|
|
34
|
+
}
|
|
35
|
+
i = coreTokenizer.eatOptionalWhitespaces(infoString, i, infoString.length);
|
|
36
|
+
const title = (() => {
|
|
37
|
+
if (i >= infoString.length)
|
|
38
|
+
return [];
|
|
39
|
+
const titleLines = [
|
|
40
|
+
{
|
|
41
|
+
nodePoints: infoString,
|
|
42
|
+
startIndex: i,
|
|
43
|
+
endIndex: infoString.length,
|
|
44
|
+
firstNonWhitespaceIndex: i,
|
|
45
|
+
countOfPrecedeSpaces: 0,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
const phrasingContent = api.buildPhrasingContent(titleLines);
|
|
49
|
+
if (phrasingContent == null)
|
|
50
|
+
return [];
|
|
51
|
+
return api.parsePhrasingContent(phrasingContent);
|
|
52
|
+
})();
|
|
53
|
+
const node = {
|
|
54
|
+
type: ast.AdmonitionType,
|
|
55
|
+
keyword: character.calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
|
|
56
|
+
title,
|
|
57
|
+
children,
|
|
58
|
+
};
|
|
59
|
+
return node;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
14
64
|
const uniqueName = '@yozora/tokenizer-admonition';
|
|
15
65
|
|
|
16
|
-
class AdmonitionTokenizer extends FencedBlockTokenizer__default[
|
|
66
|
+
class AdmonitionTokenizer extends FencedBlockTokenizer__default["default"] {
|
|
17
67
|
constructor(props = {}) {
|
|
18
68
|
var _a, _b;
|
|
19
69
|
super({
|
|
@@ -23,50 +73,13 @@ class AdmonitionTokenizer extends FencedBlockTokenizer__default['default'] {
|
|
|
23
73
|
markers: [character.AsciiCodePoint.COLON],
|
|
24
74
|
markersRequired: 3,
|
|
25
75
|
});
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
onClose(token, api) {
|
|
29
|
-
const children = api.rollbackPhrasingLines(token.lines);
|
|
30
|
-
token.children = children;
|
|
31
|
-
}
|
|
32
|
-
parseBlock(token, children, api) {
|
|
33
|
-
const infoString = token.infoString;
|
|
34
|
-
let i = 0;
|
|
35
|
-
const keyword = [];
|
|
36
|
-
for (; i < infoString.length; ++i) {
|
|
37
|
-
const p = infoString[i];
|
|
38
|
-
if (character.isUnicodeWhitespaceCharacter(p.codePoint))
|
|
39
|
-
break;
|
|
40
|
-
keyword.push(p);
|
|
41
|
-
}
|
|
42
|
-
i = coreTokenizer.eatOptionalWhitespaces(infoString, i, infoString.length);
|
|
43
|
-
const title = (() => {
|
|
44
|
-
if (i >= infoString.length)
|
|
45
|
-
return [];
|
|
46
|
-
const titleLines = [
|
|
47
|
-
{
|
|
48
|
-
nodePoints: infoString,
|
|
49
|
-
startIndex: i,
|
|
50
|
-
endIndex: infoString.length,
|
|
51
|
-
firstNonWhitespaceIndex: i,
|
|
52
|
-
countOfPrecedeSpaces: 0,
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
const phrasingContent = api.buildPhrasingContent(titleLines);
|
|
56
|
-
if (phrasingContent == null)
|
|
57
|
-
return [];
|
|
58
|
-
return api.parsePhrasingContent(phrasingContent);
|
|
59
|
-
})();
|
|
60
|
-
const node = {
|
|
61
|
-
type: ast.AdmonitionType,
|
|
62
|
-
keyword: character.calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
|
|
63
|
-
title,
|
|
64
|
-
children,
|
|
65
|
-
};
|
|
66
|
-
return node;
|
|
76
|
+
this.match = match;
|
|
77
|
+
this.parse = parse;
|
|
67
78
|
}
|
|
68
79
|
}
|
|
69
80
|
|
|
70
81
|
exports.AdmonitionTokenizer = AdmonitionTokenizer;
|
|
71
82
|
exports.AdmonitionTokenizerName = uniqueName;
|
|
72
|
-
exports
|
|
83
|
+
exports.admonitionMatch = match;
|
|
84
|
+
exports.admonitionParse = parse;
|
|
85
|
+
exports["default"] = AdmonitionTokenizer;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
|
+
import FencedBlockTokenizer, { fencedMatch } from '@yozora/tokenizer-fenced-block';
|
|
1
2
|
import { AdmonitionType } from '@yozora/ast';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { isUnicodeWhitespaceCharacter, calcEscapedStringFromNodePoints, AsciiCodePoint } from '@yozora/character';
|
|
4
|
+
import { eatOptionalWhitespaces, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
5
|
+
|
|
6
|
+
const match = function (api) {
|
|
7
|
+
const hook = fencedMatch.call(this, api);
|
|
8
|
+
return Object.assign(Object.assign({}, hook), { isContainingBlock: true, onClose });
|
|
9
|
+
function onClose(token) {
|
|
10
|
+
const children = api.rollbackPhrasingLines(token.lines);
|
|
11
|
+
token.children = children;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const parse = function (api) {
|
|
16
|
+
return {
|
|
17
|
+
parse: (token, children) => {
|
|
18
|
+
const infoString = token.infoString;
|
|
19
|
+
let i = 0;
|
|
20
|
+
const keyword = [];
|
|
21
|
+
for (; i < infoString.length; ++i) {
|
|
22
|
+
const p = infoString[i];
|
|
23
|
+
if (isUnicodeWhitespaceCharacter(p.codePoint))
|
|
24
|
+
break;
|
|
25
|
+
keyword.push(p);
|
|
26
|
+
}
|
|
27
|
+
i = eatOptionalWhitespaces(infoString, i, infoString.length);
|
|
28
|
+
const title = (() => {
|
|
29
|
+
if (i >= infoString.length)
|
|
30
|
+
return [];
|
|
31
|
+
const titleLines = [
|
|
32
|
+
{
|
|
33
|
+
nodePoints: infoString,
|
|
34
|
+
startIndex: i,
|
|
35
|
+
endIndex: infoString.length,
|
|
36
|
+
firstNonWhitespaceIndex: i,
|
|
37
|
+
countOfPrecedeSpaces: 0,
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
const phrasingContent = api.buildPhrasingContent(titleLines);
|
|
41
|
+
if (phrasingContent == null)
|
|
42
|
+
return [];
|
|
43
|
+
return api.parsePhrasingContent(phrasingContent);
|
|
44
|
+
})();
|
|
45
|
+
const node = {
|
|
46
|
+
type: AdmonitionType,
|
|
47
|
+
keyword: calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
|
|
48
|
+
title,
|
|
49
|
+
children,
|
|
50
|
+
};
|
|
51
|
+
return node;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
};
|
|
5
55
|
|
|
6
56
|
const uniqueName = '@yozora/tokenizer-admonition';
|
|
7
57
|
|
|
@@ -15,48 +65,9 @@ class AdmonitionTokenizer extends FencedBlockTokenizer {
|
|
|
15
65
|
markers: [AsciiCodePoint.COLON],
|
|
16
66
|
markersRequired: 3,
|
|
17
67
|
});
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
onClose(token, api) {
|
|
21
|
-
const children = api.rollbackPhrasingLines(token.lines);
|
|
22
|
-
token.children = children;
|
|
23
|
-
}
|
|
24
|
-
parseBlock(token, children, api) {
|
|
25
|
-
const infoString = token.infoString;
|
|
26
|
-
let i = 0;
|
|
27
|
-
const keyword = [];
|
|
28
|
-
for (; i < infoString.length; ++i) {
|
|
29
|
-
const p = infoString[i];
|
|
30
|
-
if (isUnicodeWhitespaceCharacter(p.codePoint))
|
|
31
|
-
break;
|
|
32
|
-
keyword.push(p);
|
|
33
|
-
}
|
|
34
|
-
i = eatOptionalWhitespaces(infoString, i, infoString.length);
|
|
35
|
-
const title = (() => {
|
|
36
|
-
if (i >= infoString.length)
|
|
37
|
-
return [];
|
|
38
|
-
const titleLines = [
|
|
39
|
-
{
|
|
40
|
-
nodePoints: infoString,
|
|
41
|
-
startIndex: i,
|
|
42
|
-
endIndex: infoString.length,
|
|
43
|
-
firstNonWhitespaceIndex: i,
|
|
44
|
-
countOfPrecedeSpaces: 0,
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
const phrasingContent = api.buildPhrasingContent(titleLines);
|
|
48
|
-
if (phrasingContent == null)
|
|
49
|
-
return [];
|
|
50
|
-
return api.parsePhrasingContent(phrasingContent);
|
|
51
|
-
})();
|
|
52
|
-
const node = {
|
|
53
|
-
type: AdmonitionType,
|
|
54
|
-
keyword: calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
|
|
55
|
-
title,
|
|
56
|
-
children,
|
|
57
|
-
};
|
|
58
|
-
return node;
|
|
68
|
+
this.match = match;
|
|
69
|
+
this.parse = parse;
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
|
|
62
|
-
export { AdmonitionTokenizer, uniqueName as AdmonitionTokenizerName, AdmonitionTokenizer as default };
|
|
73
|
+
export { AdmonitionTokenizer, uniqueName as AdmonitionTokenizerName, match as admonitionMatch, parse as admonitionParse, AdmonitionTokenizer as default };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
export { match as admonitionMatch } from './match';
|
|
2
|
+
export { parse as admonitionParse } from './parse';
|
|
3
|
+
export { AdmonitionTokenizer, AdmonitionTokenizer as default } from './tokenizer';
|
|
3
4
|
export { uniqueName as AdmonitionTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default AdmonitionTokenizer;
|
|
5
|
+
export type { IHookContext as IAdmonitionHookContext, IToken as IAdmonitionToken, ITokenizerProps as IAdmonitionTokenizerProps, } from './types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IHookContext, IToken, T } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A code fence is a sequence of at least three consecutive backtick characters
|
|
5
|
+
* (`) or tildes (~). (Tildes and backticks cannot be mixed.) A fenced code
|
|
6
|
+
* block begins with a code fence, indented no more than three spaces.
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/syntax-tree/mdast#code
|
|
9
|
+
* @see https://github.github.com/gfm/#code-fence
|
|
10
|
+
*/
|
|
11
|
+
export declare const match: IMatchBlockHookCreator<T, IToken, IHookContext>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { MatchBlockPhaseApi, ParseBlockPhaseApi, ResultOfParse, Tokenizer, TokenizerMatchBlockHook, TokenizerParseBlockHook } from '@yozora/core-tokenizer';
|
|
1
|
+
import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
3
2
|
import FencedBlockTokenizer from '@yozora/tokenizer-fenced-block';
|
|
4
|
-
import type {
|
|
3
|
+
import type { IHookContext, INode, IToken, ITokenizerProps, T } from './types';
|
|
5
4
|
/**
|
|
6
5
|
* Lexical Analyzer for Admonition.
|
|
7
|
-
*
|
|
8
|
-
* A code fence is a sequence of at least three consecutive backtick characters
|
|
9
|
-
* (`) or tildes (~). (Tildes and backticks cannot be mixed.) A fenced code
|
|
10
|
-
* block begins with a code fence, indented no more than three spaces.
|
|
11
|
-
*
|
|
12
6
|
* @see https://github.com/syntax-tree/mdast#code
|
|
13
7
|
* @see https://github.github.com/gfm/#code-fence
|
|
14
8
|
*/
|
|
15
|
-
export declare class AdmonitionTokenizer extends FencedBlockTokenizer<T> implements
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* Resolve children.
|
|
20
|
-
* @override
|
|
21
|
-
* @see TokenizerMatchBlockHook
|
|
22
|
-
*/
|
|
23
|
-
onClose(token: Token, api: MatchBlockPhaseApi): void;
|
|
24
|
-
/**
|
|
25
|
-
* @override
|
|
26
|
-
* @see TokenizerParseBlockHook
|
|
27
|
-
*/
|
|
28
|
-
parseBlock(token: Token, children: YastNode[], api: Readonly<ParseBlockPhaseApi>): ResultOfParse<T, Node>;
|
|
9
|
+
export declare class AdmonitionTokenizer extends FencedBlockTokenizer<T, 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>;
|
|
29
13
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AdmonitionType, IAdmonition } from '@yozora/ast';
|
|
2
|
+
import type { IBaseBlockTokenizerProps, IYastBlockToken } from '@yozora/core-tokenizer';
|
|
3
|
+
import type { IFencedBlockHookContext, IFencedBlockToken } from '@yozora/tokenizer-fenced-block';
|
|
4
4
|
export declare type T = AdmonitionType;
|
|
5
|
-
export declare type
|
|
5
|
+
export declare type INode = IAdmonition;
|
|
6
6
|
export declare const uniqueName = "@yozora/tokenizer-admonition";
|
|
7
|
-
export interface
|
|
7
|
+
export interface IToken extends IFencedBlockToken<T> {
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
|
-
children?:
|
|
11
|
+
children?: IYastBlockToken[];
|
|
12
12
|
}
|
|
13
|
-
export declare type
|
|
13
|
+
export declare type IHookContext = IFencedBlockHookContext<T>;
|
|
14
|
+
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-admonition",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
4
|
"description": "Tokenizer for processing admonitions",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@yozora/ast": "^
|
|
46
|
-
"@yozora/character": "^
|
|
47
|
-
"@yozora/core-tokenizer": "^
|
|
48
|
-
"@yozora/tokenizer-fenced-block": "^
|
|
45
|
+
"@yozora/ast": "^2.0.0-alpha.0",
|
|
46
|
+
"@yozora/character": "^2.0.0-alpha.0",
|
|
47
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.0",
|
|
48
|
+
"@yozora/tokenizer-fenced-block": "^2.0.0-alpha.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
|
|
51
51
|
}
|