@yozora/tokenizer-footnote-definition 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 +49 -31
- package/lib/esm/index.js +48 -32
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +22 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -39
- package/lib/types/types.d.ts +12 -9
- package/lib/types/util.d.ts +2 -2
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var ast = require('@yozora/ast');
|
|
6
5
|
var character = require('@yozora/character');
|
|
6
|
+
var ast = require('@yozora/ast');
|
|
7
7
|
var coreTokenizer = require('@yozora/core-tokenizer');
|
|
8
8
|
|
|
9
|
-
const uniqueName = '@yozora/tokenizer-footnote-definition';
|
|
10
|
-
|
|
11
9
|
function eatFootnoteLabel(nodePoints, firstNonWhitespaceIndex, endIndex) {
|
|
12
10
|
let i = firstNonWhitespaceIndex;
|
|
13
11
|
if (i + 1 >= endIndex ||
|
|
@@ -38,17 +36,15 @@ function eatFootnoteLabel(nodePoints, firstNonWhitespaceIndex, endIndex) {
|
|
|
38
36
|
return -1;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
eatOpener(line) {
|
|
39
|
+
const match = function (api) {
|
|
40
|
+
const { indent } = this;
|
|
41
|
+
return {
|
|
42
|
+
isContainingBlock: true,
|
|
43
|
+
eatOpener,
|
|
44
|
+
eatContinuationText,
|
|
45
|
+
onClose,
|
|
46
|
+
};
|
|
47
|
+
function eatOpener(line) {
|
|
52
48
|
if (line.countOfPrecedeSpaces >= 4)
|
|
53
49
|
return null;
|
|
54
50
|
const { nodePoints, startIndex, firstNonWhitespaceIndex, endIndex } = line;
|
|
@@ -73,40 +69,62 @@ class FootnoteDefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
73
69
|
};
|
|
74
70
|
return { token, nextIndex: nextIndex + 1 };
|
|
75
71
|
}
|
|
76
|
-
eatContinuationText(line) {
|
|
77
|
-
const { startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces
|
|
72
|
+
function eatContinuationText(line) {
|
|
73
|
+
const { startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line;
|
|
78
74
|
if (firstNonWhitespaceIndex >= endIndex) {
|
|
79
75
|
return {
|
|
80
76
|
status: 'opening',
|
|
81
|
-
nextIndex: Math.min(endIndex - 1, startIndex +
|
|
77
|
+
nextIndex: Math.min(endIndex - 1, startIndex + indent),
|
|
82
78
|
};
|
|
83
79
|
}
|
|
84
|
-
if (countOfPrecedeSpaces >=
|
|
85
|
-
return { status: 'opening', nextIndex: startIndex +
|
|
80
|
+
if (countOfPrecedeSpaces >= indent) {
|
|
81
|
+
return { status: 'opening', nextIndex: startIndex + indent };
|
|
86
82
|
}
|
|
87
83
|
return { status: 'notMatched' };
|
|
88
84
|
}
|
|
89
|
-
onClose(token
|
|
85
|
+
function onClose(token) {
|
|
90
86
|
const label = character.calcStringFromNodePoints(token.label.nodePoints, token.label.startIndex + 2, token.label.endIndex - 1);
|
|
91
87
|
const identifier = coreTokenizer.resolveLabelToIdentifier(label);
|
|
92
88
|
api.registerFootnoteDefinitionIdentifier(identifier);
|
|
93
89
|
token._label = label;
|
|
94
90
|
token._identifier = identifier;
|
|
95
91
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const parse = function () {
|
|
95
|
+
return {
|
|
96
|
+
parse: (token, children) => {
|
|
97
|
+
const label = token._label;
|
|
98
|
+
const identifier = token._identifier;
|
|
99
|
+
const node = {
|
|
100
|
+
type: ast.FootnoteDefinitionType,
|
|
101
|
+
identifier,
|
|
102
|
+
label,
|
|
103
|
+
children,
|
|
104
|
+
};
|
|
105
|
+
return node;
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const uniqueName = '@yozora/tokenizer-footnote-definition';
|
|
111
|
+
|
|
112
|
+
class FootnoteDefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
113
|
+
constructor(props = {}) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
super({
|
|
116
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
117
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_BLOCK,
|
|
118
|
+
});
|
|
119
|
+
this.indent = 4;
|
|
120
|
+
this.match = match;
|
|
121
|
+
this.parse = parse;
|
|
106
122
|
}
|
|
107
123
|
}
|
|
108
124
|
|
|
109
125
|
exports.FootnoteDefinitionTokenizer = FootnoteDefinitionTokenizer;
|
|
110
126
|
exports.FootnoteDefinitionTokenizerName = uniqueName;
|
|
111
|
-
exports[
|
|
127
|
+
exports["default"] = FootnoteDefinitionTokenizer;
|
|
112
128
|
exports.eatFootnoteLabel = eatFootnoteLabel;
|
|
129
|
+
exports.footnoteDefinitionMatch = match;
|
|
130
|
+
exports.footnoteDefinitionParse = parse;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { FootnoteDefinitionType } from '@yozora/ast';
|
|
2
1
|
import { AsciiCodePoint, isWhitespaceCharacter, VirtualCodePoint, calcStringFromNodePoints } from '@yozora/character';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const uniqueName = '@yozora/tokenizer-footnote-definition';
|
|
2
|
+
import { FootnoteDefinitionType } from '@yozora/ast';
|
|
3
|
+
import { calcStartYastNodePoint, calcEndYastNodePoint, resolveLabelToIdentifier, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
6
4
|
|
|
7
5
|
function eatFootnoteLabel(nodePoints, firstNonWhitespaceIndex, endIndex) {
|
|
8
6
|
let i = firstNonWhitespaceIndex;
|
|
@@ -34,17 +32,15 @@ function eatFootnoteLabel(nodePoints, firstNonWhitespaceIndex, endIndex) {
|
|
|
34
32
|
return -1;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
eatOpener(line) {
|
|
35
|
+
const match = function (api) {
|
|
36
|
+
const { indent } = this;
|
|
37
|
+
return {
|
|
38
|
+
isContainingBlock: true,
|
|
39
|
+
eatOpener,
|
|
40
|
+
eatContinuationText,
|
|
41
|
+
onClose,
|
|
42
|
+
};
|
|
43
|
+
function eatOpener(line) {
|
|
48
44
|
if (line.countOfPrecedeSpaces >= 4)
|
|
49
45
|
return null;
|
|
50
46
|
const { nodePoints, startIndex, firstNonWhitespaceIndex, endIndex } = line;
|
|
@@ -69,37 +65,57 @@ class FootnoteDefinitionTokenizer extends BaseBlockTokenizer {
|
|
|
69
65
|
};
|
|
70
66
|
return { token, nextIndex: nextIndex + 1 };
|
|
71
67
|
}
|
|
72
|
-
eatContinuationText(line) {
|
|
73
|
-
const { startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces
|
|
68
|
+
function eatContinuationText(line) {
|
|
69
|
+
const { startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line;
|
|
74
70
|
if (firstNonWhitespaceIndex >= endIndex) {
|
|
75
71
|
return {
|
|
76
72
|
status: 'opening',
|
|
77
|
-
nextIndex: Math.min(endIndex - 1, startIndex +
|
|
73
|
+
nextIndex: Math.min(endIndex - 1, startIndex + indent),
|
|
78
74
|
};
|
|
79
75
|
}
|
|
80
|
-
if (countOfPrecedeSpaces >=
|
|
81
|
-
return { status: 'opening', nextIndex: startIndex +
|
|
76
|
+
if (countOfPrecedeSpaces >= indent) {
|
|
77
|
+
return { status: 'opening', nextIndex: startIndex + indent };
|
|
82
78
|
}
|
|
83
79
|
return { status: 'notMatched' };
|
|
84
80
|
}
|
|
85
|
-
onClose(token
|
|
81
|
+
function onClose(token) {
|
|
86
82
|
const label = calcStringFromNodePoints(token.label.nodePoints, token.label.startIndex + 2, token.label.endIndex - 1);
|
|
87
83
|
const identifier = resolveLabelToIdentifier(label);
|
|
88
84
|
api.registerFootnoteDefinitionIdentifier(identifier);
|
|
89
85
|
token._label = label;
|
|
90
86
|
token._identifier = identifier;
|
|
91
87
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const parse = function () {
|
|
91
|
+
return {
|
|
92
|
+
parse: (token, children) => {
|
|
93
|
+
const label = token._label;
|
|
94
|
+
const identifier = token._identifier;
|
|
95
|
+
const node = {
|
|
96
|
+
type: FootnoteDefinitionType,
|
|
97
|
+
identifier,
|
|
98
|
+
label,
|
|
99
|
+
children,
|
|
100
|
+
};
|
|
101
|
+
return node;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const uniqueName = '@yozora/tokenizer-footnote-definition';
|
|
107
|
+
|
|
108
|
+
class FootnoteDefinitionTokenizer extends BaseBlockTokenizer {
|
|
109
|
+
constructor(props = {}) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
super({
|
|
112
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
113
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_BLOCK,
|
|
114
|
+
});
|
|
115
|
+
this.indent = 4;
|
|
116
|
+
this.match = match;
|
|
117
|
+
this.parse = parse;
|
|
102
118
|
}
|
|
103
119
|
}
|
|
104
120
|
|
|
105
|
-
export { FootnoteDefinitionTokenizer, uniqueName as FootnoteDefinitionTokenizerName, FootnoteDefinitionTokenizer as default, eatFootnoteLabel };
|
|
121
|
+
export { FootnoteDefinitionTokenizer, uniqueName as FootnoteDefinitionTokenizerName, FootnoteDefinitionTokenizer as default, eatFootnoteLabel, match as footnoteDefinitionMatch, parse as footnoteDefinitionParse };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FootnoteDefinitionTokenizer } from './tokenizer';
|
|
2
1
|
export * from './util';
|
|
3
|
-
export {
|
|
2
|
+
export { match as footnoteDefinitionMatch } from './match';
|
|
3
|
+
export { parse as footnoteDefinitionParse } from './parse';
|
|
4
|
+
export { FootnoteDefinitionTokenizer, FootnoteDefinitionTokenizer as default } from './tokenizer';
|
|
4
5
|
export { uniqueName as FootnoteDefinitionTokenizerName } from './types';
|
|
5
|
-
export type {
|
|
6
|
-
export default FootnoteDefinitionTokenizer;
|
|
6
|
+
export type { IHookContext as IFootnoteDefinitionHookContext, IToken as IFootnoteDefinitionToken, ITokenizerProps as IFootnoteDefinitionTokenizerProps, } from './types';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IHookContext, IToken, T } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A footnote reference definition consists of a footnote label, indented up
|
|
5
|
+
* to three spaces, followed by a colon (:), optional whitespace (including up
|
|
6
|
+
* to one line ending), a footnote contents consisted by paragraph-like strings.
|
|
7
|
+
*
|
|
8
|
+
* Unlike the link label, the footnote label should be on the same line and it
|
|
9
|
+
* begins with a left bracket ([) followed by a caret (^), and ends with the
|
|
10
|
+
* first right bracket (]) that is not backslash-escaped. Between the caret of
|
|
11
|
+
* right bracket, there must be at least one non-whitespace character.
|
|
12
|
+
* Unescaped square bracket characters are not allowed inside the opening creat
|
|
13
|
+
* and closing square bracket of footnote labels. A footnote label can have at
|
|
14
|
+
* most 999 characters inside the caret and right bracket.
|
|
15
|
+
*
|
|
16
|
+
* @see https://github.github.com/gfm/#link-label
|
|
17
|
+
* @see https://github.github.com/gfm/#link-reference-definition
|
|
18
|
+
* @see https://github.com/syntax-tree/mdast-util-footnote
|
|
19
|
+
* @see https://github.com/remarkjs/remark-footnotes
|
|
20
|
+
* @see https://www.markdownguide.org/extended-syntax/#footnotes
|
|
21
|
+
*/
|
|
22
|
+
export declare const match: IMatchBlockHookCreator<T, IToken, IHookContext>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,50 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { MatchBlockPhaseApi, PhrasingContentLine, ResultOfEatContinuationText, ResultOfEatOpener, ResultOfOnClose, ResultOfParse, Tokenizer, TokenizerMatchBlockHook, TokenizerParseBlockHook } 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 FootnoteDefinition.
|
|
7
|
-
*
|
|
8
|
-
* A footnote reference definition consists of a footnote label, indented up
|
|
9
|
-
* to three spaces, followed by a colon (:), optional whitespace (including up
|
|
10
|
-
* to one line ending), a footnote contents consisted by paragraph-like strings.
|
|
11
|
-
*
|
|
12
|
-
* Unlike the link label, the footnote label should be on the same line and it
|
|
13
|
-
* begins with a left bracket ([) followed by a caret (^), and ends with the
|
|
14
|
-
* first right bracket (]) that is not backslash-escaped. Between the caret of
|
|
15
|
-
* right bracket, there must be at least one non-whitespace character.
|
|
16
|
-
* Unescaped square bracket characters are not allowed inside the opening creat
|
|
17
|
-
* and closing square bracket of footnote labels. A footnote label can have at
|
|
18
|
-
* most 999 characters inside the caret and right bracket.
|
|
19
|
-
*
|
|
20
6
|
* @see https://github.github.com/gfm/#link-label
|
|
21
7
|
* @see https://github.github.com/gfm/#link-reference-definition
|
|
22
8
|
* @see https://github.com/syntax-tree/mdast-util-footnote
|
|
23
9
|
* @see https://github.com/remarkjs/remark-footnotes
|
|
24
10
|
* @see https://www.markdownguide.org/extended-syntax/#footnotes
|
|
25
11
|
*/
|
|
26
|
-
export declare class FootnoteDefinitionTokenizer extends BaseBlockTokenizer
|
|
27
|
-
|
|
12
|
+
export declare class FootnoteDefinitionTokenizer extends BaseBlockTokenizer<T, IToken, INode, IHookContext> implements IBlockTokenizer<T, IToken, INode, IHookContext> {
|
|
13
|
+
constructor(props?: ITokenizerProps);
|
|
28
14
|
readonly indent = 4;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* @override
|
|
32
|
-
* @see TokenizerMatchBlockHook
|
|
33
|
-
*/
|
|
34
|
-
eatOpener(line: Readonly<PhrasingContentLine>): ResultOfEatOpener<T, Token>;
|
|
35
|
-
/**
|
|
36
|
-
* @override
|
|
37
|
-
* @see TokenizerMatchBlockHook
|
|
38
|
-
*/
|
|
39
|
-
eatContinuationText(line: Readonly<PhrasingContentLine>): ResultOfEatContinuationText;
|
|
40
|
-
/**
|
|
41
|
-
* @override
|
|
42
|
-
* @see TokenizerMatchBlockHook
|
|
43
|
-
*/
|
|
44
|
-
onClose(token: Token, api: Readonly<MatchBlockPhaseApi>): ResultOfOnClose;
|
|
45
|
-
/**
|
|
46
|
-
* @override
|
|
47
|
-
* @see TokenizerParseBlockHook
|
|
48
|
-
*/
|
|
49
|
-
parseBlock(token: Readonly<Token>, children?: YastNode[]): ResultOfParse<T, Node>;
|
|
15
|
+
readonly match: IMatchBlockHookCreator<T, IToken, IHookContext>;
|
|
16
|
+
readonly parse: IParseBlockHookCreator<T, IToken, INode, IHookContext>;
|
|
50
17
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { FootnoteDefinitionType, IFootnoteDefinition } from '@yozora/ast';
|
|
2
|
+
import type { INodeInterval, INodePoint } from '@yozora/character';
|
|
3
|
+
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, ITokenizer, IYastBlockToken } from '@yozora/core-tokenizer';
|
|
4
4
|
export declare type T = FootnoteDefinitionType;
|
|
5
|
-
export declare type
|
|
5
|
+
export declare type INode = IFootnoteDefinition;
|
|
6
6
|
export declare const uniqueName = "@yozora/tokenizer-footnote-definition";
|
|
7
|
-
export interface
|
|
7
|
+
export interface IToken extends IPartialYastBlockToken<T> {
|
|
8
8
|
/**
|
|
9
9
|
* Footnote label
|
|
10
10
|
*/
|
|
11
|
-
label:
|
|
12
|
-
nodePoints: ReadonlyArray<
|
|
11
|
+
label: INodeInterval & {
|
|
12
|
+
nodePoints: ReadonlyArray<INodePoint>;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
|
-
children:
|
|
17
|
+
children: IYastBlockToken[];
|
|
18
18
|
/**
|
|
19
19
|
* Resolved definition label.
|
|
20
20
|
*/
|
|
@@ -24,4 +24,7 @@ export interface Token extends PartialYastBlockToken<T> {
|
|
|
24
24
|
*/
|
|
25
25
|
_identifier?: string;
|
|
26
26
|
}
|
|
27
|
-
export
|
|
27
|
+
export interface IHookContext extends ITokenizer {
|
|
28
|
+
indent: number;
|
|
29
|
+
}
|
|
30
|
+
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/lib/types/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { INodePoint } from '@yozora/character';
|
|
2
2
|
/**
|
|
3
3
|
* Try to match a footnote label.
|
|
4
4
|
*
|
|
@@ -15,4 +15,4 @@ import type { NodePoint } from '@yozora/character';
|
|
|
15
15
|
* @param endIndex
|
|
16
16
|
* @see https://github.github.com/gfm/#link-label
|
|
17
17
|
*/
|
|
18
|
-
export declare function eatFootnoteLabel(nodePoints: ReadonlyArray<
|
|
18
|
+
export declare function eatFootnoteLabel(nodePoints: ReadonlyArray<INodePoint>, firstNonWhitespaceIndex: number, endIndex: number): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-footnote-definition",
|
|
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
|
}
|