@yozora/tokenizer-definition 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 +149 -145
- package/lib/esm/index.js +148 -146
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +18 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -38
- package/lib/types/types.d.ts +7 -6
- package/lib/types/util/link-destination.d.ts +5 -5
- package/lib/types/util/link-label.d.ts +5 -5
- package/lib/types/util/link-title.d.ts +5 -5
- package/package.json +5 -5
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 DefinitionTokenizer from '@yozora/tokenizer-definition'
|
|
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 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
|
-
|
|
10
|
-
|
|
11
|
-
function eatAndCollectLinkDestination(nodePoints, startIndex, endIndex, token) {
|
|
9
|
+
function eatAndCollectLinkDestination(nodePoints, startIndex, endIndex, state) {
|
|
12
10
|
let i = startIndex;
|
|
13
|
-
if (
|
|
14
|
-
|
|
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,
|
|
24
|
-
if (
|
|
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
|
-
|
|
30
|
-
|
|
27
|
+
state.hasOpenAngleBracket = true;
|
|
28
|
+
state.nodePoints.push(p);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
if (
|
|
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
|
-
|
|
40
|
-
|
|
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,
|
|
44
|
+
return { nextIndex: -1, state: state };
|
|
47
45
|
case character.AsciiCodePoint.CLOSE_ANGLE:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return { nextIndex: i + 1,
|
|
46
|
+
state.saturated = true;
|
|
47
|
+
state.nodePoints.push(p);
|
|
48
|
+
return { nextIndex: i + 1, state: state };
|
|
51
49
|
default:
|
|
52
|
-
|
|
50
|
+
state.nodePoints.push(p);
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
return { nextIndex: i,
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
69
|
-
|
|
66
|
+
state.openParensCount += 1;
|
|
67
|
+
state.nodePoints.push(p);
|
|
70
68
|
break;
|
|
71
69
|
case character.AsciiCodePoint.CLOSE_PARENTHESIS:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
return { nextIndex: i,
|
|
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
|
-
|
|
81
|
-
|
|
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
|
-
|
|
81
|
+
state.nodePoints.push(p);
|
|
85
82
|
break;
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
|
-
|
|
89
|
-
return { nextIndex: i,
|
|
85
|
+
state.saturated = true;
|
|
86
|
+
return { nextIndex: i, state: state };
|
|
90
87
|
}
|
|
91
88
|
|
|
92
|
-
function eatAndCollectLinkLabel(nodePoints, startIndex, endIndex,
|
|
89
|
+
function eatAndCollectLinkLabel(nodePoints, startIndex, endIndex, state) {
|
|
93
90
|
let i = startIndex;
|
|
94
|
-
if (
|
|
95
|
-
|
|
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,
|
|
104
|
-
if (
|
|
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,
|
|
105
|
+
return { nextIndex: -1, state: state };
|
|
109
106
|
}
|
|
110
107
|
i += 1;
|
|
111
|
-
|
|
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
|
-
|
|
114
|
+
state.hasNonWhitespaceCharacter = true;
|
|
118
115
|
if (i + 1 < endIndex) {
|
|
119
|
-
|
|
120
|
-
|
|
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,
|
|
122
|
+
return { nextIndex: -1, state: state };
|
|
126
123
|
case character.AsciiCodePoint.CLOSE_BRACKET:
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
return { nextIndex: i + 1,
|
|
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,
|
|
129
|
+
return { nextIndex: -1, state: state };
|
|
133
130
|
default:
|
|
134
131
|
if (!character.isWhitespaceCharacter(p.codePoint)) {
|
|
135
|
-
|
|
132
|
+
state.hasNonWhitespaceCharacter = true;
|
|
136
133
|
}
|
|
137
|
-
|
|
134
|
+
state.nodePoints.push(p);
|
|
138
135
|
}
|
|
139
136
|
}
|
|
140
|
-
return { nextIndex: 1,
|
|
137
|
+
return { nextIndex: 1, state: state };
|
|
141
138
|
}
|
|
142
139
|
|
|
143
|
-
function eatAndCollectLinkTitle(nodePoints, startIndex, endIndex,
|
|
140
|
+
function eatAndCollectLinkTitle(nodePoints, startIndex, endIndex, state) {
|
|
144
141
|
let i = startIndex;
|
|
145
|
-
if (
|
|
146
|
-
|
|
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,
|
|
155
|
-
if (
|
|
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
|
-
|
|
163
|
-
|
|
159
|
+
state.wrapSymbol = p.codePoint;
|
|
160
|
+
state.nodePoints.push(p);
|
|
164
161
|
i += 1;
|
|
165
162
|
break;
|
|
166
163
|
default:
|
|
167
|
-
return { nextIndex: -1,
|
|
164
|
+
return { nextIndex: -1, state: state };
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
|
-
if (
|
|
171
|
-
return { nextIndex: -1,
|
|
172
|
-
switch (
|
|
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
|
-
|
|
181
|
-
|
|
177
|
+
state.nodePoints.push(p);
|
|
178
|
+
state.nodePoints.push(nodePoints[i + 1]);
|
|
182
179
|
}
|
|
183
180
|
i += 1;
|
|
184
181
|
break;
|
|
185
|
-
case
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return { nextIndex: i + 1,
|
|
182
|
+
case state.wrapSymbol:
|
|
183
|
+
state.saturated = true;
|
|
184
|
+
state.nodePoints.push(p);
|
|
185
|
+
return { nextIndex: i + 1, state: state };
|
|
189
186
|
default:
|
|
190
|
-
|
|
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
|
-
|
|
202
|
-
|
|
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,
|
|
204
|
+
return { nextIndex: -1, state: state };
|
|
208
205
|
case character.AsciiCodePoint.CLOSE_PARENTHESIS:
|
|
209
|
-
if (i + 1 >= endIndex ||
|
|
210
|
-
nodePoints
|
|
211
|
-
|
|
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,
|
|
211
|
+
return { nextIndex: -1, state: state };
|
|
216
212
|
default:
|
|
217
|
-
|
|
213
|
+
state.nodePoints.push(p);
|
|
218
214
|
}
|
|
219
215
|
}
|
|
220
216
|
break;
|
|
221
217
|
}
|
|
222
218
|
}
|
|
223
|
-
return { nextIndex: endIndex,
|
|
219
|
+
return { nextIndex: endIndex, state: state };
|
|
224
220
|
}
|
|
225
221
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
|
243
|
-
if (
|
|
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:
|
|
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 (!
|
|
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
|
|
278
|
-
if (
|
|
270
|
+
const { nextIndex: destinationEndIndex, state: destinationState } = eatAndCollectLinkDestination(nodePoints, i, endIndex, null);
|
|
271
|
+
if (destinationEndIndex < 0)
|
|
279
272
|
return null;
|
|
280
|
-
if (!
|
|
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 =
|
|
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
|
|
294
|
-
if (
|
|
295
|
-
i =
|
|
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 =
|
|
304
|
-
token.title =
|
|
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
|
|
318
|
-
if (
|
|
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
|
-
|
|
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
|
|
338
|
-
if (
|
|
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 =
|
|
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
|
|
356
|
-
token.title =
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
(
|
|
360
|
-
coreTokenizer.eatOptionalWhitespaces(nodePoints,
|
|
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
|
|
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,48 @@ class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
401
388
|
token._identifier = identifier;
|
|
402
389
|
return result;
|
|
403
390
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const parse = function (api) {
|
|
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 = api.shouldReservePosition
|
|
407
|
+
? { type: ast.DefinitionType, position: token.position, identifier, label, url, title }
|
|
408
|
+
: { type: ast.DefinitionType, identifier, label, url, title };
|
|
409
|
+
return node;
|
|
410
|
+
}),
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
const uniqueName = '@yozora/tokenizer-definition';
|
|
415
|
+
|
|
416
|
+
class DefinitionTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
417
|
+
constructor(props = {}) {
|
|
418
|
+
var _a, _b;
|
|
419
|
+
super({
|
|
420
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
421
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
|
|
422
|
+
});
|
|
423
|
+
this.match = match;
|
|
424
|
+
this.parse = parse;
|
|
423
425
|
}
|
|
424
426
|
}
|
|
425
427
|
|
|
426
428
|
exports.DefinitionTokenizer = DefinitionTokenizer;
|
|
427
429
|
exports.DefinitionTokenizerName = uniqueName;
|
|
428
|
-
exports[
|
|
430
|
+
exports["default"] = DefinitionTokenizer;
|
|
431
|
+
exports.definitionMatch = match;
|
|
432
|
+
exports.definitionParse = parse;
|
|
429
433
|
exports.eatAndCollectLinkDestination = eatAndCollectLinkDestination;
|
|
430
434
|
exports.eatAndCollectLinkLabel = eatAndCollectLinkLabel;
|
|
431
435
|
exports.eatAndCollectLinkTitle = eatAndCollectLinkTitle;
|