@yozora/tokenizer-definition 1.2.1 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -84,14 +84,14 @@ so you can use `YozoraParser` / `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 { DefaultYastParser } from '@yozora/core-parser'
87
+ import { DefaultParser } from '@yozora/core-parser'
88
88
  import ParagraphTokenizer from '@yozora/tokenizer-paragraph'
89
89
  import TextTokenizer from '@yozora/tokenizer-text'
90
90
  import DefinitionTokenizer from '@yozora/tokenizer-definition'
91
91
 
92
- const parser = new DefaultYastParser()
93
- .useBlockFallbackTokenizer(new ParagraphTokenizer())
94
- .useInlineFallbackTokenizer(new TextTokenizer())
92
+ const parser = new DefaultParser()
93
+ .useFallbackTokenizer(new ParagraphTokenizer())
94
+ .useFallbackTokenizer(new TextTokenizer())
95
95
  .useTokenizer(new DefinitionTokenizer())
96
96
 
97
97
  // parse source markdown content
@@ -242,7 +242,6 @@ Name | Type | Required | Default
242
242
  [@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
243
243
  [@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
244
244
  [@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
245
- [@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
246
245
  [@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
247
246
  [@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
248
247
  [@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
@@ -302,7 +301,6 @@ Name | Type | Required | Default
302
301
  [doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
303
302
  [doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
304
303
  [doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
305
- [doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
306
304
  [doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
307
305
  [doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
308
306
  [doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
package/lib/cjs/index.js CHANGED
@@ -2,16 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var ast = require('@yozora/ast');
6
5
  var character = require('@yozora/character');
7
6
  var coreTokenizer = require('@yozora/core-tokenizer');
7
+ var ast = require('@yozora/ast');
8
8
 
9
- const uniqueName = '@yozora/tokenizer-definition';
10
-
11
- function eatAndCollectLinkDestination(nodePoints, startIndex, endIndex, token) {
9
+ function eatAndCollectLinkDestination(nodePoints, startIndex, endIndex, state) {
12
10
  let i = startIndex;
13
- if (token == null) {
14
- token = {
11
+ if (state == null) {
12
+ state = {
15
13
  saturated: false,
16
14
  nodePoints: [],
17
15
  hasOpenAngleBracket: false,
@@ -20,79 +18,78 @@ function eatAndCollectLinkDestination(nodePoints, startIndex, endIndex, token) {
20
18
  }
21
19
  const firstNonWhitespaceIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, i, endIndex);
22
20
  if (firstNonWhitespaceIndex >= endIndex)
23
- return { nextIndex: -1, token };
24
- if (token.nodePoints.length <= 0) {
21
+ return { nextIndex: -1, state: state };
22
+ if (state.nodePoints.length <= 0) {
25
23
  i = firstNonWhitespaceIndex;
26
24
  const p = nodePoints[i];
27
25
  if (p.codePoint === character.AsciiCodePoint.OPEN_ANGLE) {
28
26
  i += 1;
29
- token.hasOpenAngleBracket = true;
30
- token.nodePoints.push(p);
27
+ state.hasOpenAngleBracket = true;
28
+ state.nodePoints.push(p);
31
29
  }
32
30
  }
33
- if (token.hasOpenAngleBracket) {
31
+ if (state.hasOpenAngleBracket) {
34
32
  for (; i < endIndex; ++i) {
35
33
  const p = nodePoints[i];
36
34
  switch (p.codePoint) {
37
35
  case character.AsciiCodePoint.BACKSLASH:
38
36
  if (i + 1 < endIndex) {
39
- token.nodePoints.push(p);
40
- token.nodePoints.push(nodePoints[i + 1]);
37
+ state.nodePoints.push(p);
38
+ state.nodePoints.push(nodePoints[i + 1]);
41
39
  }
42
40
  i += 1;
43
41
  break;
44
42
  case character.AsciiCodePoint.OPEN_ANGLE:
45
43
  case character.VirtualCodePoint.LINE_END:
46
- return { nextIndex: -1, token };
44
+ return { nextIndex: -1, state: state };
47
45
  case character.AsciiCodePoint.CLOSE_ANGLE:
48
- token.saturated = true;
49
- token.nodePoints.push(p);
50
- return { nextIndex: i + 1, token };
46
+ state.saturated = true;
47
+ state.nodePoints.push(p);
48
+ return { nextIndex: i + 1, state: state };
51
49
  default:
52
- token.nodePoints.push(p);
50
+ state.nodePoints.push(p);
53
51
  }
54
52
  }
55
- return { nextIndex: i, token };
53
+ return { nextIndex: i, state: state };
56
54
  }
57
55
  for (; i < endIndex; ++i) {
58
56
  const p = nodePoints[i];
59
57
  switch (p.codePoint) {
60
58
  case character.AsciiCodePoint.BACKSLASH:
61
59
  if (i + 1 < endIndex) {
62
- token.nodePoints.push(p);
63
- token.nodePoints.push(nodePoints[i + 1]);
60
+ state.nodePoints.push(p);
61
+ state.nodePoints.push(nodePoints[i + 1]);
64
62
  }
65
63
  i += 1;
66
64
  break;
67
65
  case character.AsciiCodePoint.OPEN_PARENTHESIS:
68
- token.openParensCount += 1;
69
- token.nodePoints.push(p);
66
+ state.openParensCount += 1;
67
+ state.nodePoints.push(p);
70
68
  break;
71
69
  case character.AsciiCodePoint.CLOSE_PARENTHESIS:
72
- token.openParensCount -= 1;
73
- token.nodePoints.push(p);
74
- if (token.openParensCount < 0) {
75
- return { nextIndex: i, token };
70
+ state.openParensCount -= 1;
71
+ state.nodePoints.push(p);
72
+ if (state.openParensCount < 0) {
73
+ return { nextIndex: i, state: state };
76
74
  }
77
75
  break;
78
76
  default:
79
- if (character.isWhitespaceCharacter(p.codePoint) ||
80
- character.isAsciiControlCharacter(p.codePoint)) {
81
- token.saturated = true;
82
- return { nextIndex: i, token };
77
+ if (character.isWhitespaceCharacter(p.codePoint) || character.isAsciiControlCharacter(p.codePoint)) {
78
+ state.saturated = true;
79
+ return { nextIndex: i, state: state };
83
80
  }
84
- token.nodePoints.push(p);
81
+ state.nodePoints.push(p);
85
82
  break;
86
83
  }
87
84
  }
88
- token.saturated = true;
89
- return { nextIndex: i, token };
85
+ state.saturated = true;
86
+ return { nextIndex: i, state: state };
90
87
  }
91
88
 
92
- function eatAndCollectLinkLabel(nodePoints, startIndex, endIndex, token) {
89
+ function eatAndCollectLinkLabel(nodePoints, startIndex, endIndex, state) {
93
90
  let i = startIndex;
94
- if (token == null) {
95
- token = {
91
+ if (state == null) {
92
+ state = {
96
93
  saturated: false,
97
94
  nodePoints: [],
98
95
  hasNonWhitespaceCharacter: false,
@@ -100,50 +97,50 @@ function eatAndCollectLinkLabel(nodePoints, startIndex, endIndex, token) {
100
97
  }
101
98
  const firstNonWhitespaceIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, i, endIndex);
102
99
  if (firstNonWhitespaceIndex >= endIndex)
103
- return { nextIndex: -1, token };
104
- if (token.nodePoints.length <= 0) {
100
+ return { nextIndex: -1, state: state };
101
+ if (state.nodePoints.length <= 0) {
105
102
  i = firstNonWhitespaceIndex;
106
103
  const p = nodePoints[i];
107
104
  if (p.codePoint !== character.AsciiCodePoint.OPEN_BRACKET) {
108
- return { nextIndex: -1, token };
105
+ return { nextIndex: -1, state: state };
109
106
  }
110
107
  i += 1;
111
- token.nodePoints.push(p);
108
+ state.nodePoints.push(p);
112
109
  }
113
110
  for (; i < endIndex; ++i) {
114
111
  const p = nodePoints[i];
115
112
  switch (p.codePoint) {
116
113
  case character.AsciiCodePoint.BACKSLASH:
117
- token.hasNonWhitespaceCharacter = true;
114
+ state.hasNonWhitespaceCharacter = true;
118
115
  if (i + 1 < endIndex) {
119
- token.nodePoints.push(p);
120
- token.nodePoints.push(nodePoints[i + 1]);
116
+ state.nodePoints.push(p);
117
+ state.nodePoints.push(nodePoints[i + 1]);
121
118
  }
122
119
  i += 1;
123
120
  break;
124
121
  case character.AsciiCodePoint.OPEN_BRACKET:
125
- return { nextIndex: -1, token };
122
+ return { nextIndex: -1, state: state };
126
123
  case character.AsciiCodePoint.CLOSE_BRACKET:
127
- token.nodePoints.push(p);
128
- if (token.hasNonWhitespaceCharacter) {
129
- token.saturated = true;
130
- return { nextIndex: i + 1, token };
124
+ state.nodePoints.push(p);
125
+ if (state.hasNonWhitespaceCharacter) {
126
+ state.saturated = true;
127
+ return { nextIndex: i + 1, state: state };
131
128
  }
132
- return { nextIndex: -1, token };
129
+ return { nextIndex: -1, state: state };
133
130
  default:
134
131
  if (!character.isWhitespaceCharacter(p.codePoint)) {
135
- token.hasNonWhitespaceCharacter = true;
132
+ state.hasNonWhitespaceCharacter = true;
136
133
  }
137
- token.nodePoints.push(p);
134
+ state.nodePoints.push(p);
138
135
  }
139
136
  }
140
- return { nextIndex: 1, token };
137
+ return { nextIndex: 1, state: state };
141
138
  }
142
139
 
143
- function eatAndCollectLinkTitle(nodePoints, startIndex, endIndex, token) {
140
+ function eatAndCollectLinkTitle(nodePoints, startIndex, endIndex, state) {
144
141
  let i = startIndex;
145
- if (token == null) {
146
- token = {
142
+ if (state == null) {
143
+ state = {
147
144
  saturated: false,
148
145
  nodePoints: [],
149
146
  wrapSymbol: null,
@@ -151,25 +148,25 @@ function eatAndCollectLinkTitle(nodePoints, startIndex, endIndex, token) {
151
148
  }
152
149
  const firstNonWhitespaceIndex = coreTokenizer.eatOptionalWhitespaces(nodePoints, i, endIndex);
153
150
  if (firstNonWhitespaceIndex >= endIndex)
154
- return { nextIndex: -1, token };
155
- if (token.nodePoints.length <= 0) {
151
+ return { nextIndex: -1, state: state };
152
+ if (state.nodePoints.length <= 0) {
156
153
  i = firstNonWhitespaceIndex;
157
154
  const p = nodePoints[i];
158
155
  switch (p.codePoint) {
159
156
  case character.AsciiCodePoint.DOUBLE_QUOTE:
160
157
  case character.AsciiCodePoint.SINGLE_QUOTE:
161
158
  case character.AsciiCodePoint.OPEN_PARENTHESIS:
162
- token.wrapSymbol = p.codePoint;
163
- token.nodePoints.push(p);
159
+ state.wrapSymbol = p.codePoint;
160
+ state.nodePoints.push(p);
164
161
  i += 1;
165
162
  break;
166
163
  default:
167
- return { nextIndex: -1, token };
164
+ return { nextIndex: -1, state: state };
168
165
  }
169
166
  }
170
- if (token.wrapSymbol == null)
171
- return { nextIndex: -1, token };
172
- switch (token.wrapSymbol) {
167
+ if (state.wrapSymbol == null)
168
+ return { nextIndex: -1, state: state };
169
+ switch (state.wrapSymbol) {
173
170
  case character.AsciiCodePoint.DOUBLE_QUOTE:
174
171
  case character.AsciiCodePoint.SINGLE_QUOTE: {
175
172
  for (; i < endIndex; ++i) {
@@ -177,17 +174,17 @@ function eatAndCollectLinkTitle(nodePoints, startIndex, endIndex, token) {
177
174
  switch (p.codePoint) {
178
175
  case character.AsciiCodePoint.BACKSLASH:
179
176
  if (i + 1 < endIndex) {
180
- token.nodePoints.push(p);
181
- token.nodePoints.push(nodePoints[i + 1]);
177
+ state.nodePoints.push(p);
178
+ state.nodePoints.push(nodePoints[i + 1]);
182
179
  }
183
180
  i += 1;
184
181
  break;
185
- case token.wrapSymbol:
186
- token.saturated = true;
187
- token.nodePoints.push(p);
188
- return { nextIndex: i + 1, token };
182
+ case state.wrapSymbol:
183
+ state.saturated = true;
184
+ state.nodePoints.push(p);
185
+ return { nextIndex: i + 1, state: state };
189
186
  default:
190
- token.nodePoints.push(p);
187
+ state.nodePoints.push(p);
191
188
  }
192
189
  }
193
190
  break;
@@ -198,49 +195,46 @@ function eatAndCollectLinkTitle(nodePoints, startIndex, endIndex, token) {
198
195
  switch (p.codePoint) {
199
196
  case character.AsciiCodePoint.BACKSLASH:
200
197
  if (i + 1 < endIndex) {
201
- token.nodePoints.push(p);
202
- token.nodePoints.push(nodePoints[i + 1]);
198
+ state.nodePoints.push(p);
199
+ state.nodePoints.push(nodePoints[i + 1]);
203
200
  }
204
201
  i += 1;
205
202
  break;
206
203
  case character.AsciiCodePoint.OPEN_PARENTHESIS:
207
- return { nextIndex: -1, token };
204
+ return { nextIndex: -1, state: state };
208
205
  case character.AsciiCodePoint.CLOSE_PARENTHESIS:
209
- if (i + 1 >= endIndex ||
210
- nodePoints[i + 1].codePoint === character.VirtualCodePoint.LINE_END) {
211
- token.nodePoints.push(p);
212
- token.saturated = true;
206
+ if (i + 1 >= endIndex || nodePoints[i + 1].codePoint === character.VirtualCodePoint.LINE_END) {
207
+ state.nodePoints.push(p);
208
+ state.saturated = true;
213
209
  break;
214
210
  }
215
- return { nextIndex: -1, token };
211
+ return { nextIndex: -1, state: state };
216
212
  default:
217
- token.nodePoints.push(p);
213
+ state.nodePoints.push(p);
218
214
  }
219
215
  }
220
216
  break;
221
217
  }
222
218
  }
223
- return { nextIndex: endIndex, token };
219
+ return { nextIndex: endIndex, state: state };
224
220
  }
225
221
 
226
- class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
227
- constructor(props = {}) {
228
- var _a, _b;
229
- super({
230
- name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
231
- priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
232
- });
233
- this.isContainingBlock = false;
234
- }
235
- eatOpener(line) {
222
+ const match = function (api) {
223
+ return {
224
+ isContainingBlock: false,
225
+ eatOpener,
226
+ eatContinuationText,
227
+ onClose,
228
+ };
229
+ function eatOpener(line) {
236
230
  if (line.countOfPrecedeSpaces >= 4)
237
231
  return null;
238
232
  const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
239
233
  if (firstNonWhitespaceIndex >= endIndex)
240
234
  return null;
241
235
  let i = firstNonWhitespaceIndex;
242
- const linkLabelCollectResult = eatAndCollectLinkLabel(nodePoints, i, endIndex, null);
243
- if (linkLabelCollectResult.nextIndex < 0)
236
+ const { nextIndex: labelEndIndex, state: labelState } = eatAndCollectLinkLabel(nodePoints, i, endIndex, null);
237
+ if (labelEndIndex < 0)
244
238
  return null;
245
239
  const lineNo = nodePoints[startIndex].line;
246
240
  const createInitState = () => {
@@ -250,7 +244,7 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
250
244
  start: coreTokenizer.calcStartYastNodePoint(nodePoints, startIndex),
251
245
  end: coreTokenizer.calcEndYastNodePoint(nodePoints, endIndex - 1),
252
246
  },
253
- label: linkLabelCollectResult.token,
247
+ label: labelState,
254
248
  destination: null,
255
249
  title: null,
256
250
  lineNoOfLabel: lineNo,
@@ -260,11 +254,10 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
260
254
  };
261
255
  return token;
262
256
  };
263
- if (!linkLabelCollectResult.token.saturated) {
257
+ if (!labelState.saturated) {
264
258
  const token = createInitState();
265
259
  return { token, nextIndex: endIndex };
266
260
  }
267
- const labelEndIndex = linkLabelCollectResult.nextIndex;
268
261
  if (labelEndIndex < 0 ||
269
262
  labelEndIndex + 1 >= endIndex ||
270
263
  nodePoints[labelEndIndex].codePoint !== character.AsciiCodePoint.COLON)
@@ -274,39 +267,36 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
274
267
  const token = createInitState();
275
268
  return { token, nextIndex: endIndex };
276
269
  }
277
- const linkDestinationCollectResult = eatAndCollectLinkDestination(nodePoints, i, endIndex, null);
278
- if (linkDestinationCollectResult.nextIndex < 0)
270
+ const { nextIndex: destinationEndIndex, state: destinationState } = eatAndCollectLinkDestination(nodePoints, i, endIndex, null);
271
+ if (destinationEndIndex < 0)
279
272
  return null;
280
- if (!linkDestinationCollectResult.token.saturated &&
281
- linkDestinationCollectResult.nextIndex !== endIndex)
273
+ if (!destinationState.saturated && destinationEndIndex !== endIndex)
282
274
  return null;
283
- const destinationEndIndex = linkDestinationCollectResult.nextIndex;
284
275
  i = coreTokenizer.eatOptionalWhitespaces(nodePoints, destinationEndIndex, endIndex);
285
276
  if (i >= endIndex) {
286
277
  const token = createInitState();
287
- token.destination = linkDestinationCollectResult.token;
278
+ token.destination = destinationState;
288
279
  token.lineNoOfDestination = lineNo;
289
280
  return { token, nextIndex: endIndex };
290
281
  }
291
282
  if (i === destinationEndIndex)
292
283
  return null;
293
- const linkTitleCollectResult = eatAndCollectLinkTitle(nodePoints, i, endIndex, null);
294
- if (linkTitleCollectResult.nextIndex >= 0) {
295
- i = linkTitleCollectResult.nextIndex;
296
- }
284
+ const { nextIndex: titleEndIndex, state: titleState } = eatAndCollectLinkTitle(nodePoints, i, endIndex, null);
285
+ if (titleEndIndex >= 0)
286
+ i = titleEndIndex;
297
287
  if (i < endIndex) {
298
288
  const k = coreTokenizer.eatOptionalWhitespaces(nodePoints, i, endIndex);
299
289
  if (k < endIndex)
300
290
  return null;
301
291
  }
302
292
  const token = createInitState();
303
- token.destination = linkDestinationCollectResult.token;
304
- token.title = linkTitleCollectResult.token;
293
+ token.destination = destinationState;
294
+ token.title = titleState;
305
295
  token.lineNoOfDestination = lineNo;
306
296
  token.lineNoOfTitle = lineNo;
307
297
  return { token, nextIndex: endIndex };
308
298
  }
309
- eatContinuationText(line, token) {
299
+ function eatContinuationText(line, token) {
310
300
  var _a;
311
301
  if (token.title != null && token.title.saturated)
312
302
  return { status: 'notMatched' };
@@ -314,12 +304,11 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
314
304
  const lineNo = nodePoints[startIndex].line;
315
305
  let i = firstNonWhitespaceIndex;
316
306
  if (!token.label.saturated) {
317
- const linkLabelCollectResult = eatAndCollectLinkLabel(nodePoints, i, endIndex, token.label);
318
- if (linkLabelCollectResult.nextIndex < 0) {
307
+ const { nextIndex: labelEndIndex, state: labelState } = eatAndCollectLinkLabel(nodePoints, i, endIndex, token.label);
308
+ if (labelEndIndex < 0) {
319
309
  return { status: 'failedAndRollback', lines: token.lines };
320
310
  }
321
- const labelEndIndex = linkLabelCollectResult.nextIndex;
322
- if (!linkLabelCollectResult.token.saturated) {
311
+ if (!labelState.saturated) {
323
312
  token.lines.push(line);
324
313
  return { status: 'opening', nextIndex: endIndex };
325
314
  }
@@ -334,15 +323,13 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
334
323
  if (i >= endIndex) {
335
324
  return { status: 'failedAndRollback', lines: token.lines };
336
325
  }
337
- const linkDestinationCollectResult = eatAndCollectLinkDestination(nodePoints, i, endIndex, null);
338
- if (linkDestinationCollectResult.nextIndex < 0 ||
339
- !linkDestinationCollectResult.token.saturated) {
326
+ const { nextIndex: destinationEndIndex, state: destinationState } = eatAndCollectLinkDestination(nodePoints, i, endIndex, null);
327
+ if (destinationEndIndex < 0 || !destinationState.saturated) {
340
328
  return { status: 'failedAndRollback', lines: token.lines };
341
329
  }
342
- const destinationEndIndex = linkDestinationCollectResult.nextIndex;
343
330
  i = coreTokenizer.eatOptionalWhitespaces(nodePoints, destinationEndIndex, endIndex);
344
331
  if (i >= endIndex) {
345
- token.destination = linkDestinationCollectResult.token;
332
+ token.destination = destinationState;
346
333
  token.lines.push(line);
347
334
  return { status: 'opening', nextIndex: endIndex };
348
335
  }
@@ -352,12 +339,12 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
352
339
  if (token.lineNoOfTitle < 0) {
353
340
  token.lineNoOfTitle = lineNo;
354
341
  }
355
- const linkTitleCollectResult = eatAndCollectLinkTitle(nodePoints, i, endIndex, token.title);
356
- token.title = linkTitleCollectResult.token;
357
- if (linkTitleCollectResult.nextIndex < 0 ||
358
- linkTitleCollectResult.token.nodePoints.length <= 0 ||
359
- (linkTitleCollectResult.token.saturated &&
360
- coreTokenizer.eatOptionalWhitespaces(nodePoints, linkTitleCollectResult.nextIndex, endIndex) < endIndex)) {
342
+ const { nextIndex: titleEndIndex, state: titleState } = eatAndCollectLinkTitle(nodePoints, i, endIndex, token.title);
343
+ token.title = titleState;
344
+ if (titleEndIndex < 0 ||
345
+ titleState.nodePoints.length <= 0 ||
346
+ (titleState.saturated &&
347
+ coreTokenizer.eatOptionalWhitespaces(nodePoints, titleEndIndex, endIndex) < endIndex)) {
361
348
  if (token.lineNoOfDestination === token.lineNoOfTitle) {
362
349
  return { status: 'failedAndRollback', lines: token.lines };
363
350
  }
@@ -373,7 +360,7 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
373
360
  const saturated = (_a = token.title) === null || _a === void 0 ? void 0 : _a.saturated;
374
361
  return { status: saturated ? 'closing' : 'opening', nextIndex: endIndex };
375
362
  }
376
- onClose(token, api) {
363
+ function onClose(token) {
377
364
  let result;
378
365
  if (token.title == null || !token.title.saturated) {
379
366
  if (!token.label.saturated) {
@@ -401,31 +388,53 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
401
388
  token._identifier = identifier;
402
389
  return result;
403
390
  }
404
- parseBlock(token) {
405
- const label = token._label;
406
- const identifier = token._identifier;
407
- const destinationPoints = token.destination.nodePoints;
408
- const destination = destinationPoints[0].codePoint === character.AsciiCodePoint.OPEN_ANGLE
409
- ? character.calcEscapedStringFromNodePoints(destinationPoints, 1, destinationPoints.length - 1, true)
410
- : character.calcEscapedStringFromNodePoints(destinationPoints, 0, destinationPoints.length, true);
411
- const url = coreTokenizer.encodeLinkDestination(destination);
412
- const title = token.title == null
413
- ? undefined
414
- : character.calcEscapedStringFromNodePoints(token.title.nodePoints, 1, token.title.nodePoints.length - 1);
415
- const node = {
416
- type: ast.DefinitionType,
417
- identifier,
418
- label,
419
- url,
420
- title,
421
- };
422
- return node;
391
+ };
392
+
393
+ const parse = function () {
394
+ return {
395
+ parse: tokens => tokens.map(token => {
396
+ const label = token._label;
397
+ const identifier = token._identifier;
398
+ const destinationPoints = token.destination.nodePoints;
399
+ const destination = destinationPoints[0].codePoint === character.AsciiCodePoint.OPEN_ANGLE
400
+ ? character.calcEscapedStringFromNodePoints(destinationPoints, 1, destinationPoints.length - 1, true)
401
+ : character.calcEscapedStringFromNodePoints(destinationPoints, 0, destinationPoints.length, true);
402
+ const url = coreTokenizer.encodeLinkDestination(destination);
403
+ const title = token.title == null
404
+ ? undefined
405
+ : character.calcEscapedStringFromNodePoints(token.title.nodePoints, 1, token.title.nodePoints.length - 1);
406
+ const node = {
407
+ type: ast.DefinitionType,
408
+ position: token.position,
409
+ identifier,
410
+ label,
411
+ url,
412
+ title,
413
+ };
414
+ return node;
415
+ }),
416
+ };
417
+ };
418
+
419
+ const uniqueName = '@yozora/tokenizer-definition';
420
+
421
+ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
422
+ constructor(props = {}) {
423
+ var _a, _b;
424
+ super({
425
+ name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
426
+ priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
427
+ });
428
+ this.match = match;
429
+ this.parse = parse;
423
430
  }
424
431
  }
425
432
 
426
433
  exports.DefinitionTokenizer = DefinitionTokenizer;
427
434
  exports.DefinitionTokenizerName = uniqueName;
428
- exports['default'] = DefinitionTokenizer;
435
+ exports["default"] = DefinitionTokenizer;
436
+ exports.definitionMatch = match;
437
+ exports.definitionParse = parse;
429
438
  exports.eatAndCollectLinkDestination = eatAndCollectLinkDestination;
430
439
  exports.eatAndCollectLinkLabel = eatAndCollectLinkLabel;
431
440
  exports.eatAndCollectLinkTitle = eatAndCollectLinkTitle;