@yozora/tokenizer-image-reference 1.2.2 → 2.0.0-alpha.2
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 +60 -32
- package/lib/esm/index.js +59 -33
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +33 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -53
- package/lib/types/types.d.ts +9 -8
- package/package.json +7 -7
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 ImageReferenceTokenizer from '@yozora/tokenizer-image-reference'
|
|
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 ImageReferenceTokenizer())
|
|
96
96
|
|
|
97
97
|
// parse source markdown content
|
|
@@ -231,7 +231,6 @@ Name | Type | Required | Default
|
|
|
231
231
|
[@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
|
|
232
232
|
[@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
|
|
233
233
|
[@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
|
|
234
|
-
[@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
|
|
235
234
|
[@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
|
|
236
235
|
[@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
|
|
237
236
|
[@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
|
|
@@ -291,7 +290,6 @@ Name | Type | Required | Default
|
|
|
291
290
|
[doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
|
|
292
291
|
[doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
|
|
293
292
|
[doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
|
|
294
|
-
[doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
|
|
295
293
|
[doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
|
|
296
294
|
[doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
|
|
297
295
|
[doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
|
package/lib/cjs/index.js
CHANGED
|
@@ -5,20 +5,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var ast = require('@yozora/ast');
|
|
6
6
|
var character = require('@yozora/character');
|
|
7
7
|
var coreTokenizer = require('@yozora/core-tokenizer');
|
|
8
|
-
var tokenizerImage = require('@yozora/tokenizer-image');
|
|
9
8
|
var tokenizerLink = require('@yozora/tokenizer-link');
|
|
9
|
+
var tokenizerImage = require('@yozora/tokenizer-image');
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
_findDelimiter(startIndex, endIndex, nodePoints) {
|
|
11
|
+
const match = function (api) {
|
|
12
|
+
return {
|
|
13
|
+
findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
|
|
14
|
+
isDelimiterPair,
|
|
15
|
+
processDelimiterPair,
|
|
16
|
+
};
|
|
17
|
+
function _findDelimiter(startIndex, endIndex) {
|
|
18
|
+
const nodePoints = api.getNodePoints();
|
|
22
19
|
for (let i = startIndex; i < endIndex; ++i) {
|
|
23
20
|
const c = nodePoints[i].codePoint;
|
|
24
21
|
switch (c) {
|
|
@@ -26,8 +23,7 @@ class ImageReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
26
23
|
i += 1;
|
|
27
24
|
break;
|
|
28
25
|
case character.AsciiCodePoint.EXCLAMATION_MARK: {
|
|
29
|
-
if (i + 1 >= endIndex ||
|
|
30
|
-
nodePoints[i + 1].codePoint !== character.AsciiCodePoint.OPEN_BRACKET) {
|
|
26
|
+
if (i + 1 >= endIndex || nodePoints[i + 1].codePoint !== character.AsciiCodePoint.OPEN_BRACKET) {
|
|
31
27
|
break;
|
|
32
28
|
}
|
|
33
29
|
return {
|
|
@@ -44,8 +40,7 @@ class ImageReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
44
40
|
endIndex: i + 1,
|
|
45
41
|
brackets: [],
|
|
46
42
|
};
|
|
47
|
-
if (i + 1 >= endIndex ||
|
|
48
|
-
nodePoints[i + 1].codePoint !== character.AsciiCodePoint.OPEN_BRACKET) {
|
|
43
|
+
if (i + 1 >= endIndex || nodePoints[i + 1].codePoint !== character.AsciiCodePoint.OPEN_BRACKET) {
|
|
49
44
|
return delimiter;
|
|
50
45
|
}
|
|
51
46
|
const result = coreTokenizer.eatLinkLabel(nodePoints, i + 1, endIndex);
|
|
@@ -82,7 +77,8 @@ class ImageReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
82
77
|
}
|
|
83
78
|
return null;
|
|
84
79
|
}
|
|
85
|
-
isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens
|
|
80
|
+
function isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
81
|
+
const nodePoints = api.getNodePoints();
|
|
86
82
|
const balancedBracketsStatus = tokenizerLink.checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
|
|
87
83
|
switch (balancedBracketsStatus) {
|
|
88
84
|
case -1:
|
|
@@ -93,7 +89,8 @@ class ImageReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
93
89
|
return { paired: false, opener: true, closer: false };
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
|
-
processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens
|
|
92
|
+
function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
93
|
+
const nodePoints = api.getNodePoints();
|
|
97
94
|
const bracket = closerDelimiter.brackets[0];
|
|
98
95
|
if (bracket != null && bracket.identifier != null) {
|
|
99
96
|
if (api.hasDefinition(bracket.identifier)) {
|
|
@@ -104,7 +101,7 @@ class ImageReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
104
101
|
referenceType: 'full',
|
|
105
102
|
label: bracket.label,
|
|
106
103
|
identifier: bracket.identifier,
|
|
107
|
-
children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex
|
|
104
|
+
children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex),
|
|
108
105
|
};
|
|
109
106
|
return { tokens: [token] };
|
|
110
107
|
}
|
|
@@ -121,26 +118,57 @@ class ImageReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
121
118
|
referenceType: bracket == null ? 'shortcut' : 'collapsed',
|
|
122
119
|
label: labelAndIdentifier.label,
|
|
123
120
|
identifier: labelAndIdentifier.identifier,
|
|
124
|
-
children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex
|
|
121
|
+
children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex),
|
|
125
122
|
};
|
|
126
123
|
return { tokens: [token] };
|
|
127
124
|
}
|
|
128
125
|
return { tokens: internalTokens };
|
|
129
126
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
identifier,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const parse = function (api) {
|
|
130
|
+
return {
|
|
131
|
+
parse: tokens => tokens.map(token => {
|
|
132
|
+
const { identifier, label, referenceType } = token;
|
|
133
|
+
const children = api.parseInlineTokens(token.children);
|
|
134
|
+
const alt = tokenizerImage.calcImageAlt(children);
|
|
135
|
+
const node = api.shouldReservePosition
|
|
136
|
+
? {
|
|
137
|
+
type: ast.ImageReferenceType,
|
|
138
|
+
position: api.calcPosition(token),
|
|
139
|
+
identifier,
|
|
140
|
+
label,
|
|
141
|
+
referenceType,
|
|
142
|
+
alt,
|
|
143
|
+
}
|
|
144
|
+
: {
|
|
145
|
+
type: ast.ImageReferenceType,
|
|
146
|
+
identifier,
|
|
147
|
+
label,
|
|
148
|
+
referenceType,
|
|
149
|
+
alt,
|
|
150
|
+
};
|
|
151
|
+
return node;
|
|
152
|
+
}),
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const uniqueName = '@yozora/tokenizer-image-reference';
|
|
157
|
+
|
|
158
|
+
class ImageReferenceTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
159
|
+
constructor(props = {}) {
|
|
160
|
+
var _a, _b;
|
|
161
|
+
super({
|
|
162
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
163
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.LINKS,
|
|
164
|
+
});
|
|
165
|
+
this.match = match;
|
|
166
|
+
this.parse = parse;
|
|
141
167
|
}
|
|
142
168
|
}
|
|
143
169
|
|
|
144
170
|
exports.ImageReferenceTokenizer = ImageReferenceTokenizer;
|
|
145
171
|
exports.ImageReferenceTokenizerName = uniqueName;
|
|
146
|
-
exports[
|
|
172
|
+
exports["default"] = ImageReferenceTokenizer;
|
|
173
|
+
exports.imageReferenceMatch = match;
|
|
174
|
+
exports.imageReferenceParse = parse;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { ImageReferenceType } from '@yozora/ast';
|
|
2
2
|
import { AsciiCodePoint } from '@yozora/character';
|
|
3
|
-
import { BaseInlineTokenizer, TokenizerPriority
|
|
4
|
-
import { calcImageAlt } from '@yozora/tokenizer-image';
|
|
3
|
+
import { genFindDelimiter, eatLinkLabel, BaseInlineTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
5
4
|
import { checkBalancedBracketsStatus } from '@yozora/tokenizer-link';
|
|
5
|
+
import { calcImageAlt } from '@yozora/tokenizer-image';
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
_findDelimiter(startIndex, endIndex, nodePoints) {
|
|
7
|
+
const match = function (api) {
|
|
8
|
+
return {
|
|
9
|
+
findDelimiter: () => genFindDelimiter(_findDelimiter),
|
|
10
|
+
isDelimiterPair,
|
|
11
|
+
processDelimiterPair,
|
|
12
|
+
};
|
|
13
|
+
function _findDelimiter(startIndex, endIndex) {
|
|
14
|
+
const nodePoints = api.getNodePoints();
|
|
18
15
|
for (let i = startIndex; i < endIndex; ++i) {
|
|
19
16
|
const c = nodePoints[i].codePoint;
|
|
20
17
|
switch (c) {
|
|
@@ -22,8 +19,7 @@ class ImageReferenceTokenizer extends BaseInlineTokenizer {
|
|
|
22
19
|
i += 1;
|
|
23
20
|
break;
|
|
24
21
|
case AsciiCodePoint.EXCLAMATION_MARK: {
|
|
25
|
-
if (i + 1 >= endIndex ||
|
|
26
|
-
nodePoints[i + 1].codePoint !== AsciiCodePoint.OPEN_BRACKET) {
|
|
22
|
+
if (i + 1 >= endIndex || nodePoints[i + 1].codePoint !== AsciiCodePoint.OPEN_BRACKET) {
|
|
27
23
|
break;
|
|
28
24
|
}
|
|
29
25
|
return {
|
|
@@ -40,8 +36,7 @@ class ImageReferenceTokenizer extends BaseInlineTokenizer {
|
|
|
40
36
|
endIndex: i + 1,
|
|
41
37
|
brackets: [],
|
|
42
38
|
};
|
|
43
|
-
if (i + 1 >= endIndex ||
|
|
44
|
-
nodePoints[i + 1].codePoint !== AsciiCodePoint.OPEN_BRACKET) {
|
|
39
|
+
if (i + 1 >= endIndex || nodePoints[i + 1].codePoint !== AsciiCodePoint.OPEN_BRACKET) {
|
|
45
40
|
return delimiter;
|
|
46
41
|
}
|
|
47
42
|
const result = eatLinkLabel(nodePoints, i + 1, endIndex);
|
|
@@ -78,7 +73,8 @@ class ImageReferenceTokenizer extends BaseInlineTokenizer {
|
|
|
78
73
|
}
|
|
79
74
|
return null;
|
|
80
75
|
}
|
|
81
|
-
isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens
|
|
76
|
+
function isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
77
|
+
const nodePoints = api.getNodePoints();
|
|
82
78
|
const balancedBracketsStatus = checkBalancedBracketsStatus(openerDelimiter.endIndex, closerDelimiter.startIndex, internalTokens, nodePoints);
|
|
83
79
|
switch (balancedBracketsStatus) {
|
|
84
80
|
case -1:
|
|
@@ -89,7 +85,8 @@ class ImageReferenceTokenizer extends BaseInlineTokenizer {
|
|
|
89
85
|
return { paired: false, opener: true, closer: false };
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
|
-
processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens
|
|
88
|
+
function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
|
|
89
|
+
const nodePoints = api.getNodePoints();
|
|
93
90
|
const bracket = closerDelimiter.brackets[0];
|
|
94
91
|
if (bracket != null && bracket.identifier != null) {
|
|
95
92
|
if (api.hasDefinition(bracket.identifier)) {
|
|
@@ -100,7 +97,7 @@ class ImageReferenceTokenizer extends BaseInlineTokenizer {
|
|
|
100
97
|
referenceType: 'full',
|
|
101
98
|
label: bracket.label,
|
|
102
99
|
identifier: bracket.identifier,
|
|
103
|
-
children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex
|
|
100
|
+
children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex),
|
|
104
101
|
};
|
|
105
102
|
return { tokens: [token] };
|
|
106
103
|
}
|
|
@@ -117,24 +114,53 @@ class ImageReferenceTokenizer extends BaseInlineTokenizer {
|
|
|
117
114
|
referenceType: bracket == null ? 'shortcut' : 'collapsed',
|
|
118
115
|
label: labelAndIdentifier.label,
|
|
119
116
|
identifier: labelAndIdentifier.identifier,
|
|
120
|
-
children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex
|
|
117
|
+
children: api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex),
|
|
121
118
|
};
|
|
122
119
|
return { tokens: [token] };
|
|
123
120
|
}
|
|
124
121
|
return { tokens: internalTokens };
|
|
125
122
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
identifier,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const parse = function (api) {
|
|
126
|
+
return {
|
|
127
|
+
parse: tokens => tokens.map(token => {
|
|
128
|
+
const { identifier, label, referenceType } = token;
|
|
129
|
+
const children = api.parseInlineTokens(token.children);
|
|
130
|
+
const alt = calcImageAlt(children);
|
|
131
|
+
const node = api.shouldReservePosition
|
|
132
|
+
? {
|
|
133
|
+
type: ImageReferenceType,
|
|
134
|
+
position: api.calcPosition(token),
|
|
135
|
+
identifier,
|
|
136
|
+
label,
|
|
137
|
+
referenceType,
|
|
138
|
+
alt,
|
|
139
|
+
}
|
|
140
|
+
: {
|
|
141
|
+
type: ImageReferenceType,
|
|
142
|
+
identifier,
|
|
143
|
+
label,
|
|
144
|
+
referenceType,
|
|
145
|
+
alt,
|
|
146
|
+
};
|
|
147
|
+
return node;
|
|
148
|
+
}),
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const uniqueName = '@yozora/tokenizer-image-reference';
|
|
153
|
+
|
|
154
|
+
class ImageReferenceTokenizer extends BaseInlineTokenizer {
|
|
155
|
+
constructor(props = {}) {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
super({
|
|
158
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
159
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.LINKS,
|
|
160
|
+
});
|
|
161
|
+
this.match = match;
|
|
162
|
+
this.parse = parse;
|
|
137
163
|
}
|
|
138
164
|
}
|
|
139
165
|
|
|
140
|
-
export { ImageReferenceTokenizer, uniqueName as ImageReferenceTokenizerName, ImageReferenceTokenizer as default };
|
|
166
|
+
export { ImageReferenceTokenizer, uniqueName as ImageReferenceTokenizerName, ImageReferenceTokenizer as default, match as imageReferenceMatch, parse as imageReferenceParse };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
export { match as imageReferenceMatch } from './match';
|
|
2
|
+
export { parse as imageReferenceParse } from './parse';
|
|
3
|
+
export { ImageReferenceTokenizer, ImageReferenceTokenizer as default } from './tokenizer';
|
|
3
4
|
export { uniqueName as ImageReferenceTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default ImageReferenceTokenizer;
|
|
5
|
+
export type { IThis as IImageReferenceHookContext, IToken as IImageReferenceToken, ITokenizerProps as IImageReferenceTokenizerProps, } from './types';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IMatchInlineHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IDelimiter, IThis, IToken, T } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Syntax for image-references is like the syntax for link-references, with one
|
|
5
|
+
* difference. Instead of link text, we have an image description. The rules for
|
|
6
|
+
* this are the same as for link text, except that
|
|
7
|
+
*
|
|
8
|
+
* a) an image description starts with '![' rather than '[', and
|
|
9
|
+
* b) an image description may contain links.
|
|
10
|
+
*
|
|
11
|
+
* An image description has inline elements as its contents. When an image is
|
|
12
|
+
* rendered to HTML, this is standardly used as the image’s alt attribute.
|
|
13
|
+
*
|
|
14
|
+
* One type of opener delimiter: '!['
|
|
15
|
+
*
|
|
16
|
+
* Three types of closer delimiter: ']', '][]' something like '][bar]'
|
|
17
|
+
*
|
|
18
|
+
* ------
|
|
19
|
+
*
|
|
20
|
+
* A 'opener' type delimiter is one of the following forms:
|
|
21
|
+
*
|
|
22
|
+
* - '!['
|
|
23
|
+
*
|
|
24
|
+
* A 'closer' type delimiter is one of the following forms:
|
|
25
|
+
*
|
|
26
|
+
* - ']'
|
|
27
|
+
* - '][]'
|
|
28
|
+
* - '][identifier]'
|
|
29
|
+
*
|
|
30
|
+
* @see https://github.com/syntax-tree/mdast#imagereference
|
|
31
|
+
* @see https://github.github.com/gfm/#images
|
|
32
|
+
*/
|
|
33
|
+
export declare const match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,60 +1,13 @@
|
|
|
1
|
-
import type {
|
|
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 {
|
|
3
|
+
import type { IDelimiter, INode, IThis, IToken, ITokenizerProps, T } from './types';
|
|
6
4
|
/**
|
|
7
5
|
* Lexical Analyzer for ImageReference.
|
|
8
|
-
*
|
|
9
|
-
* Syntax for image-references is like the syntax for link-references, with one
|
|
10
|
-
* difference. Instead of link text, we have an image description. The rules for
|
|
11
|
-
* this are the same as for link text, except that
|
|
12
|
-
*
|
|
13
|
-
* a) an image description starts with '![' rather than '[', and
|
|
14
|
-
* b) an image description may contain links.
|
|
15
|
-
*
|
|
16
|
-
* An image description has inline elements as its contents. When an image is
|
|
17
|
-
* rendered to HTML, this is standardly used as the image’s alt attribute.
|
|
18
|
-
*
|
|
19
|
-
* One type of opener delimiter: '!['
|
|
20
|
-
*
|
|
21
|
-
* Three types of closer delimiter: ']', '][]' something like '][bar]'
|
|
22
|
-
*
|
|
23
|
-
* ------
|
|
24
|
-
*
|
|
25
|
-
* A 'opener' type delimiter is one of the following forms:
|
|
26
|
-
*
|
|
27
|
-
* - '!['
|
|
28
|
-
*
|
|
29
|
-
* A 'closer' type delimiter is one of the following forms:
|
|
30
|
-
*
|
|
31
|
-
* - ']'
|
|
32
|
-
* - '][]'
|
|
33
|
-
* - '][identifier]'
|
|
34
|
-
*
|
|
35
6
|
* @see https://github.com/syntax-tree/mdast#imagereference
|
|
36
7
|
* @see https://github.github.com/gfm/#images
|
|
37
8
|
*/
|
|
38
|
-
export declare class ImageReferenceTokenizer extends BaseInlineTokenizer<
|
|
39
|
-
constructor(props?:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* @see BaseInlineTokenizer
|
|
43
|
-
*/
|
|
44
|
-
protected _findDelimiter(startIndex: number, endIndex: number, nodePoints: ReadonlyArray<NodePoint>): Delimiter | null;
|
|
45
|
-
/**
|
|
46
|
-
* @override
|
|
47
|
-
* @see TokenizerMatchInlineHook
|
|
48
|
-
*/
|
|
49
|
-
isDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, nodePoints: ReadonlyArray<NodePoint>): ResultOfIsDelimiterPair;
|
|
50
|
-
/**
|
|
51
|
-
* @override
|
|
52
|
-
* @see TokenizerMatchInlineHook
|
|
53
|
-
*/
|
|
54
|
-
processDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, nodePoints: ReadonlyArray<NodePoint>, api: Readonly<MatchInlinePhaseApi>): ResultOfProcessDelimiterPair<T, Token, Delimiter>;
|
|
55
|
-
/**
|
|
56
|
-
* @override
|
|
57
|
-
* @see TokenizerParseInlineHook
|
|
58
|
-
*/
|
|
59
|
-
processToken(token: Token, children?: YastNode[]): Node;
|
|
9
|
+
export declare class ImageReferenceTokenizer 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>;
|
|
60
13
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { IImageReference, IYastAssociation, IYastReference, ImageReferenceType } from '@yozora/ast';
|
|
2
|
+
import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, ITokenizer, IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
|
+
import type { ILinkReferenceDelimiterBracket } from '@yozora/tokenizer-link-reference';
|
|
4
4
|
export declare const uniqueName = "@yozora/tokenizer-image-reference";
|
|
5
5
|
export declare type T = ImageReferenceType;
|
|
6
|
-
export declare type
|
|
7
|
-
export interface
|
|
6
|
+
export declare type INode = IImageReference;
|
|
7
|
+
export interface IToken extends IPartialYastInlineToken<T>, IYastAssociation, IYastReference {
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
10
|
-
brackets:
|
|
9
|
+
export interface IDelimiter extends IYastTokenDelimiter {
|
|
10
|
+
brackets: ILinkReferenceDelimiterBracket[];
|
|
11
11
|
}
|
|
12
|
-
export declare type
|
|
12
|
+
export declare type IThis = ITokenizer;
|
|
13
|
+
export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-image-reference",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "guanghechen",
|
|
6
6
|
"url": "https://github.com/guanghechen/"
|
|
@@ -35,11 +35,11 @@
|
|
|
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-image": "^
|
|
42
|
-
"@yozora/tokenizer-link": "^
|
|
38
|
+
"@yozora/ast": "^2.0.0-alpha.2",
|
|
39
|
+
"@yozora/character": "^2.0.0-alpha.2",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.2",
|
|
41
|
+
"@yozora/tokenizer-image": "^2.0.0-alpha.2",
|
|
42
|
+
"@yozora/tokenizer-link": "^2.0.0-alpha.2"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "da59d85520455c59a117a35032ef1a035c10ea21"
|
|
45
45
|
}
|