@yozora/tokenizer-html-inline 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 +60 -44
- package/lib/esm/index.js +59 -45
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +11 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -29
- package/lib/types/types.d.ts +12 -11
- package/lib/types/util/cdata.d.ts +6 -6
- package/lib/types/util/closing.d.ts +7 -7
- package/lib/types/util/comment.d.ts +6 -6
- package/lib/types/util/declaration.d.ts +7 -7
- package/lib/types/util/instruction.d.ts +6 -6
- package/lib/types/util/open.d.ts +7 -7
- 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 HtmlInlineTokenizer from '@yozora/tokenizer-html-inline'
|
|
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 HtmlInlineTokenizer())
|
|
96
96
|
|
|
97
97
|
// parse source markdown content
|
|
@@ -229,7 +229,6 @@ Name | Type | Required | Default
|
|
|
229
229
|
[@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
|
|
230
230
|
[@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
|
|
231
231
|
[@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
|
|
232
|
-
[@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
|
|
233
232
|
[@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
|
|
234
233
|
[@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
|
|
235
234
|
[@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
|
|
@@ -289,7 +288,6 @@ Name | Type | Required | Default
|
|
|
289
288
|
[doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
|
|
290
289
|
[doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
|
|
291
290
|
[doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
|
|
292
|
-
[doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
|
|
293
291
|
[doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
|
|
294
292
|
[doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
|
|
295
293
|
[doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
|
package/lib/cjs/index.js
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
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');
|
|
8
7
|
var tokenizerHtmlBlock = require('@yozora/tokenizer-html-block');
|
|
9
|
-
|
|
10
|
-
const uniqueName = '@yozora/tokenizer-html-inline';
|
|
8
|
+
var ast = require('@yozora/ast');
|
|
11
9
|
|
|
12
10
|
function eatHtmlInlineCDataDelimiter(nodePoints, startIndex, endIndex) {
|
|
13
11
|
let i = startIndex;
|
|
@@ -108,8 +106,7 @@ function eatHtmlInlineCommentDelimiter(nodePoints, startIndex, endIndex) {
|
|
|
108
106
|
|
|
109
107
|
function eatHtmlInlineDeclarationDelimiter(nodePoints, startIndex, endIndex) {
|
|
110
108
|
let i = startIndex;
|
|
111
|
-
if (i + 4 >= endIndex ||
|
|
112
|
-
nodePoints[i + 1].codePoint !== character.AsciiCodePoint.EXCLAMATION_MARK)
|
|
109
|
+
if (i + 4 >= endIndex || nodePoints[i + 1].codePoint !== character.AsciiCodePoint.EXCLAMATION_MARK)
|
|
113
110
|
return null;
|
|
114
111
|
const tagNameStartIndex = i + 2;
|
|
115
112
|
for (i = tagNameStartIndex; i < endIndex; ++i) {
|
|
@@ -143,8 +140,7 @@ function eatHtmlInlineDeclarationDelimiter(nodePoints, startIndex, endIndex) {
|
|
|
143
140
|
|
|
144
141
|
function eatHtmlInlineInstructionDelimiter(nodePoints, startIndex, endIndex) {
|
|
145
142
|
let i = startIndex;
|
|
146
|
-
if (i + 3 >= endIndex ||
|
|
147
|
-
nodePoints[i + 1].codePoint !== character.AsciiCodePoint.QUESTION_MARK)
|
|
143
|
+
if (i + 3 >= endIndex || nodePoints[i + 1].codePoint !== character.AsciiCodePoint.QUESTION_MARK)
|
|
148
144
|
return null;
|
|
149
145
|
const si = i + 2;
|
|
150
146
|
for (i = si; i < endIndex; ++i) {
|
|
@@ -207,15 +203,12 @@ function eatHtmlInlineTokenOpenDelimiter(nodePoints, startIndex, endIndex) {
|
|
|
207
203
|
return delimiter;
|
|
208
204
|
}
|
|
209
205
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
_findDelimiter(startIndex, endIndex, api) {
|
|
206
|
+
const match = function (api) {
|
|
207
|
+
return {
|
|
208
|
+
findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
|
|
209
|
+
processSingleDelimiter,
|
|
210
|
+
};
|
|
211
|
+
function _findDelimiter(startIndex, endIndex) {
|
|
219
212
|
const nodePoints = api.getNodePoints();
|
|
220
213
|
for (let i = startIndex; i < endIndex; ++i) {
|
|
221
214
|
i = coreTokenizer.eatOptionalWhitespaces(nodePoints, i, endIndex);
|
|
@@ -227,7 +220,7 @@ class HtmlInlineTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
227
220
|
i += 1;
|
|
228
221
|
break;
|
|
229
222
|
case character.AsciiCodePoint.OPEN_ANGLE: {
|
|
230
|
-
const delimiter =
|
|
223
|
+
const delimiter = tryToEatDelimiter(nodePoints, i, endIndex);
|
|
231
224
|
if (delimiter != null)
|
|
232
225
|
return delimiter;
|
|
233
226
|
break;
|
|
@@ -236,45 +229,68 @@ class HtmlInlineTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
|
236
229
|
}
|
|
237
230
|
return null;
|
|
238
231
|
}
|
|
239
|
-
processSingleDelimiter(delimiter) {
|
|
232
|
+
function processSingleDelimiter(delimiter) {
|
|
240
233
|
const token = Object.assign(Object.assign({}, delimiter), { nodeType: ast.HtmlType });
|
|
241
234
|
return [token];
|
|
242
235
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return delimiter;
|
|
261
|
-
delimiter = eatHtmlInlineInstructionDelimiter(nodePoints, startIndex, endIndex);
|
|
262
|
-
if (delimiter != null)
|
|
263
|
-
return delimiter;
|
|
264
|
-
delimiter = eatHtmlInlineDeclarationDelimiter(nodePoints, startIndex, endIndex);
|
|
265
|
-
if (delimiter != null)
|
|
266
|
-
return delimiter;
|
|
267
|
-
delimiter = eatHtmlInlineCDataDelimiter(nodePoints, startIndex, endIndex);
|
|
236
|
+
};
|
|
237
|
+
function tryToEatDelimiter(nodePoints, startIndex, endIndex) {
|
|
238
|
+
let delimiter = null;
|
|
239
|
+
delimiter = eatHtmlInlineTokenOpenDelimiter(nodePoints, startIndex, endIndex);
|
|
240
|
+
if (delimiter != null)
|
|
241
|
+
return delimiter;
|
|
242
|
+
delimiter = eatHtmlInlineClosingDelimiter(nodePoints, startIndex, endIndex);
|
|
243
|
+
if (delimiter != null)
|
|
244
|
+
return delimiter;
|
|
245
|
+
delimiter = eatHtmlInlineCommentDelimiter(nodePoints, startIndex, endIndex);
|
|
246
|
+
if (delimiter != null)
|
|
247
|
+
return delimiter;
|
|
248
|
+
delimiter = eatHtmlInlineInstructionDelimiter(nodePoints, startIndex, endIndex);
|
|
249
|
+
if (delimiter != null)
|
|
250
|
+
return delimiter;
|
|
251
|
+
delimiter = eatHtmlInlineDeclarationDelimiter(nodePoints, startIndex, endIndex);
|
|
252
|
+
if (delimiter != null)
|
|
268
253
|
return delimiter;
|
|
254
|
+
delimiter = eatHtmlInlineCDataDelimiter(nodePoints, startIndex, endIndex);
|
|
255
|
+
return delimiter;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const parse = function (api) {
|
|
259
|
+
return {
|
|
260
|
+
parse: tokens => tokens.map(token => {
|
|
261
|
+
const { startIndex, endIndex } = token;
|
|
262
|
+
const nodePoints = api.getNodePoints();
|
|
263
|
+
const value = character.calcStringFromNodePoints(nodePoints, startIndex, endIndex);
|
|
264
|
+
const node = api.shouldReservePosition
|
|
265
|
+
? { type: ast.HtmlType, position: api.calcPosition(token), value }
|
|
266
|
+
: { type: ast.HtmlType, value };
|
|
267
|
+
return node;
|
|
268
|
+
}),
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const uniqueName = '@yozora/tokenizer-html-inline';
|
|
273
|
+
|
|
274
|
+
class HtmlInlineTokenizer extends coreTokenizer.BaseInlineTokenizer {
|
|
275
|
+
constructor(props = {}) {
|
|
276
|
+
var _a, _b;
|
|
277
|
+
super({
|
|
278
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
279
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
|
|
280
|
+
});
|
|
281
|
+
this.match = match;
|
|
282
|
+
this.parse = parse;
|
|
269
283
|
}
|
|
270
284
|
}
|
|
271
285
|
|
|
272
286
|
exports.HtmlInlineTokenizer = HtmlInlineTokenizer;
|
|
273
287
|
exports.HtmlInlineTokenizerName = uniqueName;
|
|
274
|
-
exports[
|
|
288
|
+
exports["default"] = HtmlInlineTokenizer;
|
|
275
289
|
exports.eatHtmlInlineCDataDelimiter = eatHtmlInlineCDataDelimiter;
|
|
276
290
|
exports.eatHtmlInlineClosingDelimiter = eatHtmlInlineClosingDelimiter;
|
|
277
291
|
exports.eatHtmlInlineCommentDelimiter = eatHtmlInlineCommentDelimiter;
|
|
278
292
|
exports.eatHtmlInlineDeclarationDelimiter = eatHtmlInlineDeclarationDelimiter;
|
|
279
293
|
exports.eatHtmlInlineInstructionDelimiter = eatHtmlInlineInstructionDelimiter;
|
|
280
294
|
exports.eatHtmlInlineTokenOpenDelimiter = eatHtmlInlineTokenOpenDelimiter;
|
|
295
|
+
exports.htmlInlineMatch = match;
|
|
296
|
+
exports.htmlInlineParse = parse;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { HtmlType } from '@yozora/ast';
|
|
2
1
|
import { AsciiCodePoint, isAsciiUpperLetter, isWhitespaceCharacter, calcStringFromNodePoints } from '@yozora/character';
|
|
3
|
-
import { eatOptionalWhitespaces, BaseInlineTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
2
|
+
import { eatOptionalWhitespaces, genFindDelimiter, BaseInlineTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
4
3
|
import { eatHTMLTagName, eatHTMLAttribute } from '@yozora/tokenizer-html-block';
|
|
5
|
-
|
|
6
|
-
const uniqueName = '@yozora/tokenizer-html-inline';
|
|
4
|
+
import { HtmlType } from '@yozora/ast';
|
|
7
5
|
|
|
8
6
|
function eatHtmlInlineCDataDelimiter(nodePoints, startIndex, endIndex) {
|
|
9
7
|
let i = startIndex;
|
|
@@ -104,8 +102,7 @@ function eatHtmlInlineCommentDelimiter(nodePoints, startIndex, endIndex) {
|
|
|
104
102
|
|
|
105
103
|
function eatHtmlInlineDeclarationDelimiter(nodePoints, startIndex, endIndex) {
|
|
106
104
|
let i = startIndex;
|
|
107
|
-
if (i + 4 >= endIndex ||
|
|
108
|
-
nodePoints[i + 1].codePoint !== AsciiCodePoint.EXCLAMATION_MARK)
|
|
105
|
+
if (i + 4 >= endIndex || nodePoints[i + 1].codePoint !== AsciiCodePoint.EXCLAMATION_MARK)
|
|
109
106
|
return null;
|
|
110
107
|
const tagNameStartIndex = i + 2;
|
|
111
108
|
for (i = tagNameStartIndex; i < endIndex; ++i) {
|
|
@@ -139,8 +136,7 @@ function eatHtmlInlineDeclarationDelimiter(nodePoints, startIndex, endIndex) {
|
|
|
139
136
|
|
|
140
137
|
function eatHtmlInlineInstructionDelimiter(nodePoints, startIndex, endIndex) {
|
|
141
138
|
let i = startIndex;
|
|
142
|
-
if (i + 3 >= endIndex ||
|
|
143
|
-
nodePoints[i + 1].codePoint !== AsciiCodePoint.QUESTION_MARK)
|
|
139
|
+
if (i + 3 >= endIndex || nodePoints[i + 1].codePoint !== AsciiCodePoint.QUESTION_MARK)
|
|
144
140
|
return null;
|
|
145
141
|
const si = i + 2;
|
|
146
142
|
for (i = si; i < endIndex; ++i) {
|
|
@@ -203,15 +199,12 @@ function eatHtmlInlineTokenOpenDelimiter(nodePoints, startIndex, endIndex) {
|
|
|
203
199
|
return delimiter;
|
|
204
200
|
}
|
|
205
201
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
_findDelimiter(startIndex, endIndex, api) {
|
|
202
|
+
const match = function (api) {
|
|
203
|
+
return {
|
|
204
|
+
findDelimiter: () => genFindDelimiter(_findDelimiter),
|
|
205
|
+
processSingleDelimiter,
|
|
206
|
+
};
|
|
207
|
+
function _findDelimiter(startIndex, endIndex) {
|
|
215
208
|
const nodePoints = api.getNodePoints();
|
|
216
209
|
for (let i = startIndex; i < endIndex; ++i) {
|
|
217
210
|
i = eatOptionalWhitespaces(nodePoints, i, endIndex);
|
|
@@ -223,7 +216,7 @@ class HtmlInlineTokenizer extends BaseInlineTokenizer {
|
|
|
223
216
|
i += 1;
|
|
224
217
|
break;
|
|
225
218
|
case AsciiCodePoint.OPEN_ANGLE: {
|
|
226
|
-
const delimiter =
|
|
219
|
+
const delimiter = tryToEatDelimiter(nodePoints, i, endIndex);
|
|
227
220
|
if (delimiter != null)
|
|
228
221
|
return delimiter;
|
|
229
222
|
break;
|
|
@@ -232,37 +225,58 @@ class HtmlInlineTokenizer extends BaseInlineTokenizer {
|
|
|
232
225
|
}
|
|
233
226
|
return null;
|
|
234
227
|
}
|
|
235
|
-
processSingleDelimiter(delimiter) {
|
|
228
|
+
function processSingleDelimiter(delimiter) {
|
|
236
229
|
const token = Object.assign(Object.assign({}, delimiter), { nodeType: HtmlType });
|
|
237
230
|
return [token];
|
|
238
231
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return delimiter;
|
|
257
|
-
delimiter = eatHtmlInlineInstructionDelimiter(nodePoints, startIndex, endIndex);
|
|
258
|
-
if (delimiter != null)
|
|
259
|
-
return delimiter;
|
|
260
|
-
delimiter = eatHtmlInlineDeclarationDelimiter(nodePoints, startIndex, endIndex);
|
|
261
|
-
if (delimiter != null)
|
|
262
|
-
return delimiter;
|
|
263
|
-
delimiter = eatHtmlInlineCDataDelimiter(nodePoints, startIndex, endIndex);
|
|
232
|
+
};
|
|
233
|
+
function tryToEatDelimiter(nodePoints, startIndex, endIndex) {
|
|
234
|
+
let delimiter = null;
|
|
235
|
+
delimiter = eatHtmlInlineTokenOpenDelimiter(nodePoints, startIndex, endIndex);
|
|
236
|
+
if (delimiter != null)
|
|
237
|
+
return delimiter;
|
|
238
|
+
delimiter = eatHtmlInlineClosingDelimiter(nodePoints, startIndex, endIndex);
|
|
239
|
+
if (delimiter != null)
|
|
240
|
+
return delimiter;
|
|
241
|
+
delimiter = eatHtmlInlineCommentDelimiter(nodePoints, startIndex, endIndex);
|
|
242
|
+
if (delimiter != null)
|
|
243
|
+
return delimiter;
|
|
244
|
+
delimiter = eatHtmlInlineInstructionDelimiter(nodePoints, startIndex, endIndex);
|
|
245
|
+
if (delimiter != null)
|
|
246
|
+
return delimiter;
|
|
247
|
+
delimiter = eatHtmlInlineDeclarationDelimiter(nodePoints, startIndex, endIndex);
|
|
248
|
+
if (delimiter != null)
|
|
264
249
|
return delimiter;
|
|
250
|
+
delimiter = eatHtmlInlineCDataDelimiter(nodePoints, startIndex, endIndex);
|
|
251
|
+
return delimiter;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const parse = function (api) {
|
|
255
|
+
return {
|
|
256
|
+
parse: tokens => tokens.map(token => {
|
|
257
|
+
const { startIndex, endIndex } = token;
|
|
258
|
+
const nodePoints = api.getNodePoints();
|
|
259
|
+
const value = calcStringFromNodePoints(nodePoints, startIndex, endIndex);
|
|
260
|
+
const node = api.shouldReservePosition
|
|
261
|
+
? { type: HtmlType, position: api.calcPosition(token), value }
|
|
262
|
+
: { type: HtmlType, value };
|
|
263
|
+
return node;
|
|
264
|
+
}),
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const uniqueName = '@yozora/tokenizer-html-inline';
|
|
269
|
+
|
|
270
|
+
class HtmlInlineTokenizer extends BaseInlineTokenizer {
|
|
271
|
+
constructor(props = {}) {
|
|
272
|
+
var _a, _b;
|
|
273
|
+
super({
|
|
274
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
275
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.ATOMIC,
|
|
276
|
+
});
|
|
277
|
+
this.match = match;
|
|
278
|
+
this.parse = parse;
|
|
265
279
|
}
|
|
266
280
|
}
|
|
267
281
|
|
|
268
|
-
export { HtmlInlineTokenizer, uniqueName as HtmlInlineTokenizerName, HtmlInlineTokenizer as default, eatHtmlInlineCDataDelimiter, eatHtmlInlineClosingDelimiter, eatHtmlInlineCommentDelimiter, eatHtmlInlineDeclarationDelimiter, eatHtmlInlineInstructionDelimiter, eatHtmlInlineTokenOpenDelimiter };
|
|
282
|
+
export { HtmlInlineTokenizer, uniqueName as HtmlInlineTokenizerName, HtmlInlineTokenizer as default, eatHtmlInlineCDataDelimiter, eatHtmlInlineClosingDelimiter, eatHtmlInlineCommentDelimiter, eatHtmlInlineDeclarationDelimiter, eatHtmlInlineInstructionDelimiter, eatHtmlInlineTokenOpenDelimiter, match as htmlInlineMatch, parse as htmlInlineParse };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { HtmlInlineTokenizer } from './tokenizer';
|
|
2
1
|
export * from './util/cdata';
|
|
3
2
|
export * from './util/closing';
|
|
4
3
|
export * from './util/comment';
|
|
5
4
|
export * from './util/declaration';
|
|
6
5
|
export * from './util/instruction';
|
|
7
6
|
export * from './util/open';
|
|
8
|
-
export {
|
|
7
|
+
export { match as htmlInlineMatch } from './match';
|
|
8
|
+
export { parse as htmlInlineParse } from './parse';
|
|
9
|
+
export { HtmlInlineTokenizer, HtmlInlineTokenizer as default } from './tokenizer';
|
|
9
10
|
export { uniqueName as HtmlInlineTokenizerName } from './types';
|
|
10
|
-
export type {
|
|
11
|
-
export default HtmlInlineTokenizer;
|
|
11
|
+
export type { IThis as IHtmlInlineHookContext, IToken as IHtmlInlineToken, ITokenizerProps as IHtmlInlineTokenizerProps, } from './types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IMatchInlineHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IDelimiter, IThis, IToken, T } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Text between '<' and '>' that looks like an HTML tag is parsed as a raw HTML
|
|
5
|
+
* tag and will be rendered in HTML without escaping. Tag and attribute names
|
|
6
|
+
* are not limited to current HTML tags, so custom tags (and even, say, DocBook
|
|
7
|
+
* tags) may be used.
|
|
8
|
+
*
|
|
9
|
+
* @see https://github.github.com/gfm/#raw-html
|
|
10
|
+
*/
|
|
11
|
+
export declare const match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { NodePoint } from '@yozora/character';
|
|
3
|
-
import type { MatchInlinePhaseApi, ParseInlinePhaseApi, ResultOfProcessSingleDelimiter, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook } 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 HtmlInline.
|
|
8
6
|
*
|
|
@@ -13,29 +11,8 @@ import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
|
|
|
13
11
|
*
|
|
14
12
|
* @see https://github.github.com/gfm/#raw-html
|
|
15
13
|
*/
|
|
16
|
-
export declare class HtmlInlineTokenizer extends BaseInlineTokenizer<
|
|
17
|
-
constructor(props?:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @see BaseInlineTokenizer
|
|
21
|
-
*/
|
|
22
|
-
protected _findDelimiter(startIndex: number, endIndex: number, api: Readonly<MatchInlinePhaseApi>): Delimiter | null;
|
|
23
|
-
/**
|
|
24
|
-
* @override
|
|
25
|
-
* @see TokenizerMatchInlineHook
|
|
26
|
-
*/
|
|
27
|
-
processSingleDelimiter(delimiter: Delimiter): ResultOfProcessSingleDelimiter<T, Token>;
|
|
28
|
-
/**
|
|
29
|
-
* @override
|
|
30
|
-
* @see TokenizerParseInlineHook
|
|
31
|
-
*/
|
|
32
|
-
parseInline(token: Token, children: YastNode[], api: Readonly<ParseInlinePhaseApi>): Node;
|
|
33
|
-
/**
|
|
34
|
-
* Try to eat a delimiter
|
|
35
|
-
*
|
|
36
|
-
* @param nodePoints
|
|
37
|
-
* @param startIndex
|
|
38
|
-
* @param endIndex
|
|
39
|
-
*/
|
|
40
|
-
protected tryToEatDelimiter(nodePoints: ReadonlyArray<NodePoint>, startIndex: number, endIndex: number): Delimiter | null;
|
|
14
|
+
export declare class HtmlInlineTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode, IThis> implements IInlineTokenizer<T, IDelimiter, IToken, INode, IThis> {
|
|
15
|
+
constructor(props?: ITokenizerProps);
|
|
16
|
+
readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
|
|
17
|
+
readonly parse: IParseInlineHookCreator<T, IToken, INode, IThis>;
|
|
41
18
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Html, HtmlType } from '@yozora/ast';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
2
|
+
import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, ITokenizer } from '@yozora/core-tokenizer';
|
|
3
|
+
import type { IHtmlInlineCDataDelimiter, IHtmlInlineCDataTokenData } from './util/cdata';
|
|
4
|
+
import type { IHtmlInlineClosingDelimiter, IHtmlInlineClosingTokenData } from './util/closing';
|
|
5
|
+
import type { IHtmlInlineCommentDelimiter, IHtmlInlineCommentTokenData } from './util/comment';
|
|
6
|
+
import type { IHtmlInlineDeclarationDelimiter, IHtmlInlineDeclarationTokenData } from './util/declaration';
|
|
7
|
+
import type { IHtmlInlineInstructionDelimiter, IHtmlInlineInstructionTokenData } from './util/instruction';
|
|
8
|
+
import type { IHtmlInlineOpenDelimiter, IHtmlInlineOpenTokenData as IHtmlInlineOpenTokenData } from './util/open';
|
|
9
9
|
export declare type T = HtmlType;
|
|
10
|
-
export declare type
|
|
10
|
+
export declare type INode = Html;
|
|
11
11
|
export declare const uniqueName = "@yozora/tokenizer-html-inline";
|
|
12
12
|
/**
|
|
13
13
|
* Text between '<' and '>' that looks like an HTML tag is parsed as a raw
|
|
@@ -17,6 +17,7 @@ export declare const uniqueName = "@yozora/tokenizer-html-inline";
|
|
|
17
17
|
*
|
|
18
18
|
* @see https://github.github.com/gfm/#raw-html
|
|
19
19
|
*/
|
|
20
|
-
export declare type
|
|
21
|
-
export declare type
|
|
22
|
-
export declare type
|
|
20
|
+
export declare type IToken = IPartialYastInlineToken<T> & (IHtmlInlineOpenTokenData | IHtmlInlineClosingTokenData | IHtmlInlineCommentTokenData | IHtmlInlineInstructionTokenData | IHtmlInlineDeclarationTokenData | IHtmlInlineCDataTokenData);
|
|
21
|
+
export declare type IDelimiter = IHtmlInlineOpenDelimiter | IHtmlInlineClosingDelimiter | IHtmlInlineCommentDelimiter | IHtmlInlineInstructionDelimiter | IHtmlInlineDeclarationDelimiter | IHtmlInlineCDataDelimiter;
|
|
22
|
+
export declare type IThis = ITokenizer;
|
|
23
|
+
export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
export interface
|
|
1
|
+
import type { INodePoint } from '@yozora/character';
|
|
2
|
+
import type { IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
|
+
export interface IHtmlInlineCDataData {
|
|
4
4
|
htmlType: 'cdata';
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface IHtmlInlineCDataTokenData {
|
|
7
7
|
htmlType: 'cdata';
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface IHtmlInlineCDataDelimiter extends IYastTokenDelimiter, IHtmlInlineCDataTokenData {
|
|
10
10
|
type: 'full';
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -18,4 +18,4 @@ export interface HtmlInlineCDataDelimiter extends YastTokenDelimiter, HtmlInline
|
|
|
18
18
|
* @param endIndex
|
|
19
19
|
* @see https://github.github.com/gfm/#cdata-section
|
|
20
20
|
*/
|
|
21
|
-
export declare function eatHtmlInlineCDataDelimiter(nodePoints: ReadonlyArray<
|
|
21
|
+
export declare function eatHtmlInlineCDataDelimiter(nodePoints: ReadonlyArray<INodePoint>, startIndex: number, endIndex: number): IHtmlInlineCDataDelimiter | null;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
export interface
|
|
1
|
+
import type { INodeInterval, INodePoint } from '@yozora/character';
|
|
2
|
+
import type { IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
|
+
export interface IHtmlInlineClosingTagData {
|
|
4
4
|
htmlType: 'closing';
|
|
5
5
|
tagName: string;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
7
|
+
export interface IHtmlInlineClosingTokenData {
|
|
8
8
|
htmlType: 'closing';
|
|
9
|
-
tagName:
|
|
9
|
+
tagName: INodeInterval;
|
|
10
10
|
}
|
|
11
|
-
export interface
|
|
11
|
+
export interface IHtmlInlineClosingDelimiter extends IYastTokenDelimiter, IHtmlInlineClosingTokenData {
|
|
12
12
|
type: 'full';
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
@@ -20,4 +20,4 @@ export interface HtmlInlineClosingDelimiter extends YastTokenDelimiter, HtmlInli
|
|
|
20
20
|
* @param endIndex
|
|
21
21
|
* @see https://github.github.com/gfm/#closing-tag
|
|
22
22
|
*/
|
|
23
|
-
export declare function eatHtmlInlineClosingDelimiter(nodePoints: ReadonlyArray<
|
|
23
|
+
export declare function eatHtmlInlineClosingDelimiter(nodePoints: ReadonlyArray<INodePoint>, startIndex: number, endIndex: number): IHtmlInlineClosingDelimiter | null;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
export interface
|
|
1
|
+
import type { INodePoint } from '@yozora/character';
|
|
2
|
+
import type { IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
|
+
export interface IHtmlInlineCommentData {
|
|
4
4
|
htmlType: 'comment';
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface IHtmlInlineCommentTokenData {
|
|
7
7
|
htmlType: 'comment';
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface IHtmlInlineCommentDelimiter extends IYastTokenDelimiter, IHtmlInlineCommentTokenData {
|
|
10
10
|
type: 'full';
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -18,4 +18,4 @@ export interface HtmlInlineCommentDelimiter extends YastTokenDelimiter, HtmlInli
|
|
|
18
18
|
* @param endIndex
|
|
19
19
|
* @see https://github.github.com/gfm/#html-comment
|
|
20
20
|
*/
|
|
21
|
-
export declare function eatHtmlInlineCommentDelimiter(nodePoints: ReadonlyArray<
|
|
21
|
+
export declare function eatHtmlInlineCommentDelimiter(nodePoints: ReadonlyArray<INodePoint>, startIndex: number, endIndex: number): IHtmlInlineCommentDelimiter | null;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
export interface
|
|
1
|
+
import type { INodeInterval, INodePoint } from '@yozora/character';
|
|
2
|
+
import type { IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
|
+
export interface IHtmlInlineDeclarationData {
|
|
4
4
|
htmlType: 'declaration';
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface IHtmlInlineDeclarationTokenData {
|
|
7
7
|
htmlType: 'declaration';
|
|
8
|
-
tagName:
|
|
8
|
+
tagName: INodeInterval;
|
|
9
9
|
}
|
|
10
|
-
export interface
|
|
10
|
+
export interface IHtmlInlineDeclarationDelimiter extends IYastTokenDelimiter, IHtmlInlineDeclarationTokenData {
|
|
11
11
|
type: 'full';
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
@@ -20,4 +20,4 @@ export interface HtmlInlineDeclarationDelimiter extends YastTokenDelimiter, Html
|
|
|
20
20
|
* @param endIndex
|
|
21
21
|
* @see https://github.github.com/gfm/#declaration
|
|
22
22
|
*/
|
|
23
|
-
export declare function eatHtmlInlineDeclarationDelimiter(nodePoints: ReadonlyArray<
|
|
23
|
+
export declare function eatHtmlInlineDeclarationDelimiter(nodePoints: ReadonlyArray<INodePoint>, startIndex: number, endIndex: number): IHtmlInlineDeclarationDelimiter | null;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { INodePoint } from '@yozora/character';
|
|
2
|
+
import type { IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
5
|
* @see https://github.github.com/gfm/#processing-instruction
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface IHtmlInlineInstructionData {
|
|
8
8
|
htmlType: 'instruction';
|
|
9
9
|
}
|
|
10
|
-
export interface
|
|
10
|
+
export interface IHtmlInlineInstructionTokenData {
|
|
11
11
|
htmlType: 'instruction';
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
13
|
+
export interface IHtmlInlineInstructionDelimiter extends IYastTokenDelimiter, IHtmlInlineInstructionTokenData {
|
|
14
14
|
type: 'full';
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -22,4 +22,4 @@ export interface HtmlInlineInstructionDelimiter extends YastTokenDelimiter, Html
|
|
|
22
22
|
* @param endIndex
|
|
23
23
|
* @see https://github.github.com/gfm/#processing-instruction
|
|
24
24
|
*/
|
|
25
|
-
export declare function eatHtmlInlineInstructionDelimiter(nodePoints: ReadonlyArray<
|
|
25
|
+
export declare function eatHtmlInlineInstructionDelimiter(nodePoints: ReadonlyArray<INodePoint>, startIndex: number, endIndex: number): IHtmlInlineInstructionDelimiter | null;
|
package/lib/types/util/open.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { INodeInterval, INodePoint } from '@yozora/character';
|
|
2
|
+
import type { IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
3
|
import type { RawHTMLAttribute } from '@yozora/tokenizer-html-block';
|
|
4
|
-
export interface
|
|
4
|
+
export interface IHtmlInlineOpenTagData {
|
|
5
5
|
htmlType: 'open';
|
|
6
6
|
/**
|
|
7
7
|
* HTML tag name.
|
|
@@ -19,13 +19,13 @@ export interface HtmlInlineOpenTagData {
|
|
|
19
19
|
*/
|
|
20
20
|
selfClosed: boolean;
|
|
21
21
|
}
|
|
22
|
-
export interface
|
|
22
|
+
export interface IHtmlInlineOpenTokenData {
|
|
23
23
|
htmlType: 'open';
|
|
24
|
-
tagName:
|
|
24
|
+
tagName: INodeInterval;
|
|
25
25
|
attributes: RawHTMLAttribute[];
|
|
26
26
|
selfClosed: boolean;
|
|
27
27
|
}
|
|
28
|
-
export interface
|
|
28
|
+
export interface IHtmlInlineOpenDelimiter extends IYastTokenDelimiter, IHtmlInlineOpenTokenData {
|
|
29
29
|
type: 'full';
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
@@ -37,4 +37,4 @@ export interface HtmlInlineOpenDelimiter extends YastTokenDelimiter, HtmlInlineO
|
|
|
37
37
|
* @param endIndex
|
|
38
38
|
* @see https://github.github.com/gfm/#open-tag
|
|
39
39
|
*/
|
|
40
|
-
export declare function eatHtmlInlineTokenOpenDelimiter(nodePoints: ReadonlyArray<
|
|
40
|
+
export declare function eatHtmlInlineTokenOpenDelimiter(nodePoints: ReadonlyArray<INodePoint>, startIndex: number, endIndex: number): IHtmlInlineOpenDelimiter | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-html-inline",
|
|
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-html-block": "^
|
|
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-html-block": "^2.0.0-alpha.3"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9f274fc7487a8c1dd213405d92508f9a7621f730"
|
|
44
44
|
}
|