@yozora/tokenizer-footnote-reference 2.0.0-alpha.0 → 2.0.0-alpha.1

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 CHANGED
@@ -84,14 +84,14 @@ so you can use `YozoraParser` directly.
84
84
  registered in *YastParser* as a plugin-in before it can be used.
85
85
 
86
86
  ```typescript {4,9}
87
- import { DefaultYastParser } from '@yozora/core-parser'
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 FootnoteReferenceTokenizer from '@yozora/tokenizer-footnote-reference'
91
91
 
92
- const parser = new DefaultYastParser()
93
- .useBlockFallbackTokenizer(new ParagraphTokenizer())
94
- .useInlineFallbackTokenizer(new TextTokenizer())
92
+ const parser = new DefaultParser()
93
+ .useFallbackTokenizer(new ParagraphTokenizer())
94
+ .useFallbackTokenizer(new TextTokenizer())
95
95
  .useTokenizer(new FootnoteReferenceTokenizer())
96
96
 
97
97
  // parse source markdown content
@@ -278,7 +278,6 @@ Name | Type | Required | Default
278
278
  [@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
279
279
  [@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
280
280
  [@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
281
- [@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
282
281
  [@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
283
282
  [@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
284
283
  [@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
@@ -338,7 +337,6 @@ Name | Type | Required | Default
338
337
  [doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
339
338
  [doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
340
339
  [doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
341
- [doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
342
340
  [doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
343
341
  [doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
344
342
  [doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
package/lib/cjs/index.js CHANGED
@@ -7,6 +7,67 @@ var character = require('@yozora/character');
7
7
  var coreTokenizer = require('@yozora/core-tokenizer');
8
8
  var tokenizerFootnoteDefinition = require('@yozora/tokenizer-footnote-definition');
9
9
 
10
+ const match = function (api) {
11
+ return {
12
+ findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
13
+ processSingleDelimiter,
14
+ };
15
+ function _findDelimiter(startIndex, endIndex) {
16
+ const nodePoints = api.getNodePoints();
17
+ for (let i = startIndex; i < endIndex; ++i) {
18
+ const p = nodePoints[i];
19
+ switch (p.codePoint) {
20
+ case character.AsciiCodePoint.BACKSLASH:
21
+ i += 1;
22
+ break;
23
+ case character.AsciiCodePoint.OPEN_BRACKET: {
24
+ const nextIndex = tokenizerFootnoteDefinition.eatFootnoteLabel(nodePoints, i, endIndex);
25
+ if (nextIndex >= 0) {
26
+ return {
27
+ type: 'full',
28
+ startIndex: i,
29
+ endIndex: nextIndex,
30
+ };
31
+ }
32
+ break;
33
+ }
34
+ }
35
+ }
36
+ return null;
37
+ }
38
+ function processSingleDelimiter(delimiter) {
39
+ const nodePoints = api.getNodePoints();
40
+ const labelAndIdentifier = coreTokenizer.resolveLinkLabelAndIdentifier(nodePoints, delimiter.startIndex + 2, delimiter.endIndex - 1);
41
+ if (labelAndIdentifier == null)
42
+ return [];
43
+ const { label, identifier } = labelAndIdentifier;
44
+ if (!api.hasFootnoteDefinition(identifier))
45
+ return [];
46
+ const token = {
47
+ nodeType: ast.FootnoteReferenceType,
48
+ startIndex: delimiter.startIndex,
49
+ endIndex: delimiter.endIndex,
50
+ label,
51
+ identifier,
52
+ };
53
+ return [token];
54
+ }
55
+ };
56
+
57
+ const parse = function (api) {
58
+ return {
59
+ parse: token => {
60
+ const { identifier, label } = token;
61
+ const result = {
62
+ type: ast.FootnoteReferenceType,
63
+ identifier,
64
+ label,
65
+ };
66
+ return result;
67
+ },
68
+ };
69
+ };
70
+
10
71
  const uniqueName = '@yozora/tokenizer-footnote-reference';
11
72
 
12
73
  class FootnoteReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
@@ -16,66 +77,13 @@ class FootnoteReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
16
77
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
17
78
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
18
79
  });
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
- }
43
- }
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];
63
- }
64
- };
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
- });
80
+ this.match = match;
81
+ this.parse = parse;
76
82
  }
77
83
  }
78
84
 
79
85
  exports.FootnoteReferenceTokenizer = FootnoteReferenceTokenizer;
80
86
  exports.FootnoteReferenceTokenizerName = uniqueName;
81
87
  exports["default"] = FootnoteReferenceTokenizer;
88
+ exports.footnoteReferenceMatch = match;
89
+ exports.footnoteReferenceParse = parse;
package/lib/esm/index.js CHANGED
@@ -1,8 +1,69 @@
1
1
  import { FootnoteReferenceType } from '@yozora/ast';
2
2
  import { AsciiCodePoint } from '@yozora/character';
3
- import { BaseInlineTokenizer, TokenizerPriority, genFindDelimiter, resolveLinkLabelAndIdentifier } from '@yozora/core-tokenizer';
3
+ import { genFindDelimiter, resolveLinkLabelAndIdentifier, BaseInlineTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
4
4
  import { eatFootnoteLabel } from '@yozora/tokenizer-footnote-definition';
5
5
 
6
+ const match = function (api) {
7
+ return {
8
+ findDelimiter: () => genFindDelimiter(_findDelimiter),
9
+ processSingleDelimiter,
10
+ };
11
+ function _findDelimiter(startIndex, endIndex) {
12
+ const nodePoints = api.getNodePoints();
13
+ for (let i = startIndex; i < endIndex; ++i) {
14
+ const p = nodePoints[i];
15
+ switch (p.codePoint) {
16
+ case AsciiCodePoint.BACKSLASH:
17
+ i += 1;
18
+ break;
19
+ case AsciiCodePoint.OPEN_BRACKET: {
20
+ const nextIndex = eatFootnoteLabel(nodePoints, i, endIndex);
21
+ if (nextIndex >= 0) {
22
+ return {
23
+ type: 'full',
24
+ startIndex: i,
25
+ endIndex: nextIndex,
26
+ };
27
+ }
28
+ break;
29
+ }
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+ function processSingleDelimiter(delimiter) {
35
+ const nodePoints = api.getNodePoints();
36
+ const labelAndIdentifier = resolveLinkLabelAndIdentifier(nodePoints, delimiter.startIndex + 2, delimiter.endIndex - 1);
37
+ if (labelAndIdentifier == null)
38
+ return [];
39
+ const { label, identifier } = labelAndIdentifier;
40
+ if (!api.hasFootnoteDefinition(identifier))
41
+ return [];
42
+ const token = {
43
+ nodeType: FootnoteReferenceType,
44
+ startIndex: delimiter.startIndex,
45
+ endIndex: delimiter.endIndex,
46
+ label,
47
+ identifier,
48
+ };
49
+ return [token];
50
+ }
51
+ };
52
+
53
+ const parse = function (api) {
54
+ return {
55
+ parse: token => {
56
+ const { identifier, label } = token;
57
+ const result = {
58
+ type: FootnoteReferenceType,
59
+ identifier,
60
+ label,
61
+ };
62
+ return result;
63
+ },
64
+ };
65
+ };
66
+
6
67
  const uniqueName = '@yozora/tokenizer-footnote-reference';
7
68
 
8
69
  class FootnoteReferenceTokenizer extends BaseInlineTokenizer {
@@ -12,64 +73,9 @@ class FootnoteReferenceTokenizer extends BaseInlineTokenizer {
12
73
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
13
74
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.ATOMIC,
14
75
  });
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
- }
39
- }
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];
59
- }
60
- };
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
- });
76
+ this.match = match;
77
+ this.parse = parse;
72
78
  }
73
79
  }
74
80
 
75
- export { FootnoteReferenceTokenizer, uniqueName as FootnoteReferenceTokenizerName, FootnoteReferenceTokenizer as default };
81
+ export { FootnoteReferenceTokenizer, uniqueName as FootnoteReferenceTokenizerName, FootnoteReferenceTokenizer as default, match as footnoteReferenceMatch, parse as footnoteReferenceParse };
@@ -1,3 +1,5 @@
1
+ export { match as footnoteReferenceMatch } from './match';
2
+ export { parse as footnoteReferenceParse } from './parse';
1
3
  export { FootnoteReferenceTokenizer, FootnoteReferenceTokenizer as default } from './tokenizer';
2
4
  export { uniqueName as FootnoteReferenceTokenizerName } from './types';
3
- export type { IToken as IFootnoteReferenceToken, ITokenizerProps as IFootnoteReferenceTokenizerProps, } from './types';
5
+ export type { IThis as IFootnoteReferenceHookContext, IToken as IFootnoteReferenceToken, ITokenizerProps as IFootnoteReferenceTokenizerProps, } from './types';
@@ -0,0 +1,17 @@
1
+ import type { IMatchInlineHookCreator } from '@yozora/core-tokenizer';
2
+ import type { IDelimiter, IThis, IToken, T } from './types';
3
+ /**
4
+ * A full footnote consists of a footnote label.
5
+ *
6
+ * Unlike the link label, the footnote label should be on the same line and it
7
+ * begins with a left bracket ([) followed by a caret (^), and ends with the
8
+ * first right bracket (]) that is not backslash-escaped. Between the caret of
9
+ * right bracket, there must be at least one non-whitespace character.
10
+ * Unescaped square bracket characters are not allowed inside the opening creat
11
+ * and closing square bracket of footnote labels. A footnote label can have at
12
+ * most 999 characters inside the caret and right bracket.
13
+ *
14
+ * @see https://github.com/syntax-tree/mdast#footnotereference
15
+ * @see https://github.github.com/gfm/#link-label
16
+ */
17
+ export declare const match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
@@ -0,0 +1,3 @@
1
+ import type { IParseInlineHookCreator } from '@yozora/core-tokenizer';
2
+ import type { INode, IThis, IToken, T } from './types';
3
+ export declare const parse: IParseInlineHookCreator<T, IToken, INode, IThis>;
@@ -1,24 +1,13 @@
1
1
  import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
2
2
  import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
3
- import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
3
+ import type { IDelimiter, INode, IThis, IToken, ITokenizerProps, T } from './types';
4
4
  /**
5
5
  * Lexical Analyzer for footnote reference.
6
- *
7
- * A full footnote consists of a footnote label.
8
- *
9
- * Unlike the link label, the footnote label should be on the same line and it
10
- * begins with a left bracket ([) followed by a caret (^), and ends with the
11
- * first right bracket (]) that is not backslash-escaped. Between the caret of
12
- * right bracket, there must be at least one non-whitespace character.
13
- * Unescaped square bracket characters are not allowed inside the opening creat
14
- * and closing square bracket of footnote labels. A footnote label can have at
15
- * most 999 characters inside the caret and right bracket.
16
- *
17
6
  * @see https://github.com/syntax-tree/mdast#footnotereference
18
7
  * @see https://github.github.com/gfm/#link-label
19
8
  */
20
- export declare class FootnoteReferenceTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
9
+ export declare class FootnoteReferenceTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode, IThis> implements IInlineTokenizer<T, IDelimiter, IToken, INode, IThis> {
21
10
  constructor(props?: ITokenizerProps);
22
- readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
23
- readonly parse: IParseInlineHookCreator<T, IToken, INode>;
11
+ readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
12
+ readonly parse: IParseInlineHookCreator<T, IToken, INode, IThis>;
24
13
  }
@@ -1,5 +1,5 @@
1
1
  import type { FootnoteReferenceType, IFootnoteReference, IYastAssociation } from '@yozora/ast';
2
- import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
2
+ import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, ITokenizer, IYastTokenDelimiter } from '@yozora/core-tokenizer';
3
3
  export declare const uniqueName = "@yozora/tokenizer-footnote-reference";
4
4
  export declare type T = FootnoteReferenceType;
5
5
  export declare type INode = IFootnoteReference;
@@ -8,4 +8,5 @@ export interface IToken extends IPartialYastInlineToken<T>, IYastAssociation {
8
8
  export interface IDelimiter extends IYastTokenDelimiter {
9
9
  type: 'full';
10
10
  }
11
+ export declare type IThis = ITokenizer;
11
12
  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": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.1",
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": "^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"
38
+ "@yozora/ast": "^2.0.0-alpha.1",
39
+ "@yozora/character": "^2.0.0-alpha.1",
40
+ "@yozora/core-tokenizer": "^2.0.0-alpha.1",
41
+ "@yozora/tokenizer-footnote-definition": "^2.0.0-alpha.1"
42
42
  },
43
- "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
43
+ "gitHead": "86202e1d2b03ccfc2ab030517d9d314f7aee7666"
44
44
  }