@yozora/tokenizer-image 1.3.0 → 2.0.0-alpha.3
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 +4 -6
- package/lib/cjs/index.js +55 -37
- package/lib/esm/index.js +54 -38
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +30 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -61
- package/lib/types/types.d.ts +12 -11
- package/lib/types/util.d.ts +2 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -84,14 +84,14 @@ so you can use `YozoraParser` / `GfmExParser` / `GfmParser` directly.
|
|
|
84
84
|
registered in *YastParser* as a plugin-in before it can be used.
|
|
85
85
|
|
|
86
86
|
```typescript {4,9}
|
|
87
|
-
import {
|
|
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 ImageTokenizer from '@yozora/tokenizer-image'
|
|
91
91
|
|
|
92
|
-
const parser = new
|
|
93
|
-
.
|
|
94
|
-
.
|
|
92
|
+
const parser = new DefaultParser()
|
|
93
|
+
.useFallbackTokenizer(new ParagraphTokenizer())
|
|
94
|
+
.useFallbackTokenizer(new TextTokenizer())
|
|
95
95
|
.useTokenizer(new ImageTokenizer())
|
|
96
96
|
|
|
97
97
|
// parse source markdown content
|
|
@@ -223,7 +223,6 @@ Name | Type | Required | Default
|
|
|
223
223
|
[@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
|
|
224
224
|
[@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
|
|
225
225
|
[@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
|
|
226
|
-
[@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
|
|
227
226
|
[@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
|
|
228
227
|
[@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
|
|
229
228
|
[@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
|
|
@@ -283,7 +282,6 @@ Name | Type | Required | Default
|
|
|
283
282
|
[doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
|
|
284
283
|
[doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
|
|
285
284
|
[doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
|
|
286
|
-
[doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
|
|
287
285
|
[doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
|
|
288
286
|
[doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
|
|
289
287
|
[doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
|
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,15 +21,13 @@ function calcImageAlt(nodes) {
|
|
|
23
21
|
.join('');
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
_findDelimiter(startIndex, endIndex, api) {
|
|
24
|
+
const match = function (api) {
|
|
25
|
+
return {
|
|
26
|
+
findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
|
|
27
|
+
isDelimiterPair,
|
|
28
|
+
processDelimiterPair,
|
|
29
|
+
};
|
|
30
|
+
function _findDelimiter(startIndex, endIndex) {
|
|
35
31
|
const nodePoints = api.getNodePoints();
|
|
36
32
|
const blockEndIndex = api.getBlockEndIndex();
|
|
37
33
|
for (let i = startIndex; i < endIndex; ++i) {
|
|
@@ -41,8 +37,7 @@ class ImageTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
41
37
|
i += 1;
|
|
42
38
|
break;
|
|
43
39
|
case character.AsciiCodePoint.EXCLAMATION_MARK: {
|
|
44
|
-
if (i + 1 < endIndex &&
|
|
45
|
-
nodePoints[i + 1].codePoint === character.AsciiCodePoint.OPEN_BRACKET) {
|
|
40
|
+
if (i + 1 < endIndex && nodePoints[i + 1].codePoint === character.AsciiCodePoint.OPEN_BRACKET) {
|
|
46
41
|
return {
|
|
47
42
|
type: 'opener',
|
|
48
43
|
startIndex: i,
|
|
@@ -67,8 +62,7 @@ class ImageTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
67
62
|
const _startIndex = i;
|
|
68
63
|
const _endIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, titleEndIndex, blockEndIndex) + 1;
|
|
69
64
|
if (_endIndex > blockEndIndex ||
|
|
70
|
-
nodePoints[_endIndex - 1].codePoint !==
|
|
71
|
-
character.AsciiCodePoint.CLOSE_PARENTHESIS) {
|
|
65
|
+
nodePoints[_endIndex - 1].codePoint !== character.AsciiCodePoint.CLOSE_PARENTHESIS) {
|
|
72
66
|
break;
|
|
73
67
|
}
|
|
74
68
|
return {
|
|
@@ -90,7 +84,7 @@ class ImageTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
90
84
|
}
|
|
91
85
|
return null;
|
|
92
86
|
}
|
|
93
|
-
isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens
|
|
87
|
+
function isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
94
88
|
const nodePoints = api.getNodePoints();
|
|
95
89
|
const balancedBracketsStatus = tokenizerLink.checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
|
|
96
90
|
switch (balancedBracketsStatus) {
|
|
@@ -102,7 +96,7 @@ class ImageTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
102
96
|
return { paired: false, opener: true, closer: false };
|
|
103
97
|
}
|
|
104
98
|
}
|
|
105
|
-
processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens
|
|
99
|
+
function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
106
100
|
const token = {
|
|
107
101
|
nodeType: ast.ImageType,
|
|
108
102
|
startIndex: openerDelimiter.startIndex,
|
|
@@ -113,30 +107,54 @@ class ImageTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
113
107
|
};
|
|
114
108
|
return { tokens: [token] };
|
|
115
109
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const parse = function (api) {
|
|
113
|
+
return {
|
|
114
|
+
parse: tokens => tokens.map(token => {
|
|
115
|
+
const nodePoints = api.getNodePoints();
|
|
116
|
+
let url = '';
|
|
117
|
+
if (token.destinationContent != null) {
|
|
118
|
+
let { startIndex, endIndex } = token.destinationContent;
|
|
119
|
+
if (nodePoints[startIndex].codePoint === character.AsciiCodePoint.OPEN_ANGLE) {
|
|
120
|
+
startIndex += 1;
|
|
121
|
+
endIndex -= 1;
|
|
122
|
+
}
|
|
123
|
+
const destination = character.calcEscapedStringFromNodePoints(nodePoints, startIndex, endIndex, true);
|
|
124
|
+
url = coreTokenizer.encodeLinkDestination(destination);
|
|
124
125
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
const children = api.parseInlineTokens(token.children);
|
|
127
|
+
const alt = calcImageAlt(children);
|
|
128
|
+
let title;
|
|
129
|
+
if (token.titleContent != null) {
|
|
130
|
+
const { startIndex, endIndex } = token.titleContent;
|
|
131
|
+
title = character.calcEscapedStringFromNodePoints(nodePoints, startIndex + 1, endIndex - 1);
|
|
132
|
+
}
|
|
133
|
+
const node = api.shouldReservePosition
|
|
134
|
+
? { type: ast.ImageType, position: api.calcPosition(token), url, alt, title }
|
|
135
|
+
: { type: ast.ImageType, url, alt, title };
|
|
136
|
+
return node;
|
|
137
|
+
}),
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const uniqueName = '@yozora/tokenizer-image';
|
|
142
|
+
|
|
143
|
+
class ImageTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
144
|
+
constructor(props = {}) {
|
|
145
|
+
var _a, _b;
|
|
146
|
+
super({
|
|
147
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
148
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.LINKS,
|
|
149
|
+
});
|
|
150
|
+
this.match = match;
|
|
151
|
+
this.parse = parse;
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
154
|
|
|
139
155
|
exports.ImageTokenizer = ImageTokenizer;
|
|
140
156
|
exports.ImageTokenizerName = uniqueName;
|
|
141
157
|
exports.calcImageAlt = calcImageAlt;
|
|
142
|
-
exports[
|
|
158
|
+
exports["default"] = ImageTokenizer;
|
|
159
|
+
exports.imageMatch = match;
|
|
160
|
+
exports.imageParse = parse;
|
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 {
|
|
3
|
+
import { genFindDelimiter, eatOptionalWhitespaces, encodeLinkDestination, BaseInlineTokenizer, TokenizerPriority } 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,15 +17,13 @@ function calcImageAlt(nodes) {
|
|
|
19
17
|
.join('');
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
_findDelimiter(startIndex, endIndex, api) {
|
|
20
|
+
const match = function (api) {
|
|
21
|
+
return {
|
|
22
|
+
findDelimiter: () => genFindDelimiter(_findDelimiter),
|
|
23
|
+
isDelimiterPair,
|
|
24
|
+
processDelimiterPair,
|
|
25
|
+
};
|
|
26
|
+
function _findDelimiter(startIndex, endIndex) {
|
|
31
27
|
const nodePoints = api.getNodePoints();
|
|
32
28
|
const blockEndIndex = api.getBlockEndIndex();
|
|
33
29
|
for (let i = startIndex; i < endIndex; ++i) {
|
|
@@ -37,8 +33,7 @@ class ImageTokenizer extends BaseInlineTokenizer {
|
|
|
37
33
|
i += 1;
|
|
38
34
|
break;
|
|
39
35
|
case AsciiCodePoint.EXCLAMATION_MARK: {
|
|
40
|
-
if (i + 1 < endIndex &&
|
|
41
|
-
nodePoints[i + 1].codePoint === AsciiCodePoint.OPEN_BRACKET) {
|
|
36
|
+
if (i + 1 < endIndex && nodePoints[i + 1].codePoint === AsciiCodePoint.OPEN_BRACKET) {
|
|
42
37
|
return {
|
|
43
38
|
type: 'opener',
|
|
44
39
|
startIndex: i,
|
|
@@ -63,8 +58,7 @@ class ImageTokenizer extends BaseInlineTokenizer {
|
|
|
63
58
|
const _startIndex = i;
|
|
64
59
|
const _endIndex = eatOptionalWhitespaces(nodePoints, titleEndIndex, blockEndIndex) + 1;
|
|
65
60
|
if (_endIndex > blockEndIndex ||
|
|
66
|
-
nodePoints[_endIndex - 1].codePoint !==
|
|
67
|
-
AsciiCodePoint.CLOSE_PARENTHESIS) {
|
|
61
|
+
nodePoints[_endIndex - 1].codePoint !== AsciiCodePoint.CLOSE_PARENTHESIS) {
|
|
68
62
|
break;
|
|
69
63
|
}
|
|
70
64
|
return {
|
|
@@ -86,7 +80,7 @@ class ImageTokenizer extends BaseInlineTokenizer {
|
|
|
86
80
|
}
|
|
87
81
|
return null;
|
|
88
82
|
}
|
|
89
|
-
isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens
|
|
83
|
+
function isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
90
84
|
const nodePoints = api.getNodePoints();
|
|
91
85
|
const balancedBracketsStatus = checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
|
|
92
86
|
switch (balancedBracketsStatus) {
|
|
@@ -98,7 +92,7 @@ class ImageTokenizer extends BaseInlineTokenizer {
|
|
|
98
92
|
return { paired: false, opener: true, closer: false };
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
|
-
processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens
|
|
95
|
+
function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
102
96
|
const token = {
|
|
103
97
|
nodeType: ImageType,
|
|
104
98
|
startIndex: openerDelimiter.startIndex,
|
|
@@ -109,27 +103,49 @@ class ImageTokenizer extends BaseInlineTokenizer {
|
|
|
109
103
|
};
|
|
110
104
|
return { tokens: [token] };
|
|
111
105
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const parse = function (api) {
|
|
109
|
+
return {
|
|
110
|
+
parse: tokens => tokens.map(token => {
|
|
111
|
+
const nodePoints = api.getNodePoints();
|
|
112
|
+
let url = '';
|
|
113
|
+
if (token.destinationContent != null) {
|
|
114
|
+
let { startIndex, endIndex } = token.destinationContent;
|
|
115
|
+
if (nodePoints[startIndex].codePoint === AsciiCodePoint.OPEN_ANGLE) {
|
|
116
|
+
startIndex += 1;
|
|
117
|
+
endIndex -= 1;
|
|
118
|
+
}
|
|
119
|
+
const destination = calcEscapedStringFromNodePoints(nodePoints, startIndex, endIndex, true);
|
|
120
|
+
url = encodeLinkDestination(destination);
|
|
120
121
|
}
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
const children = api.parseInlineTokens(token.children);
|
|
123
|
+
const alt = calcImageAlt(children);
|
|
124
|
+
let title;
|
|
125
|
+
if (token.titleContent != null) {
|
|
126
|
+
const { startIndex, endIndex } = token.titleContent;
|
|
127
|
+
title = calcEscapedStringFromNodePoints(nodePoints, startIndex + 1, endIndex - 1);
|
|
128
|
+
}
|
|
129
|
+
const node = api.shouldReservePosition
|
|
130
|
+
? { type: ImageType, position: api.calcPosition(token), url, alt, title }
|
|
131
|
+
: { type: ImageType, url, alt, title };
|
|
132
|
+
return node;
|
|
133
|
+
}),
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const uniqueName = '@yozora/tokenizer-image';
|
|
138
|
+
|
|
139
|
+
class ImageTokenizer extends BaseInlineTokenizer {
|
|
140
|
+
constructor(props = {}) {
|
|
141
|
+
var _a, _b;
|
|
142
|
+
super({
|
|
143
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
144
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.LINKS,
|
|
145
|
+
});
|
|
146
|
+
this.match = match;
|
|
147
|
+
this.parse = parse;
|
|
132
148
|
}
|
|
133
149
|
}
|
|
134
150
|
|
|
135
|
-
export { ImageTokenizer, uniqueName as ImageTokenizerName, calcImageAlt, ImageTokenizer as default };
|
|
151
|
+
export { ImageTokenizer, uniqueName as ImageTokenizerName, calcImageAlt, ImageTokenizer as default, match as imageMatch, parse as imageParse };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ImageTokenizer } from './tokenizer';
|
|
2
1
|
export * from './util';
|
|
3
|
-
export {
|
|
2
|
+
export { match as imageMatch } from './match';
|
|
3
|
+
export { parse as imageParse } from './parse';
|
|
4
|
+
export { ImageTokenizer, ImageTokenizer as default } from './tokenizer';
|
|
4
5
|
export { uniqueName as ImageTokenizerName } from './types';
|
|
5
|
-
export type {
|
|
6
|
-
export default ImageTokenizer;
|
|
6
|
+
export type { IThis as IImageHookContext, IToken as IImageToken, ITokenizerProps as IImageTokenizerProps, } from './types';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IMatchInlineHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IDelimiter, IThis, IToken, T } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Syntax for images is like the syntax for links, with one difference.
|
|
5
|
+
* Instead of link text, we have an image description.
|
|
6
|
+
* The rules for this are the same as for link text, except that
|
|
7
|
+
*
|
|
8
|
+
* a) an image description starts with ''
|
|
23
|
+
* - '](url "title")'
|
|
24
|
+
* - '](<url>)'
|
|
25
|
+
* - '](<url> "title")'
|
|
26
|
+
*
|
|
27
|
+
* @see https://github.com/syntax-tree/mdast#image
|
|
28
|
+
* @see https://github.github.com/gfm/#images
|
|
29
|
+
*/
|
|
30
|
+
export declare const match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,68 +1,13 @@
|
|
|
1
|
-
import type {
|
|
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 {
|
|
3
|
+
import type { IDelimiter, INode, IThis, IToken, ITokenizerProps, T } from './types';
|
|
5
4
|
/**
|
|
6
5
|
* Lexical Analyzer for InlineImage.
|
|
7
|
-
*
|
|
8
|
-
* Syntax for images is like the syntax for links, with one difference.
|
|
9
|
-
* Instead of link text, we have an image description.
|
|
10
|
-
* The rules for this are the same as for link text, except that
|
|
11
|
-
*
|
|
12
|
-
* a) an image description starts with ''
|
|
27
|
-
* - '](url "title")'
|
|
28
|
-
* - '](<url>)'
|
|
29
|
-
* - '](<url> "title")'
|
|
30
|
-
*
|
|
31
6
|
* @see https://github.com/syntax-tree/mdast#image
|
|
32
7
|
* @see https://github.github.com/gfm/#images
|
|
33
8
|
*/
|
|
34
|
-
export declare class ImageTokenizer extends BaseInlineTokenizer<
|
|
35
|
-
constructor(props?:
|
|
36
|
-
|
|
37
|
-
|
|
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;
|
|
9
|
+
export declare class ImageTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode, IThis> implements IInlineTokenizer<T, IDelimiter, IToken, INode, IThis> {
|
|
10
|
+
constructor(props?: ITokenizerProps);
|
|
11
|
+
readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
|
|
12
|
+
readonly parse: IParseInlineHookCreator<T, IToken, INode, IThis>;
|
|
68
13
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
import type { Image, ImageType } from '@yozora/ast';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { INodeInterval } from '@yozora/character';
|
|
3
|
+
import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, ITokenizer, IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
4
4
|
export declare type T = ImageType;
|
|
5
|
-
export declare type
|
|
5
|
+
export declare type INode = Image;
|
|
6
6
|
export declare const uniqueName = "@yozora/tokenizer-image";
|
|
7
7
|
/**
|
|
8
8
|
* An image token.
|
|
9
9
|
*/
|
|
10
|
-
export interface
|
|
10
|
+
export interface IToken extends IPartialYastInlineToken<T> {
|
|
11
11
|
/**
|
|
12
12
|
* Link destination interval.
|
|
13
13
|
*/
|
|
14
|
-
destinationContent?:
|
|
14
|
+
destinationContent?: INodeInterval;
|
|
15
15
|
/**
|
|
16
16
|
* Link title interval.
|
|
17
17
|
*/
|
|
18
|
-
titleContent?:
|
|
18
|
+
titleContent?: INodeInterval;
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
20
|
+
export interface IDelimiter extends IYastTokenDelimiter {
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* IDelimiter type.
|
|
23
23
|
*/
|
|
24
24
|
type: 'opener' | 'closer';
|
|
25
25
|
/**
|
|
26
26
|
* link destination
|
|
27
27
|
*/
|
|
28
|
-
destinationContent?:
|
|
28
|
+
destinationContent?: INodeInterval;
|
|
29
29
|
/**
|
|
30
30
|
* link title
|
|
31
31
|
*/
|
|
32
|
-
titleContent?:
|
|
32
|
+
titleContent?: INodeInterval;
|
|
33
33
|
}
|
|
34
|
-
export declare type
|
|
34
|
+
export declare type IThis = ITokenizer;
|
|
35
|
+
export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
|
package/lib/types/util.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Node } 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<
|
|
8
|
+
export declare function calcImageAlt(nodes: ReadonlyArray<Node>): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-image",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
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": "^
|
|
39
|
-
"@yozora/character": "^
|
|
40
|
-
"@yozora/core-tokenizer": "^
|
|
41
|
-
"@yozora/tokenizer-link": "^
|
|
38
|
+
"@yozora/ast": "^2.0.0-alpha.3",
|
|
39
|
+
"@yozora/character": "^2.0.0-alpha.3",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.3",
|
|
41
|
+
"@yozora/tokenizer-link": "^2.0.0-alpha.3"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9f274fc7487a8c1dd213405d92508f9a7621f730"
|
|
44
44
|
}
|