@yozora/tokenizer-image 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 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,113 +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, api) {
35
- const nodePoints = api.getNodePoints();
36
- const blockEndIndex = api.getBlockEndIndex();
37
- for (let i = startIndex; i < endIndex; ++i) {
38
- const c = nodePoints[i].codePoint;
39
- switch (c) {
40
- case character.AsciiCodePoint.BACKSLASH:
41
- i += 1;
42
- break;
43
- case character.AsciiCodePoint.EXCLAMATION_MARK: {
44
- if (i + 1 < endIndex &&
45
- nodePoints[i + 1].codePoint === character.AsciiCodePoint.OPEN_BRACKET) {
46
- return {
47
- type: 'opener',
48
- startIndex: i,
49
- endIndex: i + 2,
50
- };
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
+ }
51
92
  }
52
- break;
53
93
  }
54
- case character.AsciiCodePoint.CLOSE_BRACKET: {
55
- if (i + 1 >= endIndex ||
56
- nodePoints[i + 1].codePoint !== character.AsciiCodePoint.OPEN_PARENTHESIS) {
57
- break;
58
- }
59
- const destinationStartIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, i + 2, blockEndIndex);
60
- const destinationEndIndex = tokenizerLink.eatLinkDestination(nodePoints, destinationStartIndex, blockEndIndex);
61
- if (destinationEndIndex < 0)
62
- break;
63
- const titleStartIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, destinationEndIndex, blockEndIndex);
64
- const titleEndIndex = tokenizerLink.eatLinkTitle(nodePoints, titleStartIndex, blockEndIndex);
65
- if (titleEndIndex < 0)
66
- break;
67
- const _startIndex = i;
68
- const _endIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, titleEndIndex, blockEndIndex) + 1;
69
- if (_endIndex > blockEndIndex ||
70
- nodePoints[_endIndex - 1].codePoint !==
71
- character.AsciiCodePoint.CLOSE_PARENTHESIS) {
72
- break;
73
- }
74
- return {
75
- type: 'closer',
76
- startIndex: _startIndex,
77
- endIndex: _endIndex,
78
- destinationContent: destinationStartIndex < destinationEndIndex
79
- ? {
80
- startIndex: destinationStartIndex,
81
- endIndex: destinationEndIndex,
82
- }
83
- : undefined,
84
- titleContent: titleStartIndex < titleEndIndex
85
- ? { startIndex: titleStartIndex, endIndex: titleEndIndex }
86
- : undefined,
87
- };
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 };
88
106
  }
89
107
  }
90
- }
91
- return null;
92
- }
93
- isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
94
- const nodePoints = api.getNodePoints();
95
- const balancedBracketsStatus = tokenizerLink.checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
96
- switch (balancedBracketsStatus) {
97
- case -1:
98
- return { paired: false, opener: false, closer: true };
99
- case 0:
100
- return { paired: true };
101
- case 1:
102
- return { paired: false, opener: true, closer: false };
103
- }
104
- }
105
- processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
106
- const token = {
107
- nodeType: ast.ImageType,
108
- startIndex: openerDelimiter.startIndex,
109
- endIndex: closerDelimiter.endIndex,
110
- destinationContent: closerDelimiter.destinationContent,
111
- titleContent: closerDelimiter.titleContent,
112
- children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex),
113
- };
114
- return { tokens: [token] };
115
- }
116
- parseInline(token, children, api) {
117
- const nodePoints = api.getNodePoints();
118
- let url = '';
119
- if (token.destinationContent != null) {
120
- let { startIndex, endIndex } = token.destinationContent;
121
- if (nodePoints[startIndex].codePoint === character.AsciiCodePoint.OPEN_ANGLE) {
122
- startIndex += 1;
123
- 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] };
124
118
  }
125
- const destination = character.calcEscapedStringFromNodePoints(nodePoints, startIndex, endIndex, true);
126
- url = coreTokenizer.encodeLinkDestination(destination);
127
- }
128
- const alt = calcImageAlt(children);
129
- let title;
130
- if (token.titleContent != null) {
131
- const { startIndex, endIndex } = token.titleContent;
132
- title = character.calcEscapedStringFromNodePoints(nodePoints, startIndex + 1, endIndex - 1);
133
- }
134
- const result = { type: ast.ImageType, url, alt, title };
135
- 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
+ });
136
143
  }
137
144
  }
138
145
 
139
146
  exports.ImageTokenizer = ImageTokenizer;
140
147
  exports.ImageTokenizerName = uniqueName;
141
148
  exports.calcImageAlt = calcImageAlt;
142
- 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,109 +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, api) {
31
- const nodePoints = api.getNodePoints();
32
- const blockEndIndex = api.getBlockEndIndex();
33
- for (let i = startIndex; i < endIndex; ++i) {
34
- const c = nodePoints[i].codePoint;
35
- switch (c) {
36
- case AsciiCodePoint.BACKSLASH:
37
- i += 1;
38
- break;
39
- case AsciiCodePoint.EXCLAMATION_MARK: {
40
- if (i + 1 < endIndex &&
41
- nodePoints[i + 1].codePoint === AsciiCodePoint.OPEN_BRACKET) {
42
- return {
43
- type: 'opener',
44
- startIndex: i,
45
- endIndex: i + 2,
46
- };
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
+ }
47
88
  }
48
- break;
49
89
  }
50
- case AsciiCodePoint.CLOSE_BRACKET: {
51
- if (i + 1 >= endIndex ||
52
- nodePoints[i + 1].codePoint !== AsciiCodePoint.OPEN_PARENTHESIS) {
53
- break;
54
- }
55
- const destinationStartIndex = eatOptionalWhitespaces(nodePoints, i + 2, blockEndIndex);
56
- const destinationEndIndex = eatLinkDestination(nodePoints, destinationStartIndex, blockEndIndex);
57
- if (destinationEndIndex < 0)
58
- break;
59
- const titleStartIndex = eatOptionalWhitespaces(nodePoints, destinationEndIndex, blockEndIndex);
60
- const titleEndIndex = eatLinkTitle(nodePoints, titleStartIndex, blockEndIndex);
61
- if (titleEndIndex < 0)
62
- break;
63
- const _startIndex = i;
64
- const _endIndex = eatOptionalWhitespaces(nodePoints, titleEndIndex, blockEndIndex) + 1;
65
- if (_endIndex > blockEndIndex ||
66
- nodePoints[_endIndex - 1].codePoint !==
67
- AsciiCodePoint.CLOSE_PARENTHESIS) {
68
- break;
69
- }
70
- return {
71
- type: 'closer',
72
- startIndex: _startIndex,
73
- endIndex: _endIndex,
74
- destinationContent: destinationStartIndex < destinationEndIndex
75
- ? {
76
- startIndex: destinationStartIndex,
77
- endIndex: destinationEndIndex,
78
- }
79
- : undefined,
80
- titleContent: titleStartIndex < titleEndIndex
81
- ? { startIndex: titleStartIndex, endIndex: titleEndIndex }
82
- : undefined,
83
- };
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 };
84
102
  }
85
103
  }
86
- }
87
- return null;
88
- }
89
- isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
90
- const nodePoints = api.getNodePoints();
91
- const balancedBracketsStatus = checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
92
- switch (balancedBracketsStatus) {
93
- case -1:
94
- return { paired: false, opener: false, closer: true };
95
- case 0:
96
- return { paired: true };
97
- case 1:
98
- return { paired: false, opener: true, closer: false };
99
- }
100
- }
101
- processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
102
- const token = {
103
- nodeType: ImageType,
104
- startIndex: openerDelimiter.startIndex,
105
- endIndex: closerDelimiter.endIndex,
106
- destinationContent: closerDelimiter.destinationContent,
107
- titleContent: closerDelimiter.titleContent,
108
- children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex),
109
- };
110
- return { tokens: [token] };
111
- }
112
- parseInline(token, children, api) {
113
- const nodePoints = api.getNodePoints();
114
- let url = '';
115
- if (token.destinationContent != null) {
116
- let { startIndex, endIndex } = token.destinationContent;
117
- if (nodePoints[startIndex].codePoint === AsciiCodePoint.OPEN_ANGLE) {
118
- startIndex += 1;
119
- 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] };
120
114
  }
121
- const destination = calcEscapedStringFromNodePoints(nodePoints, startIndex, endIndex, true);
122
- url = encodeLinkDestination(destination);
123
- }
124
- const alt = calcImageAlt(children);
125
- let title;
126
- if (token.titleContent != null) {
127
- const { startIndex, endIndex } = token.titleContent;
128
- title = calcEscapedStringFromNodePoints(nodePoints, startIndex + 1, endIndex - 1);
129
- }
130
- const result = { type: ImageType, url, alt, title };
131
- 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
+ });
132
139
  }
133
140
  }
134
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,7 +1,6 @@
1
- import type { YastNode } from '@yozora/ast';
2
- import type { MatchInlinePhaseApi, ParseInlinePhaseApi, ResultOfIsDelimiterPair, ResultOfProcessDelimiterPair, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook, YastInlineToken } 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 InlineImage.
7
6
  *
@@ -31,38 +30,8 @@ import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
31
30
  * @see https://github.com/syntax-tree/mdast#image
32
31
  * @see https://github.github.com/gfm/#images
33
32
  */
34
- export declare class ImageTokenizer extends BaseInlineTokenizer<Delimiter> implements Tokenizer, TokenizerMatchInlineHook<T, Delimiter, Token>, TokenizerParseInlineHook<T, Token, Node> {
35
- constructor(props?: TokenizerProps);
36
- /**
37
- * Images can contains Images, so implement an algorithm similar to bracket
38
- * matching, pushing all opener delimiters onto the stack
39
- *
40
- * The rules for this are the same as for link text, except that
41
- * (a) an image description starts with '![' rather than '[', and
42
- * (b) an image description may contain links. An image description has
43
- * inline elements as its contents. When an image is rendered to HTML,
44
- * this is standardly used as the image’s alt attribute
45
- *
46
- * @see https://github.github.com/gfm/#inline-link
47
- * @see https://github.github.com/gfm/#example-582
48
- *
49
- * @override
50
- * @see TokenizerMatchInlineHook
51
- */
52
- protected _findDelimiter(startIndex: number, endIndex: number, api: Readonly<MatchInlinePhaseApi>): Delimiter | null;
53
- /**
54
- * @override
55
- * @see TokenizerMatchInlineHook
56
- */
57
- isDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, api: Readonly<MatchInlinePhaseApi>): ResultOfIsDelimiterPair;
58
- /**
59
- * @override
60
- * @see TokenizerMatchInlineHook
61
- */
62
- processDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, api: Readonly<MatchInlinePhaseApi>): ResultOfProcessDelimiterPair<T, Token, Delimiter>;
63
- /**
64
- * @override
65
- * @see TokenizerParseInlineHook
66
- */
67
- parseInline(token: Token, children: YastNode[], api: Readonly<ParseInlinePhaseApi>): 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>;
68
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.3.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.3.0",
39
- "@yozora/character": "^1.3.0",
40
- "@yozora/core-tokenizer": "^1.3.0",
41
- "@yozora/tokenizer-link": "^1.3.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": "18c9b167004ad97718b2f94f25139f80598cbf7a"
43
+ "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
44
44
  }