@yozora/tokenizer-image 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
@@ -7,8 +7,6 @@ var character = require('@yozora/character');
7
7
  var coreTokenizer = require('@yozora/core-tokenizer');
8
8
  var tokenizerLink = require('@yozora/tokenizer-link');
9
9
 
10
- const uniqueName = '@yozora/tokenizer-image';
11
-
12
10
  function calcImageAlt(nodes) {
13
11
  return nodes
14
12
  .map((o) => {
@@ -23,6 +21,8 @@ function calcImageAlt(nodes) {
23
21
  .join('');
24
22
  }
25
23
 
24
+ const uniqueName = '@yozora/tokenizer-image';
25
+
26
26
  class ImageTokenizer extends coreTokenizer.BaseInlineTokenizer {
27
27
  constructor(props = {}) {
28
28
  var _a, _b;
@@ -30,110 +30,120 @@ class ImageTokenizer extends coreTokenizer.BaseInlineTokenizer {
30
30
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
31
31
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.LINKS,
32
32
  });
33
- }
34
- _findDelimiter(startIndex, endIndex, nodePoints, api) {
35
- const blockEndIndex = api.getBlockEndIndex();
36
- for (let i = startIndex; i < endIndex; ++i) {
37
- const c = nodePoints[i].codePoint;
38
- switch (c) {
39
- case character.AsciiCodePoint.BACKSLASH:
40
- i += 1;
41
- break;
42
- case character.AsciiCodePoint.EXCLAMATION_MARK: {
43
- if (i + 1 < endIndex &&
44
- nodePoints[i + 1].codePoint === character.AsciiCodePoint.OPEN_BRACKET) {
45
- return {
46
- type: 'opener',
47
- startIndex: i,
48
- endIndex: i + 2,
49
- };
33
+ this.match = api => {
34
+ return {
35
+ findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
36
+ isDelimiterPair,
37
+ processDelimiterPair,
38
+ };
39
+ function _findDelimiter(startIndex, endIndex) {
40
+ const nodePoints = api.getNodePoints();
41
+ const blockEndIndex = api.getBlockEndIndex();
42
+ for (let i = startIndex; i < endIndex; ++i) {
43
+ const c = nodePoints[i].codePoint;
44
+ switch (c) {
45
+ case character.AsciiCodePoint.BACKSLASH:
46
+ i += 1;
47
+ break;
48
+ case character.AsciiCodePoint.EXCLAMATION_MARK: {
49
+ if (i + 1 < endIndex && nodePoints[i + 1].codePoint === character.AsciiCodePoint.OPEN_BRACKET) {
50
+ return {
51
+ type: 'opener',
52
+ startIndex: i,
53
+ endIndex: i + 2,
54
+ };
55
+ }
56
+ break;
57
+ }
58
+ case character.AsciiCodePoint.CLOSE_BRACKET: {
59
+ if (i + 1 >= endIndex ||
60
+ nodePoints[i + 1].codePoint !== character.AsciiCodePoint.OPEN_PARENTHESIS) {
61
+ break;
62
+ }
63
+ const destinationStartIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, i + 2, blockEndIndex);
64
+ const destinationEndIndex = tokenizerLink.eatLinkDestination(nodePoints, destinationStartIndex, blockEndIndex);
65
+ if (destinationEndIndex < 0)
66
+ break;
67
+ const titleStartIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, destinationEndIndex, blockEndIndex);
68
+ const titleEndIndex = tokenizerLink.eatLinkTitle(nodePoints, titleStartIndex, blockEndIndex);
69
+ if (titleEndIndex < 0)
70
+ break;
71
+ const _startIndex = i;
72
+ const _endIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, titleEndIndex, blockEndIndex) + 1;
73
+ if (_endIndex > blockEndIndex ||
74
+ nodePoints[_endIndex - 1].codePoint !== character.AsciiCodePoint.CLOSE_PARENTHESIS) {
75
+ break;
76
+ }
77
+ return {
78
+ type: 'closer',
79
+ startIndex: _startIndex,
80
+ endIndex: _endIndex,
81
+ destinationContent: destinationStartIndex < destinationEndIndex
82
+ ? {
83
+ startIndex: destinationStartIndex,
84
+ endIndex: destinationEndIndex,
85
+ }
86
+ : undefined,
87
+ titleContent: titleStartIndex < titleEndIndex
88
+ ? { startIndex: titleStartIndex, endIndex: titleEndIndex }
89
+ : undefined,
90
+ };
91
+ }
50
92
  }
51
- break;
52
93
  }
53
- case character.AsciiCodePoint.CLOSE_BRACKET: {
54
- if (i + 1 >= endIndex ||
55
- nodePoints[i + 1].codePoint !== character.AsciiCodePoint.OPEN_PARENTHESIS) {
56
- break;
57
- }
58
- const destinationStartIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, i + 2, blockEndIndex);
59
- const destinationEndIndex = tokenizerLink.eatLinkDestination(nodePoints, destinationStartIndex, blockEndIndex);
60
- if (destinationEndIndex < 0)
61
- break;
62
- const titleStartIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, destinationEndIndex, blockEndIndex);
63
- const titleEndIndex = tokenizerLink.eatLinkTitle(nodePoints, titleStartIndex, blockEndIndex);
64
- if (titleEndIndex < 0)
65
- break;
66
- const _startIndex = i;
67
- const _endIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, titleEndIndex, blockEndIndex) + 1;
68
- if (_endIndex > blockEndIndex ||
69
- nodePoints[_endIndex - 1].codePoint !==
70
- character.AsciiCodePoint.CLOSE_PARENTHESIS) {
71
- break;
72
- }
73
- return {
74
- type: 'closer',
75
- startIndex: _startIndex,
76
- endIndex: _endIndex,
77
- destinationContent: destinationStartIndex < destinationEndIndex
78
- ? {
79
- startIndex: destinationStartIndex,
80
- endIndex: destinationEndIndex,
81
- }
82
- : undefined,
83
- titleContent: titleStartIndex < titleEndIndex
84
- ? { startIndex: titleStartIndex, endIndex: titleEndIndex }
85
- : undefined,
86
- };
94
+ return null;
95
+ }
96
+ function isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
97
+ const nodePoints = api.getNodePoints();
98
+ const balancedBracketsStatus = tokenizerLink.checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
99
+ switch (balancedBracketsStatus) {
100
+ case -1:
101
+ return { paired: false, opener: false, closer: true };
102
+ case 0:
103
+ return { paired: true };
104
+ case 1:
105
+ return { paired: false, opener: true, closer: false };
87
106
  }
88
107
  }
89
- }
90
- return null;
91
- }
92
- isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, nodePoints) {
93
- const balancedBracketsStatus = tokenizerLink.checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
94
- switch (balancedBracketsStatus) {
95
- case -1:
96
- return { paired: false, opener: false, closer: true };
97
- case 0:
98
- return { paired: true };
99
- case 1:
100
- return { paired: false, opener: true, closer: false };
101
- }
102
- }
103
- processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, nodePoints, api) {
104
- const token = {
105
- nodeType: ast.ImageType,
106
- startIndex: openerDelimiter.startIndex,
107
- endIndex: closerDelimiter.endIndex,
108
- destinationContent: closerDelimiter.destinationContent,
109
- titleContent: closerDelimiter.titleContent,
110
- children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex, nodePoints),
111
- };
112
- return { tokens: [token] };
113
- }
114
- processToken(token, children, nodePoints) {
115
- let url = '';
116
- if (token.destinationContent != null) {
117
- let { startIndex, endIndex } = token.destinationContent;
118
- if (nodePoints[startIndex].codePoint === character.AsciiCodePoint.OPEN_ANGLE) {
119
- startIndex += 1;
120
- endIndex -= 1;
108
+ function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
109
+ const token = {
110
+ nodeType: ast.ImageType,
111
+ startIndex: openerDelimiter.startIndex,
112
+ endIndex: closerDelimiter.endIndex,
113
+ destinationContent: closerDelimiter.destinationContent,
114
+ titleContent: closerDelimiter.titleContent,
115
+ children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex),
116
+ };
117
+ return { tokens: [token] };
121
118
  }
122
- const destination = character.calcEscapedStringFromNodePoints(nodePoints, startIndex, endIndex, true);
123
- url = coreTokenizer.encodeLinkDestination(destination);
124
- }
125
- const alt = calcImageAlt(children || []);
126
- let title;
127
- if (token.titleContent != null) {
128
- const { startIndex, endIndex } = token.titleContent;
129
- title = character.calcEscapedStringFromNodePoints(nodePoints, startIndex + 1, endIndex - 1);
130
- }
131
- const result = { type: ast.ImageType, url, alt, title };
132
- return result;
119
+ };
120
+ this.parse = api => ({
121
+ parse: (token, children) => {
122
+ const nodePoints = api.getNodePoints();
123
+ let url = '';
124
+ if (token.destinationContent != null) {
125
+ let { startIndex, endIndex } = token.destinationContent;
126
+ if (nodePoints[startIndex].codePoint === character.AsciiCodePoint.OPEN_ANGLE) {
127
+ startIndex += 1;
128
+ endIndex -= 1;
129
+ }
130
+ const destination = character.calcEscapedStringFromNodePoints(nodePoints, startIndex, endIndex, true);
131
+ url = coreTokenizer.encodeLinkDestination(destination);
132
+ }
133
+ const alt = calcImageAlt(children);
134
+ let title;
135
+ if (token.titleContent != null) {
136
+ const { startIndex, endIndex } = token.titleContent;
137
+ title = character.calcEscapedStringFromNodePoints(nodePoints, startIndex + 1, endIndex - 1);
138
+ }
139
+ const result = { type: ast.ImageType, url, alt, title };
140
+ return result;
141
+ },
142
+ });
133
143
  }
134
144
  }
135
145
 
136
146
  exports.ImageTokenizer = ImageTokenizer;
137
147
  exports.ImageTokenizerName = uniqueName;
138
148
  exports.calcImageAlt = calcImageAlt;
139
- exports['default'] = ImageTokenizer;
149
+ exports["default"] = ImageTokenizer;
package/lib/esm/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import { ImageType } from '@yozora/ast';
2
2
  import { AsciiCodePoint, calcEscapedStringFromNodePoints } from '@yozora/character';
3
- import { BaseInlineTokenizer, TokenizerPriority, eatOptionalWhitespaces, encodeLinkDestination } from '@yozora/core-tokenizer';
3
+ import { BaseInlineTokenizer, TokenizerPriority, genFindDelimiter, eatOptionalWhitespaces, encodeLinkDestination } from '@yozora/core-tokenizer';
4
4
  import { eatLinkDestination, eatLinkTitle, checkBalancedBracketsStatus } from '@yozora/tokenizer-link';
5
5
 
6
- const uniqueName = '@yozora/tokenizer-image';
7
-
8
6
  function calcImageAlt(nodes) {
9
7
  return nodes
10
8
  .map((o) => {
@@ -19,6 +17,8 @@ function calcImageAlt(nodes) {
19
17
  .join('');
20
18
  }
21
19
 
20
+ const uniqueName = '@yozora/tokenizer-image';
21
+
22
22
  class ImageTokenizer extends BaseInlineTokenizer {
23
23
  constructor(props = {}) {
24
24
  var _a, _b;
@@ -26,106 +26,116 @@ class ImageTokenizer extends BaseInlineTokenizer {
26
26
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
27
27
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.LINKS,
28
28
  });
29
- }
30
- _findDelimiter(startIndex, endIndex, nodePoints, api) {
31
- const blockEndIndex = api.getBlockEndIndex();
32
- for (let i = startIndex; i < endIndex; ++i) {
33
- const c = nodePoints[i].codePoint;
34
- switch (c) {
35
- case AsciiCodePoint.BACKSLASH:
36
- i += 1;
37
- break;
38
- case AsciiCodePoint.EXCLAMATION_MARK: {
39
- if (i + 1 < endIndex &&
40
- nodePoints[i + 1].codePoint === AsciiCodePoint.OPEN_BRACKET) {
41
- return {
42
- type: 'opener',
43
- startIndex: i,
44
- endIndex: i + 2,
45
- };
29
+ this.match = api => {
30
+ return {
31
+ findDelimiter: () => genFindDelimiter(_findDelimiter),
32
+ isDelimiterPair,
33
+ processDelimiterPair,
34
+ };
35
+ function _findDelimiter(startIndex, endIndex) {
36
+ const nodePoints = api.getNodePoints();
37
+ const blockEndIndex = api.getBlockEndIndex();
38
+ for (let i = startIndex; i < endIndex; ++i) {
39
+ const c = nodePoints[i].codePoint;
40
+ switch (c) {
41
+ case AsciiCodePoint.BACKSLASH:
42
+ i += 1;
43
+ break;
44
+ case AsciiCodePoint.EXCLAMATION_MARK: {
45
+ if (i + 1 < endIndex && nodePoints[i + 1].codePoint === AsciiCodePoint.OPEN_BRACKET) {
46
+ return {
47
+ type: 'opener',
48
+ startIndex: i,
49
+ endIndex: i + 2,
50
+ };
51
+ }
52
+ break;
53
+ }
54
+ case AsciiCodePoint.CLOSE_BRACKET: {
55
+ if (i + 1 >= endIndex ||
56
+ nodePoints[i + 1].codePoint !== AsciiCodePoint.OPEN_PARENTHESIS) {
57
+ break;
58
+ }
59
+ const destinationStartIndex = eatOptionalWhitespaces(nodePoints, i + 2, blockEndIndex);
60
+ const destinationEndIndex = eatLinkDestination(nodePoints, destinationStartIndex, blockEndIndex);
61
+ if (destinationEndIndex < 0)
62
+ break;
63
+ const titleStartIndex = eatOptionalWhitespaces(nodePoints, destinationEndIndex, blockEndIndex);
64
+ const titleEndIndex = eatLinkTitle(nodePoints, titleStartIndex, blockEndIndex);
65
+ if (titleEndIndex < 0)
66
+ break;
67
+ const _startIndex = i;
68
+ const _endIndex = eatOptionalWhitespaces(nodePoints, titleEndIndex, blockEndIndex) + 1;
69
+ if (_endIndex > blockEndIndex ||
70
+ nodePoints[_endIndex - 1].codePoint !== AsciiCodePoint.CLOSE_PARENTHESIS) {
71
+ break;
72
+ }
73
+ return {
74
+ type: 'closer',
75
+ startIndex: _startIndex,
76
+ endIndex: _endIndex,
77
+ destinationContent: destinationStartIndex < destinationEndIndex
78
+ ? {
79
+ startIndex: destinationStartIndex,
80
+ endIndex: destinationEndIndex,
81
+ }
82
+ : undefined,
83
+ titleContent: titleStartIndex < titleEndIndex
84
+ ? { startIndex: titleStartIndex, endIndex: titleEndIndex }
85
+ : undefined,
86
+ };
87
+ }
46
88
  }
47
- break;
48
89
  }
49
- case AsciiCodePoint.CLOSE_BRACKET: {
50
- if (i + 1 >= endIndex ||
51
- nodePoints[i + 1].codePoint !== AsciiCodePoint.OPEN_PARENTHESIS) {
52
- break;
53
- }
54
- const destinationStartIndex = eatOptionalWhitespaces(nodePoints, i + 2, blockEndIndex);
55
- const destinationEndIndex = eatLinkDestination(nodePoints, destinationStartIndex, blockEndIndex);
56
- if (destinationEndIndex < 0)
57
- break;
58
- const titleStartIndex = eatOptionalWhitespaces(nodePoints, destinationEndIndex, blockEndIndex);
59
- const titleEndIndex = eatLinkTitle(nodePoints, titleStartIndex, blockEndIndex);
60
- if (titleEndIndex < 0)
61
- break;
62
- const _startIndex = i;
63
- const _endIndex = eatOptionalWhitespaces(nodePoints, titleEndIndex, blockEndIndex) + 1;
64
- if (_endIndex > blockEndIndex ||
65
- nodePoints[_endIndex - 1].codePoint !==
66
- AsciiCodePoint.CLOSE_PARENTHESIS) {
67
- break;
68
- }
69
- return {
70
- type: 'closer',
71
- startIndex: _startIndex,
72
- endIndex: _endIndex,
73
- destinationContent: destinationStartIndex < destinationEndIndex
74
- ? {
75
- startIndex: destinationStartIndex,
76
- endIndex: destinationEndIndex,
77
- }
78
- : undefined,
79
- titleContent: titleStartIndex < titleEndIndex
80
- ? { startIndex: titleStartIndex, endIndex: titleEndIndex }
81
- : undefined,
82
- };
90
+ return null;
91
+ }
92
+ function isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
93
+ const nodePoints = api.getNodePoints();
94
+ const balancedBracketsStatus = checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
95
+ switch (balancedBracketsStatus) {
96
+ case -1:
97
+ return { paired: false, opener: false, closer: true };
98
+ case 0:
99
+ return { paired: true };
100
+ case 1:
101
+ return { paired: false, opener: true, closer: false };
83
102
  }
84
103
  }
85
- }
86
- return null;
87
- }
88
- isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, nodePoints) {
89
- const balancedBracketsStatus = checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
90
- switch (balancedBracketsStatus) {
91
- case -1:
92
- return { paired: false, opener: false, closer: true };
93
- case 0:
94
- return { paired: true };
95
- case 1:
96
- return { paired: false, opener: true, closer: false };
97
- }
98
- }
99
- processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, nodePoints, api) {
100
- const token = {
101
- nodeType: ImageType,
102
- startIndex: openerDelimiter.startIndex,
103
- endIndex: closerDelimiter.endIndex,
104
- destinationContent: closerDelimiter.destinationContent,
105
- titleContent: closerDelimiter.titleContent,
106
- children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex, nodePoints),
107
- };
108
- return { tokens: [token] };
109
- }
110
- processToken(token, children, nodePoints) {
111
- let url = '';
112
- if (token.destinationContent != null) {
113
- let { startIndex, endIndex } = token.destinationContent;
114
- if (nodePoints[startIndex].codePoint === AsciiCodePoint.OPEN_ANGLE) {
115
- startIndex += 1;
116
- endIndex -= 1;
104
+ function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
105
+ const token = {
106
+ nodeType: ImageType,
107
+ startIndex: openerDelimiter.startIndex,
108
+ endIndex: closerDelimiter.endIndex,
109
+ destinationContent: closerDelimiter.destinationContent,
110
+ titleContent: closerDelimiter.titleContent,
111
+ children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex),
112
+ };
113
+ return { tokens: [token] };
117
114
  }
118
- const destination = calcEscapedStringFromNodePoints(nodePoints, startIndex, endIndex, true);
119
- url = encodeLinkDestination(destination);
120
- }
121
- const alt = calcImageAlt(children || []);
122
- let title;
123
- if (token.titleContent != null) {
124
- const { startIndex, endIndex } = token.titleContent;
125
- title = calcEscapedStringFromNodePoints(nodePoints, startIndex + 1, endIndex - 1);
126
- }
127
- const result = { type: ImageType, url, alt, title };
128
- return result;
115
+ };
116
+ this.parse = api => ({
117
+ parse: (token, children) => {
118
+ const nodePoints = api.getNodePoints();
119
+ let url = '';
120
+ if (token.destinationContent != null) {
121
+ let { startIndex, endIndex } = token.destinationContent;
122
+ if (nodePoints[startIndex].codePoint === AsciiCodePoint.OPEN_ANGLE) {
123
+ startIndex += 1;
124
+ endIndex -= 1;
125
+ }
126
+ const destination = calcEscapedStringFromNodePoints(nodePoints, startIndex, endIndex, true);
127
+ url = encodeLinkDestination(destination);
128
+ }
129
+ const alt = calcImageAlt(children);
130
+ let title;
131
+ if (token.titleContent != null) {
132
+ const { startIndex, endIndex } = token.titleContent;
133
+ title = calcEscapedStringFromNodePoints(nodePoints, startIndex + 1, endIndex - 1);
134
+ }
135
+ const result = { type: ImageType, url, alt, title };
136
+ return result;
137
+ },
138
+ });
129
139
  }
130
140
  }
131
141
 
@@ -1,6 +1,4 @@
1
- import { ImageTokenizer } from './tokenizer';
2
1
  export * from './util';
3
- export { ImageTokenizer } from './tokenizer';
2
+ export { ImageTokenizer, ImageTokenizer as default } from './tokenizer';
4
3
  export { uniqueName as ImageTokenizerName } from './types';
5
- export type { Token as ImageToken, TokenizerProps as ImageTokenizerProps, } from './types';
6
- export default ImageTokenizer;
4
+ export type { IToken as IImageToken, ITokenizerProps as IImageTokenizerProps } from './types';
@@ -1,8 +1,6 @@
1
- import type { YastNode } from '@yozora/ast';
2
- import type { NodePoint } from '@yozora/character';
3
- import type { MatchInlinePhaseApi, ResultOfIsDelimiterPair, ResultOfProcessDelimiterPair, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook, YastInlineToken } from '@yozora/core-tokenizer';
1
+ import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
4
2
  import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
5
- import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
3
+ import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
6
4
  /**
7
5
  * Lexical Analyzer for InlineImage.
8
6
  *
@@ -32,38 +30,8 @@ import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
32
30
  * @see https://github.com/syntax-tree/mdast#image
33
31
  * @see https://github.github.com/gfm/#images
34
32
  */
35
- export declare class ImageTokenizer extends BaseInlineTokenizer<Delimiter> implements Tokenizer, TokenizerMatchInlineHook<T, Delimiter, Token>, TokenizerParseInlineHook<T, Token, Node> {
36
- constructor(props?: TokenizerProps);
37
- /**
38
- * Images can contains Images, so implement an algorithm similar to bracket
39
- * matching, pushing all opener delimiters onto the stack
40
- *
41
- * The rules for this are the same as for link text, except that
42
- * (a) an image description starts with '![' rather than '[', and
43
- * (b) an image description may contain links. An image description has
44
- * inline elements as its contents. When an image is rendered to HTML,
45
- * this is standardly used as the image’s alt attribute
46
- *
47
- * @see https://github.github.com/gfm/#inline-link
48
- * @see https://github.github.com/gfm/#example-582
49
- *
50
- * @override
51
- * @see TokenizerMatchInlineHook
52
- */
53
- protected _findDelimiter(startIndex: number, endIndex: number, nodePoints: ReadonlyArray<NodePoint>, api: Readonly<MatchInlinePhaseApi>): Delimiter | null;
54
- /**
55
- * @override
56
- * @see TokenizerMatchInlineHook
57
- */
58
- isDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, nodePoints: ReadonlyArray<NodePoint>): ResultOfIsDelimiterPair;
59
- /**
60
- * @override
61
- * @see TokenizerMatchInlineHook
62
- */
63
- processDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, nodePoints: ReadonlyArray<NodePoint>, api: Readonly<MatchInlinePhaseApi>): ResultOfProcessDelimiterPair<T, Token, Delimiter>;
64
- /**
65
- * @override
66
- * @see TokenizerParseInlineHook
67
- */
68
- processToken(token: Token, children: YastNode[] | undefined, nodePoints: ReadonlyArray<NodePoint>): Node;
33
+ export declare class ImageTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
34
+ constructor(props?: ITokenizerProps);
35
+ readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
36
+ readonly parse: IParseInlineHookCreator<T, IToken, INode>;
69
37
  }
@@ -1,34 +1,34 @@
1
- import type { Image, ImageType } from '@yozora/ast';
2
- import type { NodeInterval } from '@yozora/character';
3
- import type { BaseInlineTokenizerProps, PartialYastInlineToken, YastTokenDelimiter } from '@yozora/core-tokenizer';
1
+ import type { IImage, ImageType } from '@yozora/ast';
2
+ import type { INodeInterval } from '@yozora/character';
3
+ import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
4
4
  export declare type T = ImageType;
5
- export declare type Node = Image;
5
+ export declare type INode = IImage;
6
6
  export declare const uniqueName = "@yozora/tokenizer-image";
7
7
  /**
8
8
  * An image token.
9
9
  */
10
- export interface Token extends PartialYastInlineToken<T> {
10
+ export interface IToken extends IPartialYastInlineToken<T> {
11
11
  /**
12
12
  * Link destination interval.
13
13
  */
14
- destinationContent?: NodeInterval;
14
+ destinationContent?: INodeInterval;
15
15
  /**
16
16
  * Link title interval.
17
17
  */
18
- titleContent?: NodeInterval;
18
+ titleContent?: INodeInterval;
19
19
  }
20
- export interface Delimiter extends YastTokenDelimiter {
20
+ export interface IDelimiter extends IYastTokenDelimiter {
21
21
  /**
22
- * Delimiter type.
22
+ * IDelimiter type.
23
23
  */
24
24
  type: 'opener' | 'closer';
25
25
  /**
26
26
  * link destination
27
27
  */
28
- destinationContent?: NodeInterval;
28
+ destinationContent?: INodeInterval;
29
29
  /**
30
30
  * link title
31
31
  */
32
- titleContent?: NodeInterval;
32
+ titleContent?: INodeInterval;
33
33
  }
34
- export declare type TokenizerProps = Partial<BaseInlineTokenizerProps>;
34
+ export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
@@ -1,8 +1,8 @@
1
- import type { YastNode } from '@yozora/ast';
1
+ import type { IYastNode } from '@yozora/ast';
2
2
  /**
3
3
  * calc alt
4
4
  * An image description has inline elements as its contents. When an image
5
5
  * is rendered to HTML, this is standardly used as the image’s alt attribute
6
6
  * @see https://github.github.com/gfm/#example-582
7
7
  */
8
- export declare function calcImageAlt(nodes: ReadonlyArray<YastNode>): string;
8
+ export declare function calcImageAlt(nodes: ReadonlyArray<IYastNode>): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-image",
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-link": "^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-link": "^2.0.0-alpha.0"
42
42
  },
43
- "gitHead": "86da40e50d2fe9acace68695288e15e012e6cd0d"
43
+ "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
44
44
  }