@yozora/tokenizer-footnote-reference 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 CHANGED
@@ -16,56 +16,66 @@ class FootnoteReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
16
16
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
17
17
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
18
18
  });
19
- }
20
- _findDelimiter(startIndex, endIndex, nodePoints) {
21
- for (let i = startIndex; i < endIndex; ++i) {
22
- const p = nodePoints[i];
23
- switch (p.codePoint) {
24
- case character.AsciiCodePoint.BACKSLASH:
25
- i += 1;
26
- break;
27
- case character.AsciiCodePoint.OPEN_BRACKET: {
28
- const nextIndex = tokenizerFootnoteDefinition.eatFootnoteLabel(nodePoints, i, endIndex);
29
- if (nextIndex >= 0) {
30
- return {
31
- type: 'full',
32
- startIndex: i,
33
- endIndex: nextIndex,
34
- };
19
+ this.match = api => {
20
+ return {
21
+ findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
22
+ processSingleDelimiter,
23
+ };
24
+ function _findDelimiter(startIndex, endIndex) {
25
+ const nodePoints = api.getNodePoints();
26
+ for (let i = startIndex; i < endIndex; ++i) {
27
+ const p = nodePoints[i];
28
+ switch (p.codePoint) {
29
+ case character.AsciiCodePoint.BACKSLASH:
30
+ i += 1;
31
+ break;
32
+ case character.AsciiCodePoint.OPEN_BRACKET: {
33
+ const nextIndex = tokenizerFootnoteDefinition.eatFootnoteLabel(nodePoints, i, endIndex);
34
+ if (nextIndex >= 0) {
35
+ return {
36
+ type: 'full',
37
+ startIndex: i,
38
+ endIndex: nextIndex,
39
+ };
40
+ }
41
+ break;
42
+ }
35
43
  }
36
- break;
37
44
  }
45
+ return null;
46
+ }
47
+ function processSingleDelimiter(delimiter) {
48
+ const nodePoints = api.getNodePoints();
49
+ const labelAndIdentifier = coreTokenizer.resolveLinkLabelAndIdentifier(nodePoints, delimiter.startIndex + 2, delimiter.endIndex - 1);
50
+ if (labelAndIdentifier == null)
51
+ return [];
52
+ const { label, identifier } = labelAndIdentifier;
53
+ if (!api.hasFootnoteDefinition(identifier))
54
+ return [];
55
+ const token = {
56
+ nodeType: ast.FootnoteReferenceType,
57
+ startIndex: delimiter.startIndex,
58
+ endIndex: delimiter.endIndex,
59
+ label,
60
+ identifier,
61
+ };
62
+ return [token];
38
63
  }
39
- }
40
- return null;
41
- }
42
- processSingleDelimiter(delimiter, nodePoints, api) {
43
- const labelAndIdentifier = coreTokenizer.resolveLinkLabelAndIdentifier(nodePoints, delimiter.startIndex + 2, delimiter.endIndex - 1);
44
- if (labelAndIdentifier == null)
45
- return [];
46
- const { label, identifier } = labelAndIdentifier;
47
- if (!api.hasFootnoteDefinition(identifier))
48
- return [];
49
- const token = {
50
- nodeType: ast.FootnoteReferenceType,
51
- startIndex: delimiter.startIndex,
52
- endIndex: delimiter.endIndex,
53
- label,
54
- identifier,
55
- };
56
- return [token];
57
- }
58
- processToken(token) {
59
- const { identifier, label } = token;
60
- const result = {
61
- type: ast.FootnoteReferenceType,
62
- identifier,
63
- label,
64
64
  };
65
- return result;
65
+ this.parse = () => ({
66
+ parse: token => {
67
+ const { identifier, label } = token;
68
+ const result = {
69
+ type: ast.FootnoteReferenceType,
70
+ identifier,
71
+ label,
72
+ };
73
+ return result;
74
+ },
75
+ });
66
76
  }
67
77
  }
68
78
 
69
79
  exports.FootnoteReferenceTokenizer = FootnoteReferenceTokenizer;
70
80
  exports.FootnoteReferenceTokenizerName = uniqueName;
71
- exports['default'] = FootnoteReferenceTokenizer;
81
+ exports["default"] = FootnoteReferenceTokenizer;
package/lib/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FootnoteReferenceType } from '@yozora/ast';
2
2
  import { AsciiCodePoint } from '@yozora/character';
3
- import { BaseInlineTokenizer, TokenizerPriority, resolveLinkLabelAndIdentifier } from '@yozora/core-tokenizer';
3
+ import { BaseInlineTokenizer, TokenizerPriority, genFindDelimiter, resolveLinkLabelAndIdentifier } from '@yozora/core-tokenizer';
4
4
  import { eatFootnoteLabel } from '@yozora/tokenizer-footnote-definition';
5
5
 
6
6
  const uniqueName = '@yozora/tokenizer-footnote-reference';
@@ -12,53 +12,63 @@ class FootnoteReferenceTokenizer extends BaseInlineTokenizer {
12
12
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
13
13
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.ATOMIC,
14
14
  });
15
- }
16
- _findDelimiter(startIndex, endIndex, nodePoints) {
17
- for (let i = startIndex; i < endIndex; ++i) {
18
- const p = nodePoints[i];
19
- switch (p.codePoint) {
20
- case AsciiCodePoint.BACKSLASH:
21
- i += 1;
22
- break;
23
- case AsciiCodePoint.OPEN_BRACKET: {
24
- const nextIndex = eatFootnoteLabel(nodePoints, i, endIndex);
25
- if (nextIndex >= 0) {
26
- return {
27
- type: 'full',
28
- startIndex: i,
29
- endIndex: nextIndex,
30
- };
15
+ this.match = api => {
16
+ return {
17
+ findDelimiter: () => genFindDelimiter(_findDelimiter),
18
+ processSingleDelimiter,
19
+ };
20
+ function _findDelimiter(startIndex, endIndex) {
21
+ const nodePoints = api.getNodePoints();
22
+ for (let i = startIndex; i < endIndex; ++i) {
23
+ const p = nodePoints[i];
24
+ switch (p.codePoint) {
25
+ case AsciiCodePoint.BACKSLASH:
26
+ i += 1;
27
+ break;
28
+ case AsciiCodePoint.OPEN_BRACKET: {
29
+ const nextIndex = eatFootnoteLabel(nodePoints, i, endIndex);
30
+ if (nextIndex >= 0) {
31
+ return {
32
+ type: 'full',
33
+ startIndex: i,
34
+ endIndex: nextIndex,
35
+ };
36
+ }
37
+ break;
38
+ }
31
39
  }
32
- break;
33
40
  }
41
+ return null;
42
+ }
43
+ function processSingleDelimiter(delimiter) {
44
+ const nodePoints = api.getNodePoints();
45
+ const labelAndIdentifier = resolveLinkLabelAndIdentifier(nodePoints, delimiter.startIndex + 2, delimiter.endIndex - 1);
46
+ if (labelAndIdentifier == null)
47
+ return [];
48
+ const { label, identifier } = labelAndIdentifier;
49
+ if (!api.hasFootnoteDefinition(identifier))
50
+ return [];
51
+ const token = {
52
+ nodeType: FootnoteReferenceType,
53
+ startIndex: delimiter.startIndex,
54
+ endIndex: delimiter.endIndex,
55
+ label,
56
+ identifier,
57
+ };
58
+ return [token];
34
59
  }
35
- }
36
- return null;
37
- }
38
- processSingleDelimiter(delimiter, nodePoints, api) {
39
- const labelAndIdentifier = resolveLinkLabelAndIdentifier(nodePoints, delimiter.startIndex + 2, delimiter.endIndex - 1);
40
- if (labelAndIdentifier == null)
41
- return [];
42
- const { label, identifier } = labelAndIdentifier;
43
- if (!api.hasFootnoteDefinition(identifier))
44
- return [];
45
- const token = {
46
- nodeType: FootnoteReferenceType,
47
- startIndex: delimiter.startIndex,
48
- endIndex: delimiter.endIndex,
49
- label,
50
- identifier,
51
- };
52
- return [token];
53
- }
54
- processToken(token) {
55
- const { identifier, label } = token;
56
- const result = {
57
- type: FootnoteReferenceType,
58
- identifier,
59
- label,
60
60
  };
61
- return result;
61
+ this.parse = () => ({
62
+ parse: token => {
63
+ const { identifier, label } = token;
64
+ const result = {
65
+ type: FootnoteReferenceType,
66
+ identifier,
67
+ label,
68
+ };
69
+ return result;
70
+ },
71
+ });
62
72
  }
63
73
  }
64
74
 
@@ -1,5 +1,3 @@
1
- import { FootnoteReferenceTokenizer } from './tokenizer';
2
- export { FootnoteReferenceTokenizer } from './tokenizer';
1
+ export { FootnoteReferenceTokenizer, FootnoteReferenceTokenizer as default } from './tokenizer';
3
2
  export { uniqueName as FootnoteReferenceTokenizerName } from './types';
4
- export type { Token as FootnoteReferenceToken, TokenizerProps as FootnoteReferenceTokenizerProps, } from './types';
5
- export default FootnoteReferenceTokenizer;
3
+ export type { IToken as IFootnoteReferenceToken, ITokenizerProps as IFootnoteReferenceTokenizerProps, } from './types';
@@ -1,7 +1,6 @@
1
- import type { NodePoint } from '@yozora/character';
2
- import type { MatchInlinePhaseApi, ResultOfProcessSingleDelimiter, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook } from '@yozora/core-tokenizer';
1
+ import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
3
2
  import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
4
- import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
3
+ import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
5
4
  /**
6
5
  * Lexical Analyzer for footnote reference.
7
6
  *
@@ -18,21 +17,8 @@ import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
18
17
  * @see https://github.com/syntax-tree/mdast#footnotereference
19
18
  * @see https://github.github.com/gfm/#link-label
20
19
  */
21
- export declare class FootnoteReferenceTokenizer extends BaseInlineTokenizer<Delimiter> implements Tokenizer, TokenizerMatchInlineHook<T, Delimiter, Token>, TokenizerParseInlineHook<T, Token, Node> {
22
- constructor(props?: TokenizerProps);
23
- /**
24
- * @override
25
- * @see BaseInlineTokenizer
26
- */
27
- protected _findDelimiter(startIndex: number, endIndex: number, nodePoints: ReadonlyArray<NodePoint>): Delimiter | null;
28
- /**
29
- * @override
30
- * @see TokenizerMatchInlineHook
31
- */
32
- processSingleDelimiter(delimiter: Delimiter, nodePoints: ReadonlyArray<NodePoint>, api: Readonly<MatchInlinePhaseApi>): ResultOfProcessSingleDelimiter<T, Token>;
33
- /**
34
- * @override
35
- * @see TokenizerParseInlineHook
36
- */
37
- processToken(token: Token): Node;
20
+ export declare class FootnoteReferenceTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
21
+ constructor(props?: ITokenizerProps);
22
+ readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
23
+ readonly parse: IParseInlineHookCreator<T, IToken, INode>;
38
24
  }
@@ -1,11 +1,11 @@
1
- import type { FootnoteReference, FootnoteReferenceType, YastAssociation } from '@yozora/ast';
2
- import type { BaseInlineTokenizerProps, PartialYastInlineToken, YastTokenDelimiter } from '@yozora/core-tokenizer';
1
+ import type { FootnoteReferenceType, IFootnoteReference, IYastAssociation } from '@yozora/ast';
2
+ import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
3
3
  export declare const uniqueName = "@yozora/tokenizer-footnote-reference";
4
4
  export declare type T = FootnoteReferenceType;
5
- export declare type Node = FootnoteReference;
6
- export interface Token extends PartialYastInlineToken<T>, YastAssociation {
5
+ export declare type INode = IFootnoteReference;
6
+ export interface IToken extends IPartialYastInlineToken<T>, IYastAssociation {
7
7
  }
8
- export interface Delimiter extends YastTokenDelimiter {
8
+ export interface IDelimiter extends IYastTokenDelimiter {
9
9
  type: 'full';
10
10
  }
11
- export declare type TokenizerProps = Partial<BaseInlineTokenizerProps>;
11
+ export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-footnote-reference",
3
- "version": "1.2.0",
3
+ "version": "2.0.0-alpha.0",
4
4
  "author": {
5
5
  "name": "guanghechen",
6
6
  "url": "https://github.com/guanghechen/"
@@ -35,10 +35,10 @@
35
35
  "test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
36
36
  },
37
37
  "dependencies": {
38
- "@yozora/ast": "^1.2.0",
39
- "@yozora/character": "^1.2.0",
40
- "@yozora/core-tokenizer": "^1.2.0",
41
- "@yozora/tokenizer-footnote-definition": "^1.2.0"
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
+ "@yozora/tokenizer-footnote-definition": "^2.0.0-alpha.0"
42
42
  },
43
- "gitHead": "86da40e50d2fe9acace68695288e15e012e6cd0d"
43
+ "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
44
44
  }