@mtcute/markdown-parser 0.1.0 → 0.2.0
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const long_1 = __importDefault(require("long"));
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const client_1 = require("@mtcute/client");
|
|
9
|
+
// md is special cased in prettier, we don't want that here
|
|
10
|
+
const index_js_1 = require("./index.js");
|
|
11
|
+
const createEntity = (type, offset, length, additional) => {
|
|
12
|
+
return {
|
|
13
|
+
_: type,
|
|
14
|
+
offset,
|
|
15
|
+
length,
|
|
16
|
+
...(additional ?? {}),
|
|
17
|
+
}; // idc really, its not that important
|
|
18
|
+
};
|
|
19
|
+
(0, vitest_1.describe)('MarkdownMessageEntityParser', () => {
|
|
20
|
+
(0, vitest_1.describe)('unparse', () => {
|
|
21
|
+
const test = (text, entities, expected) => {
|
|
22
|
+
const result = index_js_1.md.unparse({ text, entities });
|
|
23
|
+
if (Array.isArray(expected)) {
|
|
24
|
+
(0, vitest_1.expect)(expected).to.include(result);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
(0, vitest_1.expect)(result).eq(expected);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
(0, vitest_1.it)('should return the same text if there are no entities or text', () => {
|
|
31
|
+
test('', [], '');
|
|
32
|
+
test('some text', [], 'some text');
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.it)('should handle bold, italic, underline, strikethrough and spoiler', () => {
|
|
35
|
+
test('plain bold italic underline strikethrough spoiler plain', [
|
|
36
|
+
createEntity('messageEntityBold', 6, 4),
|
|
37
|
+
createEntity('messageEntityItalic', 11, 6),
|
|
38
|
+
createEntity('messageEntityUnderline', 18, 9),
|
|
39
|
+
createEntity('messageEntityStrike', 28, 13),
|
|
40
|
+
createEntity('messageEntitySpoiler', 42, 7),
|
|
41
|
+
], 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain');
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.it)('should handle code and pre', () => {
|
|
44
|
+
test('plain code pre __ignored__ plain', [
|
|
45
|
+
createEntity('messageEntityCode', 6, 4),
|
|
46
|
+
createEntity('messageEntityPre', 11, 3),
|
|
47
|
+
createEntity('messageEntityCode', 15, 11),
|
|
48
|
+
], 'plain `code` ```\npre\n``` `\\_\\_ignored\\_\\_` plain');
|
|
49
|
+
});
|
|
50
|
+
(0, vitest_1.it)('should handle links and text mentions', () => {
|
|
51
|
+
test('plain https://google.com google @durov Pavel Durov mail@mail.ru plain', [
|
|
52
|
+
createEntity('messageEntityTextUrl', 25, 6, {
|
|
53
|
+
url: 'https://google.com',
|
|
54
|
+
}),
|
|
55
|
+
createEntity('messageEntityMention', 32, 6),
|
|
56
|
+
createEntity('messageEntityMentionName', 39, 11, {
|
|
57
|
+
userId: 36265675,
|
|
58
|
+
}),
|
|
59
|
+
createEntity('messageEntityEmail', 51, 12),
|
|
60
|
+
], 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) mail@mail.ru plain');
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.it)('should handle language in pre', () => {
|
|
63
|
+
test('plain console.log("Hello, world!") some code plain', [
|
|
64
|
+
createEntity('messageEntityPre', 6, 28, {
|
|
65
|
+
language: 'javascript',
|
|
66
|
+
}),
|
|
67
|
+
createEntity('messageEntityPre', 35, 9, { language: '' }),
|
|
68
|
+
], 'plain ```javascript\nconsole.log("Hello, world!")\n``` ```\nsome code\n``` plain');
|
|
69
|
+
});
|
|
70
|
+
(0, vitest_1.it)('should support entities on the edges', () => {
|
|
71
|
+
test('Hello, world', [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)], '**Hello**, **world**');
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.it)('should clamp out-of-range entities', () => {
|
|
74
|
+
test('Hello, world', [createEntity('messageEntityBold', -2, 7), createEntity('messageEntityBold', 7, 10)], '**Hello**, **world**');
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)('should ignore entities outside the length', () => {
|
|
77
|
+
test('Hello, world', [createEntity('messageEntityBold', 50, 5)], 'Hello, world');
|
|
78
|
+
});
|
|
79
|
+
(0, vitest_1.it)('should support entities followed by each other', () => {
|
|
80
|
+
test('plain Hello, world plain', [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)], [
|
|
81
|
+
'plain **Hello,**__ world__ plain',
|
|
82
|
+
// not the most obvious order, but who cares :D
|
|
83
|
+
// we support this syntax in parse()
|
|
84
|
+
'plain **Hello,__** world__ plain',
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
(0, vitest_1.it)('should support nested entities', () => {
|
|
88
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 8)], '__Welcome to the **gym zone**!__');
|
|
89
|
+
});
|
|
90
|
+
(0, vitest_1.it)('should support nested entities with the same edges', () => {
|
|
91
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)], ['__Welcome to the **gym zone!**__', '__Welcome to the **gym zone!__**']);
|
|
92
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)], ['**Welcome to the __gym zone!__**', '**Welcome to the __gym zone!**__']);
|
|
93
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 7)], ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__']);
|
|
94
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)], [
|
|
95
|
+
'__**Welcome to the gym zone!**__',
|
|
96
|
+
'__**Welcome to the gym zone!__**',
|
|
97
|
+
'**__Welcome to the gym zone!**__',
|
|
98
|
+
'**__Welcome to the gym zone!__**',
|
|
99
|
+
]);
|
|
100
|
+
});
|
|
101
|
+
(0, vitest_1.it)('should support overlapping entities', () => {
|
|
102
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)], '__Welcome **to the__ gym** zone!');
|
|
103
|
+
test('plain bold bold!italic bold!italic!underline underline plain', [
|
|
104
|
+
createEntity('messageEntityBold', 6, 38),
|
|
105
|
+
createEntity('messageEntityItalic', 11, 33),
|
|
106
|
+
createEntity('messageEntityUnderline', 23, 31),
|
|
107
|
+
], [
|
|
108
|
+
'plain **bold __bold!italic --bold!italic!underline**__ underline-- plain',
|
|
109
|
+
'plain **bold __bold!italic --bold!italic!underline__** underline-- plain',
|
|
110
|
+
]);
|
|
111
|
+
test('plain bold bold!italic bold!italic!underline italic!underline underline plain', [
|
|
112
|
+
createEntity('messageEntityBold', 6, 38),
|
|
113
|
+
createEntity('messageEntityItalic', 11, 50),
|
|
114
|
+
createEntity('messageEntityUnderline', 23, 48),
|
|
115
|
+
], 'plain **bold __bold!italic --bold!italic!underline** italic!underline__ underline-- plain');
|
|
116
|
+
});
|
|
117
|
+
(0, vitest_1.it)('should properly handle emojis', () => {
|
|
118
|
+
test("best flower: 🌸. don't you even doubt it.", [
|
|
119
|
+
createEntity('messageEntityItalic', 0, 11),
|
|
120
|
+
createEntity('messageEntityBold', 13, 2),
|
|
121
|
+
createEntity('messageEntityItalic', 17, 5),
|
|
122
|
+
], "__best flower__: **🌸**. __don't__ you even doubt it.");
|
|
123
|
+
});
|
|
124
|
+
(0, vitest_1.it)('should escape reserved symbols', () => {
|
|
125
|
+
test('* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\ \\\\', [createEntity('messageEntityItalic', 9, 8)],
|
|
126
|
+
// holy shit
|
|
127
|
+
'/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'
|
|
128
|
+
// so we don't have to escape every single backslash lol
|
|
129
|
+
.replace(/\//g, '\\'));
|
|
130
|
+
test('* ** *** _ __ ___ - -- ---', [
|
|
131
|
+
// here we test that the order of the entities does not matter
|
|
132
|
+
createEntity('messageEntityItalic', 18, 4),
|
|
133
|
+
createEntity('messageEntityItalic', 9, 8),
|
|
134
|
+
], '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\//g, '\\'));
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
(0, vitest_1.describe)('parse', () => {
|
|
138
|
+
const test = (texts, expectedEntities, expectedText) => {
|
|
139
|
+
if (!Array.isArray(texts))
|
|
140
|
+
texts = [texts];
|
|
141
|
+
for (const text of texts) {
|
|
142
|
+
const res = (0, index_js_1.md)(text);
|
|
143
|
+
(0, vitest_1.expect)(res.text).eql(expectedText);
|
|
144
|
+
(0, vitest_1.expect)(res.entities ?? []).eql(expectedEntities);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
(0, vitest_1.it)('should handle bold, italic, underline, spoiler and strikethrough', () => {
|
|
148
|
+
test('plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain', [
|
|
149
|
+
createEntity('messageEntityBold', 6, 4),
|
|
150
|
+
createEntity('messageEntityItalic', 11, 6),
|
|
151
|
+
createEntity('messageEntityUnderline', 18, 9),
|
|
152
|
+
createEntity('messageEntityStrike', 28, 13),
|
|
153
|
+
createEntity('messageEntitySpoiler', 42, 7),
|
|
154
|
+
], 'plain bold italic underline strikethrough spoiler plain');
|
|
155
|
+
});
|
|
156
|
+
(0, vitest_1.it)('should handle code and pre', () => {
|
|
157
|
+
test([
|
|
158
|
+
'plain `code` ```\npre\n``` `__ignored__` plain',
|
|
159
|
+
'plain `code` ```\npre\n``` `\\_\\_ignored\\_\\_` plain',
|
|
160
|
+
'plain `code` ```\npre``` `\\_\\_ignored\\_\\_` plain',
|
|
161
|
+
], [
|
|
162
|
+
createEntity('messageEntityCode', 6, 4),
|
|
163
|
+
createEntity('messageEntityPre', 11, 3, { language: '' }),
|
|
164
|
+
createEntity('messageEntityCode', 15, 11),
|
|
165
|
+
], 'plain code pre __ignored__ plain');
|
|
166
|
+
test('plain ```\npre with ` and ``\n``` plain', [createEntity('messageEntityPre', 6, 17, { language: '' })], 'plain pre with ` and `` plain');
|
|
167
|
+
test('plain ```\npre with \n`\n and \n``\nend\n``` plain', [createEntity('messageEntityPre', 6, 24, { language: '' })], 'plain pre with \n`\n and \n``\nend plain');
|
|
168
|
+
});
|
|
169
|
+
(0, vitest_1.it)('should handle links and text mentions', () => {
|
|
170
|
+
test('plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) plain', [
|
|
171
|
+
createEntity('messageEntityTextUrl', 25, 6, {
|
|
172
|
+
url: 'https://google.com',
|
|
173
|
+
}),
|
|
174
|
+
createEntity('messageEntityMentionName', 39, 11, {
|
|
175
|
+
userId: 36265675,
|
|
176
|
+
}),
|
|
177
|
+
], 'plain https://google.com google @durov Pavel Durov plain');
|
|
178
|
+
test('[user](tg://user?id=1234567&hash=aabbccddaabbccdd)', [
|
|
179
|
+
createEntity('inputMessageEntityMentionName', 0, 4, {
|
|
180
|
+
userId: {
|
|
181
|
+
_: 'inputUser',
|
|
182
|
+
userId: 1234567,
|
|
183
|
+
accessHash: long_1.default.fromString('aabbccddaabbccdd', 16),
|
|
184
|
+
},
|
|
185
|
+
}),
|
|
186
|
+
], 'user');
|
|
187
|
+
});
|
|
188
|
+
(0, vitest_1.it)('should handle language in pre', () => {
|
|
189
|
+
test('plain ```javascript\nconsole.log("Hello, world!")\n``` ```\nsome code\n``` plain', [
|
|
190
|
+
createEntity('messageEntityPre', 6, 28, {
|
|
191
|
+
language: 'javascript',
|
|
192
|
+
}),
|
|
193
|
+
createEntity('messageEntityPre', 35, 9, { language: '' }),
|
|
194
|
+
], 'plain console.log("Hello, world!") some code plain');
|
|
195
|
+
});
|
|
196
|
+
(0, vitest_1.it)('should support entities on the edges', () => {
|
|
197
|
+
test('**Hello**, **world**', [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)], 'Hello, world');
|
|
198
|
+
});
|
|
199
|
+
(0, vitest_1.it)('should return empty array if there are no entities', () => {
|
|
200
|
+
test('Hello, world', [], 'Hello, world');
|
|
201
|
+
});
|
|
202
|
+
(0, vitest_1.it)('should support overlapping entities', () => {
|
|
203
|
+
test('__Welcome **to the__ gym** zone!', [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)], 'Welcome to the gym zone!');
|
|
204
|
+
// resulting order will depend on the order in which the closing ** or __ are passed,
|
|
205
|
+
// thus we use separate tests
|
|
206
|
+
test('plain **bold __bold-italic --bold-italic-underline**__ underline-- plain', [
|
|
207
|
+
createEntity('messageEntityBold', 6, 38),
|
|
208
|
+
createEntity('messageEntityItalic', 11, 33),
|
|
209
|
+
createEntity('messageEntityUnderline', 23, 31),
|
|
210
|
+
], 'plain bold bold-italic bold-italic-underline underline plain');
|
|
211
|
+
test('plain **bold __bold-italic --bold-italic-underline__** underline-- plain', [
|
|
212
|
+
createEntity('messageEntityItalic', 11, 33),
|
|
213
|
+
createEntity('messageEntityBold', 6, 38),
|
|
214
|
+
createEntity('messageEntityUnderline', 23, 31),
|
|
215
|
+
], 'plain bold bold-italic bold-italic-underline underline plain');
|
|
216
|
+
test('plain **bold __bold-italic --bold-italic-underline** italic-underline__ underline-- plain', [
|
|
217
|
+
createEntity('messageEntityBold', 6, 38),
|
|
218
|
+
createEntity('messageEntityItalic', 11, 50),
|
|
219
|
+
createEntity('messageEntityUnderline', 23, 48),
|
|
220
|
+
], 'plain bold bold-italic bold-italic-underline italic-underline underline plain');
|
|
221
|
+
});
|
|
222
|
+
(0, vitest_1.it)('should support entities followed by each other', () => {
|
|
223
|
+
test(['plain **Hello,**__ world__ plain', 'plain **Hello,__** world__ plain'], [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)], 'plain Hello, world plain');
|
|
224
|
+
});
|
|
225
|
+
(0, vitest_1.it)('should support nested entities', () => {
|
|
226
|
+
test('__Welcome to the **gym zone**!__', [createEntity('messageEntityBold', 15, 8), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
|
|
227
|
+
test('plain [__google__](https://google.com) plain', [
|
|
228
|
+
createEntity('messageEntityItalic', 6, 6),
|
|
229
|
+
createEntity('messageEntityTextUrl', 6, 6, {
|
|
230
|
+
url: 'https://google.com',
|
|
231
|
+
}),
|
|
232
|
+
], 'plain google plain');
|
|
233
|
+
test('plain [plain __google__ plain](https://google.com) plain', [
|
|
234
|
+
createEntity('messageEntityItalic', 12, 6),
|
|
235
|
+
createEntity('messageEntityTextUrl', 6, 18, {
|
|
236
|
+
url: 'https://google.com',
|
|
237
|
+
}),
|
|
238
|
+
], 'plain plain google plain plain');
|
|
239
|
+
});
|
|
240
|
+
(0, vitest_1.it)('should support nested entities with the same edges', () => {
|
|
241
|
+
// again, order of the entities depends on which closing tag goes first.
|
|
242
|
+
test('__Welcome to the **gym zone!**__', [createEntity('messageEntityBold', 15, 9), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
|
|
243
|
+
test('__Welcome to the **gym zone!__**', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)], 'Welcome to the gym zone!');
|
|
244
|
+
test('**Welcome to the __gym zone!__**', [createEntity('messageEntityItalic', 15, 9), createEntity('messageEntityBold', 0, 24)], 'Welcome to the gym zone!');
|
|
245
|
+
test('**Welcome to the __gym zone!**__', [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)], 'Welcome to the gym zone!');
|
|
246
|
+
test(['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'], [createEntity('messageEntityBold', 0, 7), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
|
|
247
|
+
test(['__**Welcome to the gym zone!**__', '**__Welcome to the gym zone!**__'], [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
|
|
248
|
+
test(['__**Welcome to the gym zone!__**', '**__Welcome to the gym zone!__**'], [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)], 'Welcome to the gym zone!');
|
|
249
|
+
});
|
|
250
|
+
(0, vitest_1.it)('should properly handle emojis', () => {
|
|
251
|
+
test("__best flower__: **🌸**. __don't__ you even doubt it.", [
|
|
252
|
+
createEntity('messageEntityItalic', 0, 11),
|
|
253
|
+
createEntity('messageEntityBold', 13, 2),
|
|
254
|
+
createEntity('messageEntityItalic', 17, 5),
|
|
255
|
+
], "best flower: 🌸. don't you even doubt it.");
|
|
256
|
+
});
|
|
257
|
+
(0, vitest_1.it)('should handle escaped reserved symbols', () => {
|
|
258
|
+
test('/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'.replace(/\//g, '\\'), [createEntity('messageEntityItalic', 9, 8)], '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\ \\\\');
|
|
259
|
+
test('/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\//g, '\\'), [createEntity('messageEntityItalic', 9, 8), createEntity('messageEntityItalic', 18, 4)], '* ** *** _ __ ___ - -- ---');
|
|
260
|
+
});
|
|
261
|
+
(0, vitest_1.it)('should ignore empty urls', () => {
|
|
262
|
+
test('[link]() [link]', [], 'link [link]');
|
|
263
|
+
});
|
|
264
|
+
(0, vitest_1.describe)('malformed input', () => {
|
|
265
|
+
const testThrows = (input) => (0, vitest_1.expect)(() => (0, index_js_1.md)(input)).throws(Error);
|
|
266
|
+
(0, vitest_1.it)('should throw an error on malformed links', () => {
|
|
267
|
+
testThrows('plain [link](https://google.com but unclosed');
|
|
268
|
+
});
|
|
269
|
+
(0, vitest_1.it)('should throw an error on malformed pres', () => {
|
|
270
|
+
testThrows('plain ```pre without linebreaks```');
|
|
271
|
+
testThrows('plain ``` pre without linebreaks but with spaces instead ```');
|
|
272
|
+
});
|
|
273
|
+
(0, vitest_1.it)('should throw an error on unterminated entity', () => {
|
|
274
|
+
testThrows('plain **bold but unclosed');
|
|
275
|
+
testThrows('plain **bold and __also italic but unclosed');
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
(0, vitest_1.describe)('template', () => {
|
|
280
|
+
const test = (text, expectedEntities, expectedText) => {
|
|
281
|
+
(0, vitest_1.expect)(text.text).eql(expectedText);
|
|
282
|
+
(0, vitest_1.expect)(text.entities ?? []).eql(expectedEntities);
|
|
283
|
+
};
|
|
284
|
+
(0, vitest_1.it)('should add plain strings as is', () => {
|
|
285
|
+
test((0, index_js_1.md) `${'**plain**'}`, [], '**plain**');
|
|
286
|
+
});
|
|
287
|
+
(0, vitest_1.it)('should skip falsy values', () => {
|
|
288
|
+
test((0, index_js_1.md) `some text ${null} more text ${false}`, [], 'some text more text ');
|
|
289
|
+
});
|
|
290
|
+
(0, vitest_1.it)('should properly dedent', () => {
|
|
291
|
+
test((0, index_js_1.md) `
|
|
292
|
+
some text
|
|
293
|
+
**bold**
|
|
294
|
+
more text
|
|
295
|
+
`, [createEntity('messageEntityBold', 10, 4)], 'some text\nbold\nmore text');
|
|
296
|
+
});
|
|
297
|
+
(0, vitest_1.it)('should process entities', () => {
|
|
298
|
+
const inner = (0, index_js_1.md) `**bold**`;
|
|
299
|
+
test((0, index_js_1.md) `some text ${inner} some more text`, [createEntity('messageEntityBold', 10, 4)], 'some text bold some more text');
|
|
300
|
+
test((0, index_js_1.md) `some text ${inner} some more ${inner} text`, [createEntity('messageEntityBold', 10, 4), createEntity('messageEntityBold', 25, 4)], 'some text bold some more bold text');
|
|
301
|
+
});
|
|
302
|
+
(0, vitest_1.it)('should process entities on edges', () => {
|
|
303
|
+
test((0, index_js_1.md) `${(0, index_js_1.md) `**bold**`} and ${(0, index_js_1.md) `__italic__`}`, [createEntity('messageEntityBold', 0, 4), createEntity('messageEntityItalic', 9, 6)], 'bold and italic');
|
|
304
|
+
});
|
|
305
|
+
(0, vitest_1.it)('should process nested entities', () => {
|
|
306
|
+
test((0, index_js_1.md) `**bold ${(0, index_js_1.md) `__bold italic__`} more bold**`, [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)], 'bold bold italic more bold');
|
|
307
|
+
test((0, index_js_1.md) `**bold ${(0, index_js_1.md) `__bold italic__ --and some underline--`} more bold**`, [
|
|
308
|
+
createEntity('messageEntityItalic', 5, 11),
|
|
309
|
+
createEntity('messageEntityUnderline', 17, 18),
|
|
310
|
+
createEntity('messageEntityBold', 0, 45),
|
|
311
|
+
], 'bold bold italic and some underline more bold');
|
|
312
|
+
test((0, index_js_1.md) `**${(0, index_js_1.md) `__bold italic --underline--__`}**`, [
|
|
313
|
+
createEntity('messageEntityUnderline', 12, 9),
|
|
314
|
+
createEntity('messageEntityItalic', 0, 21),
|
|
315
|
+
createEntity('messageEntityBold', 0, 21),
|
|
316
|
+
], 'bold italic underline');
|
|
317
|
+
});
|
|
318
|
+
(0, vitest_1.it)('should process MessageEntity', () => {
|
|
319
|
+
test((0, index_js_1.md) `**bold ${new client_1.MessageEntity(createEntity('messageEntityItalic', 0, 11), 'bold italic')} more bold**`, [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)], 'bold bold italic more bold');
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
//# sourceMappingURL=markdown-parser.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown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,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import Long from 'long'\nimport { describe, expect, it } from 'vitest'\n\nimport { MessageEntity, TextWithEntities, tl } from '@mtcute/client'\n\n// md is special cased in prettier, we don't want that here\nimport { md as md_ } from './index.js'\n\nconst createEntity = <T extends tl.TypeMessageEntity['_']>(\n type: T,\n offset: number,\n length: number,\n additional?: Omit<tl.FindByName<tl.TypeMessageEntity, T>, '_' | 'offset' | 'length'>,\n): tl.TypeMessageEntity => {\n return {\n _: type,\n offset,\n length,\n ...(additional ?? {}),\n } as tl.TypeMessageEntity // idc really, its not that important\n}\n\ndescribe('MarkdownMessageEntityParser', () => {\n describe('unparse', () => {\n const test = (text: string, entities: tl.TypeMessageEntity[], expected: string | string[]): void => {\n const result = md_.unparse({ text, entities })\n\n if (Array.isArray(expected)) {\n expect(expected).to.include(result)\n } else {\n expect(result).eq(expected)\n }\n }\n\n it('should return the same text if there are no entities or text', () => {\n test('', [], '')\n test('some text', [], 'some text')\n })\n\n it('should handle bold, italic, underline, strikethrough and spoiler', () => {\n test(\n 'plain bold italic underline strikethrough spoiler plain',\n [\n createEntity('messageEntityBold', 6, 4),\n createEntity('messageEntityItalic', 11, 6),\n createEntity('messageEntityUnderline', 18, 9),\n createEntity('messageEntityStrike', 28, 13),\n createEntity('messageEntitySpoiler', 42, 7),\n ],\n 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain',\n )\n })\n\n it('should handle code and pre', () => {\n test(\n 'plain code pre __ignored__ plain',\n [\n createEntity('messageEntityCode', 6, 4),\n createEntity('messageEntityPre', 11, 3),\n createEntity('messageEntityCode', 15, 11),\n ],\n 'plain `code` ```\\npre\\n``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n )\n })\n\n it('should handle links and text mentions', () => {\n test(\n 'plain https://google.com google @durov Pavel Durov mail@mail.ru plain',\n [\n createEntity('messageEntityTextUrl', 25, 6, {\n url: 'https://google.com',\n }),\n createEntity('messageEntityMention', 32, 6),\n createEntity('messageEntityMentionName', 39, 11, {\n userId: 36265675,\n }),\n createEntity('messageEntityEmail', 51, 12),\n ],\n 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) mail@mail.ru plain',\n )\n })\n\n it('should handle language in pre', () => {\n test(\n 'plain console.log(\"Hello, world!\") some code plain',\n [\n createEntity('messageEntityPre', 6, 28, {\n language: 'javascript',\n }),\n createEntity('messageEntityPre', 35, 9, { language: '' }),\n ],\n 'plain ```javascript\\nconsole.log(\"Hello, world!\")\\n``` ```\\nsome code\\n``` plain',\n )\n })\n\n it('should support entities on the edges', () => {\n test(\n 'Hello, world',\n [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)],\n '**Hello**, **world**',\n )\n })\n\n it('should clamp out-of-range entities', () => {\n test(\n 'Hello, world',\n [createEntity('messageEntityBold', -2, 7), createEntity('messageEntityBold', 7, 10)],\n '**Hello**, **world**',\n )\n })\n\n it('should ignore entities outside the length', () => {\n test('Hello, world', [createEntity('messageEntityBold', 50, 5)], 'Hello, world')\n })\n\n it('should support entities followed by each other', () => {\n test(\n 'plain Hello, world plain',\n [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)],\n [\n 'plain **Hello,**__ world__ plain',\n // not the most obvious order, but who cares :D\n // we support this syntax in parse()\n 'plain **Hello,__** world__ plain',\n ],\n )\n })\n\n it('should support nested entities', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 8)],\n '__Welcome to the **gym zone**!__',\n )\n })\n\n it('should support nested entities with the same edges', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)],\n ['__Welcome to the **gym zone!**__', '__Welcome to the **gym zone!__**'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)],\n ['**Welcome to the __gym zone!__**', '**Welcome to the __gym zone!**__'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 7)],\n ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)],\n [\n '__**Welcome to the gym zone!**__',\n '__**Welcome to the gym zone!__**',\n '**__Welcome to the gym zone!**__',\n '**__Welcome to the gym zone!__**',\n ],\n )\n })\n\n it('should support overlapping entities', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)],\n '__Welcome **to the__ gym** zone!',\n )\n test(\n 'plain bold bold!italic bold!italic!underline underline plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n [\n 'plain **bold __bold!italic --bold!italic!underline**__ underline-- plain',\n 'plain **bold __bold!italic --bold!italic!underline__** underline-- plain',\n ],\n )\n test(\n 'plain bold bold!italic bold!italic!underline italic!underline underline plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 50),\n createEntity('messageEntityUnderline', 23, 48),\n ],\n 'plain **bold __bold!italic --bold!italic!underline** italic!underline__ underline-- plain',\n )\n })\n\n it('should properly handle emojis', () => {\n test(\n \"best flower: 🌸. don't you even doubt it.\",\n [\n createEntity('messageEntityItalic', 0, 11),\n createEntity('messageEntityBold', 13, 2),\n createEntity('messageEntityItalic', 17, 5),\n ],\n \"__best flower__: **🌸**. __don't__ you even doubt it.\",\n )\n })\n\n it('should escape reserved symbols', () => {\n test(\n '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\\\ \\\\\\\\',\n [createEntity('messageEntityItalic', 9, 8)],\n // holy shit\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'\n // so we don't have to escape every single backslash lol\n .replace(/\\//g, '\\\\'),\n )\n test(\n '* ** *** _ __ ___ - -- ---',\n [\n // here we test that the order of the entities does not matter\n createEntity('messageEntityItalic', 18, 4),\n createEntity('messageEntityItalic', 9, 8),\n ],\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\\//g, '\\\\'),\n )\n })\n })\n\n describe('parse', () => {\n const test = (\n texts: string | string[],\n expectedEntities: tl.TypeMessageEntity[],\n expectedText: string,\n ): void => {\n if (!Array.isArray(texts)) texts = [texts]\n\n for (const text of texts) {\n const res = md_(text)\n expect(res.text).eql(expectedText)\n expect(res.entities ?? []).eql(expectedEntities)\n }\n }\n\n it('should handle bold, italic, underline, spoiler and strikethrough', () => {\n test(\n 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain',\n [\n createEntity('messageEntityBold', 6, 4),\n createEntity('messageEntityItalic', 11, 6),\n createEntity('messageEntityUnderline', 18, 9),\n createEntity('messageEntityStrike', 28, 13),\n createEntity('messageEntitySpoiler', 42, 7),\n ],\n 'plain bold italic underline strikethrough spoiler plain',\n )\n })\n\n it('should handle code and pre', () => {\n test(\n [\n 'plain `code` ```\\npre\\n``` `__ignored__` plain',\n 'plain `code` ```\\npre\\n``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n 'plain `code` ```\\npre``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n ],\n [\n createEntity('messageEntityCode', 6, 4),\n createEntity('messageEntityPre', 11, 3, { language: '' }),\n createEntity('messageEntityCode', 15, 11),\n ],\n 'plain code pre __ignored__ plain',\n )\n\n test(\n 'plain ```\\npre with ` and ``\\n``` plain',\n [createEntity('messageEntityPre', 6, 17, { language: '' })],\n 'plain pre with ` and `` plain',\n )\n\n test(\n 'plain ```\\npre with \\n`\\n and \\n``\\nend\\n``` plain',\n [createEntity('messageEntityPre', 6, 24, { language: '' })],\n 'plain pre with \\n`\\n and \\n``\\nend plain',\n )\n })\n\n it('should handle links and text mentions', () => {\n test(\n 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) plain',\n [\n createEntity('messageEntityTextUrl', 25, 6, {\n url: 'https://google.com',\n }),\n createEntity('messageEntityMentionName', 39, 11, {\n userId: 36265675,\n }),\n ],\n 'plain https://google.com google @durov Pavel Durov plain',\n )\n\n test(\n '[user](tg://user?id=1234567&hash=aabbccddaabbccdd)',\n [\n createEntity('inputMessageEntityMentionName', 0, 4, {\n userId: {\n _: 'inputUser',\n userId: 1234567,\n accessHash: Long.fromString('aabbccddaabbccdd', 16),\n },\n }),\n ],\n 'user',\n )\n })\n\n it('should handle language in pre', () => {\n test(\n 'plain ```javascript\\nconsole.log(\"Hello, world!\")\\n``` ```\\nsome code\\n``` plain',\n [\n createEntity('messageEntityPre', 6, 28, {\n language: 'javascript',\n }),\n createEntity('messageEntityPre', 35, 9, { language: '' }),\n ],\n 'plain console.log(\"Hello, world!\") some code plain',\n )\n })\n\n it('should support entities on the edges', () => {\n test(\n '**Hello**, **world**',\n [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)],\n 'Hello, world',\n )\n })\n\n it('should return empty array if there are no entities', () => {\n test('Hello, world', [], 'Hello, world')\n })\n\n it('should support overlapping entities', () => {\n test(\n '__Welcome **to the__ gym** zone!',\n [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)],\n 'Welcome to the gym zone!',\n )\n\n // resulting order will depend on the order in which the closing ** or __ are passed,\n // thus we use separate tests\n test(\n 'plain **bold __bold-italic --bold-italic-underline**__ underline-- plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n 'plain bold bold-italic bold-italic-underline underline plain',\n )\n test(\n 'plain **bold __bold-italic --bold-italic-underline__** underline-- plain',\n [\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n 'plain bold bold-italic bold-italic-underline underline plain',\n )\n\n test(\n 'plain **bold __bold-italic --bold-italic-underline** italic-underline__ underline-- plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 50),\n createEntity('messageEntityUnderline', 23, 48),\n ],\n 'plain bold bold-italic bold-italic-underline italic-underline underline plain',\n )\n })\n\n it('should support entities followed by each other', () => {\n test(\n ['plain **Hello,**__ world__ plain', 'plain **Hello,__** world__ plain'],\n [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)],\n 'plain Hello, world plain',\n )\n })\n\n it('should support nested entities', () => {\n test(\n '__Welcome to the **gym zone**!__',\n [createEntity('messageEntityBold', 15, 8), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n\n test(\n 'plain [__google__](https://google.com) plain',\n [\n createEntity('messageEntityItalic', 6, 6),\n createEntity('messageEntityTextUrl', 6, 6, {\n url: 'https://google.com',\n }),\n ],\n 'plain google plain',\n )\n test(\n 'plain [plain __google__ plain](https://google.com) plain',\n [\n createEntity('messageEntityItalic', 12, 6),\n createEntity('messageEntityTextUrl', 6, 18, {\n url: 'https://google.com',\n }),\n ],\n 'plain plain google plain plain',\n )\n })\n\n it('should support nested entities with the same edges', () => {\n // again, order of the entities depends on which closing tag goes first.\n test(\n '__Welcome to the **gym zone!**__',\n [createEntity('messageEntityBold', 15, 9), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n '__Welcome to the **gym zone!__**',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)],\n 'Welcome to the gym zone!',\n )\n\n test(\n '**Welcome to the __gym zone!__**',\n [createEntity('messageEntityItalic', 15, 9), createEntity('messageEntityBold', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n '**Welcome to the __gym zone!**__',\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)],\n 'Welcome to the gym zone!',\n )\n\n test(\n ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'],\n [createEntity('messageEntityBold', 0, 7), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n\n test(\n ['__**Welcome to the gym zone!**__', '**__Welcome to the gym zone!**__'],\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n ['__**Welcome to the gym zone!__**', '**__Welcome to the gym zone!__**'],\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)],\n 'Welcome to the gym zone!',\n )\n })\n\n it('should properly handle emojis', () => {\n test(\n \"__best flower__: **🌸**. __don't__ you even doubt it.\",\n [\n createEntity('messageEntityItalic', 0, 11),\n createEntity('messageEntityBold', 13, 2),\n createEntity('messageEntityItalic', 17, 5),\n ],\n \"best flower: 🌸. don't you even doubt it.\",\n )\n })\n\n it('should handle escaped reserved symbols', () => {\n test(\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'.replace(\n /\\//g,\n '\\\\',\n ),\n [createEntity('messageEntityItalic', 9, 8)],\n '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\\\ \\\\\\\\',\n )\n test(\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\\//g, '\\\\'),\n [createEntity('messageEntityItalic', 9, 8), createEntity('messageEntityItalic', 18, 4)],\n '* ** *** _ __ ___ - -- ---',\n )\n })\n\n it('should ignore empty urls', () => {\n test('[link]() [link]', [], 'link [link]')\n })\n\n describe('malformed input', () => {\n const testThrows = (input: string) => expect(() => md_(input)).throws(Error)\n\n it('should throw an error on malformed links', () => {\n testThrows('plain [link](https://google.com but unclosed')\n })\n\n it('should throw an error on malformed pres', () => {\n testThrows('plain ```pre without linebreaks```')\n testThrows('plain ``` pre without linebreaks but with spaces instead ```')\n })\n\n it('should throw an error on unterminated entity', () => {\n testThrows('plain **bold but unclosed')\n testThrows('plain **bold and __also italic but unclosed')\n })\n })\n })\n\n describe('template', () => {\n const test = (text: TextWithEntities, expectedEntities: tl.TypeMessageEntity[], expectedText: string): void => {\n expect(text.text).eql(expectedText)\n expect(text.entities ?? []).eql(expectedEntities)\n }\n\n it('should add plain strings as is', () => {\n test(md_`${'**plain**'}`, [], '**plain**')\n })\n\n it('should skip falsy values', () => {\n test(md_`some text ${null} more text ${false}`, [], 'some text more text ')\n })\n\n it('should properly dedent', () => {\n test(\n md_`\n some text\n **bold**\n more text\n `,\n [createEntity('messageEntityBold', 10, 4)],\n 'some text\\nbold\\nmore text',\n )\n })\n\n it('should process entities', () => {\n const inner = md_`**bold**`\n\n test(\n md_`some text ${inner} some more text`,\n [createEntity('messageEntityBold', 10, 4)],\n 'some text bold some more text',\n )\n test(\n md_`some text ${inner} some more ${inner} text`,\n [createEntity('messageEntityBold', 10, 4), createEntity('messageEntityBold', 25, 4)],\n 'some text bold some more bold text',\n )\n })\n\n it('should process entities on edges', () => {\n test(\n md_`${md_`**bold**`} and ${md_`__italic__`}`,\n [createEntity('messageEntityBold', 0, 4), createEntity('messageEntityItalic', 9, 6)],\n 'bold and italic',\n )\n })\n\n it('should process nested entities', () => {\n test(\n md_`**bold ${md_`__bold italic__`} more bold**`,\n [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)],\n 'bold bold italic more bold',\n )\n test(\n md_`**bold ${md_`__bold italic__ --and some underline--`} more bold**`,\n [\n createEntity('messageEntityItalic', 5, 11),\n createEntity('messageEntityUnderline', 17, 18),\n createEntity('messageEntityBold', 0, 45),\n ],\n 'bold bold italic and some underline more bold',\n )\n test(\n md_`**${md_`__bold italic --underline--__`}**`,\n [\n createEntity('messageEntityUnderline', 12, 9),\n createEntity('messageEntityItalic', 0, 21),\n createEntity('messageEntityBold', 0, 21),\n ],\n 'bold italic underline',\n )\n })\n\n it('should process MessageEntity', () => {\n test(\n md_`**bold ${new MessageEntity(createEntity('messageEntityItalic', 0, 11), 'bold italic')} more bold**`,\n [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)],\n 'bold bold italic more bold',\n )\n })\n })\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import Long from 'long';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { MessageEntity } from '@mtcute/client';
|
|
4
|
+
// md is special cased in prettier, we don't want that here
|
|
5
|
+
import { md as md_ } from './index.js';
|
|
6
|
+
const createEntity = (type, offset, length, additional) => {
|
|
7
|
+
return {
|
|
8
|
+
_: type,
|
|
9
|
+
offset,
|
|
10
|
+
length,
|
|
11
|
+
...(additional ?? {}),
|
|
12
|
+
}; // idc really, its not that important
|
|
13
|
+
};
|
|
14
|
+
describe('MarkdownMessageEntityParser', () => {
|
|
15
|
+
describe('unparse', () => {
|
|
16
|
+
const test = (text, entities, expected) => {
|
|
17
|
+
const result = md_.unparse({ text, entities });
|
|
18
|
+
if (Array.isArray(expected)) {
|
|
19
|
+
expect(expected).to.include(result);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
expect(result).eq(expected);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
it('should return the same text if there are no entities or text', () => {
|
|
26
|
+
test('', [], '');
|
|
27
|
+
test('some text', [], 'some text');
|
|
28
|
+
});
|
|
29
|
+
it('should handle bold, italic, underline, strikethrough and spoiler', () => {
|
|
30
|
+
test('plain bold italic underline strikethrough spoiler plain', [
|
|
31
|
+
createEntity('messageEntityBold', 6, 4),
|
|
32
|
+
createEntity('messageEntityItalic', 11, 6),
|
|
33
|
+
createEntity('messageEntityUnderline', 18, 9),
|
|
34
|
+
createEntity('messageEntityStrike', 28, 13),
|
|
35
|
+
createEntity('messageEntitySpoiler', 42, 7),
|
|
36
|
+
], 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain');
|
|
37
|
+
});
|
|
38
|
+
it('should handle code and pre', () => {
|
|
39
|
+
test('plain code pre __ignored__ plain', [
|
|
40
|
+
createEntity('messageEntityCode', 6, 4),
|
|
41
|
+
createEntity('messageEntityPre', 11, 3),
|
|
42
|
+
createEntity('messageEntityCode', 15, 11),
|
|
43
|
+
], 'plain `code` ```\npre\n``` `\\_\\_ignored\\_\\_` plain');
|
|
44
|
+
});
|
|
45
|
+
it('should handle links and text mentions', () => {
|
|
46
|
+
test('plain https://google.com google @durov Pavel Durov mail@mail.ru plain', [
|
|
47
|
+
createEntity('messageEntityTextUrl', 25, 6, {
|
|
48
|
+
url: 'https://google.com',
|
|
49
|
+
}),
|
|
50
|
+
createEntity('messageEntityMention', 32, 6),
|
|
51
|
+
createEntity('messageEntityMentionName', 39, 11, {
|
|
52
|
+
userId: 36265675,
|
|
53
|
+
}),
|
|
54
|
+
createEntity('messageEntityEmail', 51, 12),
|
|
55
|
+
], 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) mail@mail.ru plain');
|
|
56
|
+
});
|
|
57
|
+
it('should handle language in pre', () => {
|
|
58
|
+
test('plain console.log("Hello, world!") some code plain', [
|
|
59
|
+
createEntity('messageEntityPre', 6, 28, {
|
|
60
|
+
language: 'javascript',
|
|
61
|
+
}),
|
|
62
|
+
createEntity('messageEntityPre', 35, 9, { language: '' }),
|
|
63
|
+
], 'plain ```javascript\nconsole.log("Hello, world!")\n``` ```\nsome code\n``` plain');
|
|
64
|
+
});
|
|
65
|
+
it('should support entities on the edges', () => {
|
|
66
|
+
test('Hello, world', [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)], '**Hello**, **world**');
|
|
67
|
+
});
|
|
68
|
+
it('should clamp out-of-range entities', () => {
|
|
69
|
+
test('Hello, world', [createEntity('messageEntityBold', -2, 7), createEntity('messageEntityBold', 7, 10)], '**Hello**, **world**');
|
|
70
|
+
});
|
|
71
|
+
it('should ignore entities outside the length', () => {
|
|
72
|
+
test('Hello, world', [createEntity('messageEntityBold', 50, 5)], 'Hello, world');
|
|
73
|
+
});
|
|
74
|
+
it('should support entities followed by each other', () => {
|
|
75
|
+
test('plain Hello, world plain', [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)], [
|
|
76
|
+
'plain **Hello,**__ world__ plain',
|
|
77
|
+
// not the most obvious order, but who cares :D
|
|
78
|
+
// we support this syntax in parse()
|
|
79
|
+
'plain **Hello,__** world__ plain',
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
it('should support nested entities', () => {
|
|
83
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 8)], '__Welcome to the **gym zone**!__');
|
|
84
|
+
});
|
|
85
|
+
it('should support nested entities with the same edges', () => {
|
|
86
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)], ['__Welcome to the **gym zone!**__', '__Welcome to the **gym zone!__**']);
|
|
87
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)], ['**Welcome to the __gym zone!__**', '**Welcome to the __gym zone!**__']);
|
|
88
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 7)], ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__']);
|
|
89
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)], [
|
|
90
|
+
'__**Welcome to the gym zone!**__',
|
|
91
|
+
'__**Welcome to the gym zone!__**',
|
|
92
|
+
'**__Welcome to the gym zone!**__',
|
|
93
|
+
'**__Welcome to the gym zone!__**',
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
it('should support overlapping entities', () => {
|
|
97
|
+
test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)], '__Welcome **to the__ gym** zone!');
|
|
98
|
+
test('plain bold bold!italic bold!italic!underline underline plain', [
|
|
99
|
+
createEntity('messageEntityBold', 6, 38),
|
|
100
|
+
createEntity('messageEntityItalic', 11, 33),
|
|
101
|
+
createEntity('messageEntityUnderline', 23, 31),
|
|
102
|
+
], [
|
|
103
|
+
'plain **bold __bold!italic --bold!italic!underline**__ underline-- plain',
|
|
104
|
+
'plain **bold __bold!italic --bold!italic!underline__** underline-- plain',
|
|
105
|
+
]);
|
|
106
|
+
test('plain bold bold!italic bold!italic!underline italic!underline underline plain', [
|
|
107
|
+
createEntity('messageEntityBold', 6, 38),
|
|
108
|
+
createEntity('messageEntityItalic', 11, 50),
|
|
109
|
+
createEntity('messageEntityUnderline', 23, 48),
|
|
110
|
+
], 'plain **bold __bold!italic --bold!italic!underline** italic!underline__ underline-- plain');
|
|
111
|
+
});
|
|
112
|
+
it('should properly handle emojis', () => {
|
|
113
|
+
test("best flower: 🌸. don't you even doubt it.", [
|
|
114
|
+
createEntity('messageEntityItalic', 0, 11),
|
|
115
|
+
createEntity('messageEntityBold', 13, 2),
|
|
116
|
+
createEntity('messageEntityItalic', 17, 5),
|
|
117
|
+
], "__best flower__: **🌸**. __don't__ you even doubt it.");
|
|
118
|
+
});
|
|
119
|
+
it('should escape reserved symbols', () => {
|
|
120
|
+
test('* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\ \\\\', [createEntity('messageEntityItalic', 9, 8)],
|
|
121
|
+
// holy shit
|
|
122
|
+
'/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'
|
|
123
|
+
// so we don't have to escape every single backslash lol
|
|
124
|
+
.replace(/\//g, '\\'));
|
|
125
|
+
test('* ** *** _ __ ___ - -- ---', [
|
|
126
|
+
// here we test that the order of the entities does not matter
|
|
127
|
+
createEntity('messageEntityItalic', 18, 4),
|
|
128
|
+
createEntity('messageEntityItalic', 9, 8),
|
|
129
|
+
], '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\//g, '\\'));
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
describe('parse', () => {
|
|
133
|
+
const test = (texts, expectedEntities, expectedText) => {
|
|
134
|
+
if (!Array.isArray(texts))
|
|
135
|
+
texts = [texts];
|
|
136
|
+
for (const text of texts) {
|
|
137
|
+
const res = md_(text);
|
|
138
|
+
expect(res.text).eql(expectedText);
|
|
139
|
+
expect(res.entities ?? []).eql(expectedEntities);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
it('should handle bold, italic, underline, spoiler and strikethrough', () => {
|
|
143
|
+
test('plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain', [
|
|
144
|
+
createEntity('messageEntityBold', 6, 4),
|
|
145
|
+
createEntity('messageEntityItalic', 11, 6),
|
|
146
|
+
createEntity('messageEntityUnderline', 18, 9),
|
|
147
|
+
createEntity('messageEntityStrike', 28, 13),
|
|
148
|
+
createEntity('messageEntitySpoiler', 42, 7),
|
|
149
|
+
], 'plain bold italic underline strikethrough spoiler plain');
|
|
150
|
+
});
|
|
151
|
+
it('should handle code and pre', () => {
|
|
152
|
+
test([
|
|
153
|
+
'plain `code` ```\npre\n``` `__ignored__` plain',
|
|
154
|
+
'plain `code` ```\npre\n``` `\\_\\_ignored\\_\\_` plain',
|
|
155
|
+
'plain `code` ```\npre``` `\\_\\_ignored\\_\\_` plain',
|
|
156
|
+
], [
|
|
157
|
+
createEntity('messageEntityCode', 6, 4),
|
|
158
|
+
createEntity('messageEntityPre', 11, 3, { language: '' }),
|
|
159
|
+
createEntity('messageEntityCode', 15, 11),
|
|
160
|
+
], 'plain code pre __ignored__ plain');
|
|
161
|
+
test('plain ```\npre with ` and ``\n``` plain', [createEntity('messageEntityPre', 6, 17, { language: '' })], 'plain pre with ` and `` plain');
|
|
162
|
+
test('plain ```\npre with \n`\n and \n``\nend\n``` plain', [createEntity('messageEntityPre', 6, 24, { language: '' })], 'plain pre with \n`\n and \n``\nend plain');
|
|
163
|
+
});
|
|
164
|
+
it('should handle links and text mentions', () => {
|
|
165
|
+
test('plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) plain', [
|
|
166
|
+
createEntity('messageEntityTextUrl', 25, 6, {
|
|
167
|
+
url: 'https://google.com',
|
|
168
|
+
}),
|
|
169
|
+
createEntity('messageEntityMentionName', 39, 11, {
|
|
170
|
+
userId: 36265675,
|
|
171
|
+
}),
|
|
172
|
+
], 'plain https://google.com google @durov Pavel Durov plain');
|
|
173
|
+
test('[user](tg://user?id=1234567&hash=aabbccddaabbccdd)', [
|
|
174
|
+
createEntity('inputMessageEntityMentionName', 0, 4, {
|
|
175
|
+
userId: {
|
|
176
|
+
_: 'inputUser',
|
|
177
|
+
userId: 1234567,
|
|
178
|
+
accessHash: Long.fromString('aabbccddaabbccdd', 16),
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
], 'user');
|
|
182
|
+
});
|
|
183
|
+
it('should handle language in pre', () => {
|
|
184
|
+
test('plain ```javascript\nconsole.log("Hello, world!")\n``` ```\nsome code\n``` plain', [
|
|
185
|
+
createEntity('messageEntityPre', 6, 28, {
|
|
186
|
+
language: 'javascript',
|
|
187
|
+
}),
|
|
188
|
+
createEntity('messageEntityPre', 35, 9, { language: '' }),
|
|
189
|
+
], 'plain console.log("Hello, world!") some code plain');
|
|
190
|
+
});
|
|
191
|
+
it('should support entities on the edges', () => {
|
|
192
|
+
test('**Hello**, **world**', [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)], 'Hello, world');
|
|
193
|
+
});
|
|
194
|
+
it('should return empty array if there are no entities', () => {
|
|
195
|
+
test('Hello, world', [], 'Hello, world');
|
|
196
|
+
});
|
|
197
|
+
it('should support overlapping entities', () => {
|
|
198
|
+
test('__Welcome **to the__ gym** zone!', [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)], 'Welcome to the gym zone!');
|
|
199
|
+
// resulting order will depend on the order in which the closing ** or __ are passed,
|
|
200
|
+
// thus we use separate tests
|
|
201
|
+
test('plain **bold __bold-italic --bold-italic-underline**__ underline-- plain', [
|
|
202
|
+
createEntity('messageEntityBold', 6, 38),
|
|
203
|
+
createEntity('messageEntityItalic', 11, 33),
|
|
204
|
+
createEntity('messageEntityUnderline', 23, 31),
|
|
205
|
+
], 'plain bold bold-italic bold-italic-underline underline plain');
|
|
206
|
+
test('plain **bold __bold-italic --bold-italic-underline__** underline-- plain', [
|
|
207
|
+
createEntity('messageEntityItalic', 11, 33),
|
|
208
|
+
createEntity('messageEntityBold', 6, 38),
|
|
209
|
+
createEntity('messageEntityUnderline', 23, 31),
|
|
210
|
+
], 'plain bold bold-italic bold-italic-underline underline plain');
|
|
211
|
+
test('plain **bold __bold-italic --bold-italic-underline** italic-underline__ underline-- plain', [
|
|
212
|
+
createEntity('messageEntityBold', 6, 38),
|
|
213
|
+
createEntity('messageEntityItalic', 11, 50),
|
|
214
|
+
createEntity('messageEntityUnderline', 23, 48),
|
|
215
|
+
], 'plain bold bold-italic bold-italic-underline italic-underline underline plain');
|
|
216
|
+
});
|
|
217
|
+
it('should support entities followed by each other', () => {
|
|
218
|
+
test(['plain **Hello,**__ world__ plain', 'plain **Hello,__** world__ plain'], [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)], 'plain Hello, world plain');
|
|
219
|
+
});
|
|
220
|
+
it('should support nested entities', () => {
|
|
221
|
+
test('__Welcome to the **gym zone**!__', [createEntity('messageEntityBold', 15, 8), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
|
|
222
|
+
test('plain [__google__](https://google.com) plain', [
|
|
223
|
+
createEntity('messageEntityItalic', 6, 6),
|
|
224
|
+
createEntity('messageEntityTextUrl', 6, 6, {
|
|
225
|
+
url: 'https://google.com',
|
|
226
|
+
}),
|
|
227
|
+
], 'plain google plain');
|
|
228
|
+
test('plain [plain __google__ plain](https://google.com) plain', [
|
|
229
|
+
createEntity('messageEntityItalic', 12, 6),
|
|
230
|
+
createEntity('messageEntityTextUrl', 6, 18, {
|
|
231
|
+
url: 'https://google.com',
|
|
232
|
+
}),
|
|
233
|
+
], 'plain plain google plain plain');
|
|
234
|
+
});
|
|
235
|
+
it('should support nested entities with the same edges', () => {
|
|
236
|
+
// again, order of the entities depends on which closing tag goes first.
|
|
237
|
+
test('__Welcome to the **gym zone!**__', [createEntity('messageEntityBold', 15, 9), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
|
|
238
|
+
test('__Welcome to the **gym zone!__**', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)], 'Welcome to the gym zone!');
|
|
239
|
+
test('**Welcome to the __gym zone!__**', [createEntity('messageEntityItalic', 15, 9), createEntity('messageEntityBold', 0, 24)], 'Welcome to the gym zone!');
|
|
240
|
+
test('**Welcome to the __gym zone!**__', [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)], 'Welcome to the gym zone!');
|
|
241
|
+
test(['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'], [createEntity('messageEntityBold', 0, 7), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
|
|
242
|
+
test(['__**Welcome to the gym zone!**__', '**__Welcome to the gym zone!**__'], [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
|
|
243
|
+
test(['__**Welcome to the gym zone!__**', '**__Welcome to the gym zone!__**'], [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)], 'Welcome to the gym zone!');
|
|
244
|
+
});
|
|
245
|
+
it('should properly handle emojis', () => {
|
|
246
|
+
test("__best flower__: **🌸**. __don't__ you even doubt it.", [
|
|
247
|
+
createEntity('messageEntityItalic', 0, 11),
|
|
248
|
+
createEntity('messageEntityBold', 13, 2),
|
|
249
|
+
createEntity('messageEntityItalic', 17, 5),
|
|
250
|
+
], "best flower: 🌸. don't you even doubt it.");
|
|
251
|
+
});
|
|
252
|
+
it('should handle escaped reserved symbols', () => {
|
|
253
|
+
test('/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'.replace(/\//g, '\\'), [createEntity('messageEntityItalic', 9, 8)], '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\ \\\\');
|
|
254
|
+
test('/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\//g, '\\'), [createEntity('messageEntityItalic', 9, 8), createEntity('messageEntityItalic', 18, 4)], '* ** *** _ __ ___ - -- ---');
|
|
255
|
+
});
|
|
256
|
+
it('should ignore empty urls', () => {
|
|
257
|
+
test('[link]() [link]', [], 'link [link]');
|
|
258
|
+
});
|
|
259
|
+
describe('malformed input', () => {
|
|
260
|
+
const testThrows = (input) => expect(() => md_(input)).throws(Error);
|
|
261
|
+
it('should throw an error on malformed links', () => {
|
|
262
|
+
testThrows('plain [link](https://google.com but unclosed');
|
|
263
|
+
});
|
|
264
|
+
it('should throw an error on malformed pres', () => {
|
|
265
|
+
testThrows('plain ```pre without linebreaks```');
|
|
266
|
+
testThrows('plain ``` pre without linebreaks but with spaces instead ```');
|
|
267
|
+
});
|
|
268
|
+
it('should throw an error on unterminated entity', () => {
|
|
269
|
+
testThrows('plain **bold but unclosed');
|
|
270
|
+
testThrows('plain **bold and __also italic but unclosed');
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
describe('template', () => {
|
|
275
|
+
const test = (text, expectedEntities, expectedText) => {
|
|
276
|
+
expect(text.text).eql(expectedText);
|
|
277
|
+
expect(text.entities ?? []).eql(expectedEntities);
|
|
278
|
+
};
|
|
279
|
+
it('should add plain strings as is', () => {
|
|
280
|
+
test(md_ `${'**plain**'}`, [], '**plain**');
|
|
281
|
+
});
|
|
282
|
+
it('should skip falsy values', () => {
|
|
283
|
+
test(md_ `some text ${null} more text ${false}`, [], 'some text more text ');
|
|
284
|
+
});
|
|
285
|
+
it('should properly dedent', () => {
|
|
286
|
+
test(md_ `
|
|
287
|
+
some text
|
|
288
|
+
**bold**
|
|
289
|
+
more text
|
|
290
|
+
`, [createEntity('messageEntityBold', 10, 4)], 'some text\nbold\nmore text');
|
|
291
|
+
});
|
|
292
|
+
it('should process entities', () => {
|
|
293
|
+
const inner = md_ `**bold**`;
|
|
294
|
+
test(md_ `some text ${inner} some more text`, [createEntity('messageEntityBold', 10, 4)], 'some text bold some more text');
|
|
295
|
+
test(md_ `some text ${inner} some more ${inner} text`, [createEntity('messageEntityBold', 10, 4), createEntity('messageEntityBold', 25, 4)], 'some text bold some more bold text');
|
|
296
|
+
});
|
|
297
|
+
it('should process entities on edges', () => {
|
|
298
|
+
test(md_ `${md_ `**bold**`} and ${md_ `__italic__`}`, [createEntity('messageEntityBold', 0, 4), createEntity('messageEntityItalic', 9, 6)], 'bold and italic');
|
|
299
|
+
});
|
|
300
|
+
it('should process nested entities', () => {
|
|
301
|
+
test(md_ `**bold ${md_ `__bold italic__`} more bold**`, [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)], 'bold bold italic more bold');
|
|
302
|
+
test(md_ `**bold ${md_ `__bold italic__ --and some underline--`} more bold**`, [
|
|
303
|
+
createEntity('messageEntityItalic', 5, 11),
|
|
304
|
+
createEntity('messageEntityUnderline', 17, 18),
|
|
305
|
+
createEntity('messageEntityBold', 0, 45),
|
|
306
|
+
], 'bold bold italic and some underline more bold');
|
|
307
|
+
test(md_ `**${md_ `__bold italic --underline--__`}**`, [
|
|
308
|
+
createEntity('messageEntityUnderline', 12, 9),
|
|
309
|
+
createEntity('messageEntityItalic', 0, 21),
|
|
310
|
+
createEntity('messageEntityBold', 0, 21),
|
|
311
|
+
], 'bold italic underline');
|
|
312
|
+
});
|
|
313
|
+
it('should process MessageEntity', () => {
|
|
314
|
+
test(md_ `**bold ${new MessageEntity(createEntity('messageEntityItalic', 0, 11), 'bold italic')} more bold**`, [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)], 'bold bold italic more bold');
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
//# sourceMappingURL=markdown-parser.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-parser.test.js","sourceRoot":"","sources":["../../src/markdown-parser.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAwB,MAAM,gBAAgB,CAAA;AAEpE,2DAA2D;AAC3D,OAAO,EAAE,EAAE,IAAI,GAAG,EAAE,MAAM,YAAY,CAAA;AAEtC,MAAM,YAAY,GAAG,CACjB,IAAO,EACP,MAAc,EACd,MAAc,EACd,UAAoF,EAChE,EAAE;IACtB,OAAO;QACH,CAAC,EAAE,IAAI;QACP,MAAM;QACN,MAAM;QACN,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;KACA,CAAA,CAAC,qCAAqC;AACnE,CAAC,CAAA;AAED,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IACzC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACrB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,QAAgC,EAAE,QAA2B,EAAQ,EAAE;YAC/F,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,E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UAAU,IAAI,aAAa,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,aAAa,CAAC,cAAc,EACvG,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,YAAY,CAAC,mBAAmB,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EACtF,4BAA4B,CAC/B,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import Long from 'long'\nimport { describe, expect, it } from 'vitest'\n\nimport { MessageEntity, TextWithEntities, tl } from '@mtcute/client'\n\n// md is special cased in prettier, we don't want that here\nimport { md as md_ } from './index.js'\n\nconst createEntity = <T extends tl.TypeMessageEntity['_']>(\n type: T,\n offset: number,\n length: number,\n additional?: Omit<tl.FindByName<tl.TypeMessageEntity, T>, '_' | 'offset' | 'length'>,\n): tl.TypeMessageEntity => {\n return {\n _: type,\n offset,\n length,\n ...(additional ?? {}),\n } as tl.TypeMessageEntity // idc really, its not that important\n}\n\ndescribe('MarkdownMessageEntityParser', () => {\n describe('unparse', () => {\n const test = (text: string, entities: tl.TypeMessageEntity[], expected: string | string[]): void => {\n const result = md_.unparse({ text, entities })\n\n if (Array.isArray(expected)) {\n expect(expected).to.include(result)\n } else {\n expect(result).eq(expected)\n }\n }\n\n it('should return the same text if there are no entities or text', () => {\n test('', [], '')\n test('some text', [], 'some text')\n })\n\n it('should handle bold, italic, underline, strikethrough and spoiler', () => {\n test(\n 'plain bold italic underline strikethrough spoiler plain',\n [\n createEntity('messageEntityBold', 6, 4),\n createEntity('messageEntityItalic', 11, 6),\n createEntity('messageEntityUnderline', 18, 9),\n createEntity('messageEntityStrike', 28, 13),\n createEntity('messageEntitySpoiler', 42, 7),\n ],\n 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain',\n )\n })\n\n it('should handle code and pre', () => {\n test(\n 'plain code pre __ignored__ plain',\n [\n createEntity('messageEntityCode', 6, 4),\n createEntity('messageEntityPre', 11, 3),\n createEntity('messageEntityCode', 15, 11),\n ],\n 'plain `code` ```\\npre\\n``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n )\n })\n\n it('should handle links and text mentions', () => {\n test(\n 'plain https://google.com google @durov Pavel Durov mail@mail.ru plain',\n [\n createEntity('messageEntityTextUrl', 25, 6, {\n url: 'https://google.com',\n }),\n createEntity('messageEntityMention', 32, 6),\n createEntity('messageEntityMentionName', 39, 11, {\n userId: 36265675,\n }),\n createEntity('messageEntityEmail', 51, 12),\n ],\n 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) mail@mail.ru plain',\n )\n })\n\n it('should handle language in pre', () => {\n test(\n 'plain console.log(\"Hello, world!\") some code plain',\n [\n createEntity('messageEntityPre', 6, 28, {\n language: 'javascript',\n }),\n createEntity('messageEntityPre', 35, 9, { language: '' }),\n ],\n 'plain ```javascript\\nconsole.log(\"Hello, world!\")\\n``` ```\\nsome code\\n``` plain',\n )\n })\n\n it('should support entities on the edges', () => {\n test(\n 'Hello, world',\n [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)],\n '**Hello**, **world**',\n )\n })\n\n it('should clamp out-of-range entities', () => {\n test(\n 'Hello, world',\n [createEntity('messageEntityBold', -2, 7), createEntity('messageEntityBold', 7, 10)],\n '**Hello**, **world**',\n )\n })\n\n it('should ignore entities outside the length', () => {\n test('Hello, world', [createEntity('messageEntityBold', 50, 5)], 'Hello, world')\n })\n\n it('should support entities followed by each other', () => {\n test(\n 'plain Hello, world plain',\n [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)],\n [\n 'plain **Hello,**__ world__ plain',\n // not the most obvious order, but who cares :D\n // we support this syntax in parse()\n 'plain **Hello,__** world__ plain',\n ],\n )\n })\n\n it('should support nested entities', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 8)],\n '__Welcome to the **gym zone**!__',\n )\n })\n\n it('should support nested entities with the same edges', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)],\n ['__Welcome to the **gym zone!**__', '__Welcome to the **gym zone!__**'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)],\n ['**Welcome to the __gym zone!__**', '**Welcome to the __gym zone!**__'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 7)],\n ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)],\n [\n '__**Welcome to the gym zone!**__',\n '__**Welcome to the gym zone!__**',\n '**__Welcome to the gym zone!**__',\n '**__Welcome to the gym zone!__**',\n ],\n )\n })\n\n it('should support overlapping entities', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)],\n '__Welcome **to the__ gym** zone!',\n )\n test(\n 'plain bold bold!italic bold!italic!underline underline plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n [\n 'plain **bold __bold!italic --bold!italic!underline**__ underline-- plain',\n 'plain **bold __bold!italic --bold!italic!underline__** underline-- plain',\n ],\n )\n test(\n 'plain bold bold!italic bold!italic!underline italic!underline underline plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 50),\n createEntity('messageEntityUnderline', 23, 48),\n ],\n 'plain **bold __bold!italic --bold!italic!underline** italic!underline__ underline-- plain',\n )\n })\n\n it('should properly handle emojis', () => {\n test(\n \"best flower: 🌸. don't you even doubt it.\",\n [\n createEntity('messageEntityItalic', 0, 11),\n createEntity('messageEntityBold', 13, 2),\n createEntity('messageEntityItalic', 17, 5),\n ],\n \"__best flower__: **🌸**. __don't__ you even doubt it.\",\n )\n })\n\n it('should escape reserved symbols', () => {\n test(\n '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\\\ \\\\\\\\',\n [createEntity('messageEntityItalic', 9, 8)],\n // holy shit\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'\n // so we don't have to escape every single backslash lol\n .replace(/\\//g, '\\\\'),\n )\n test(\n '* ** *** _ __ ___ - -- ---',\n [\n // here we test that the order of the entities does not matter\n createEntity('messageEntityItalic', 18, 4),\n createEntity('messageEntityItalic', 9, 8),\n ],\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\\//g, '\\\\'),\n )\n })\n })\n\n describe('parse', () => {\n const test = (\n texts: string | string[],\n expectedEntities: tl.TypeMessageEntity[],\n expectedText: string,\n ): void => {\n if (!Array.isArray(texts)) texts = [texts]\n\n for (const text of texts) {\n const res = md_(text)\n expect(res.text).eql(expectedText)\n expect(res.entities ?? []).eql(expectedEntities)\n }\n }\n\n it('should handle bold, italic, underline, spoiler and strikethrough', () => {\n test(\n 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain',\n [\n createEntity('messageEntityBold', 6, 4),\n createEntity('messageEntityItalic', 11, 6),\n createEntity('messageEntityUnderline', 18, 9),\n createEntity('messageEntityStrike', 28, 13),\n createEntity('messageEntitySpoiler', 42, 7),\n ],\n 'plain bold italic underline strikethrough spoiler plain',\n )\n })\n\n it('should handle code and pre', () => {\n test(\n [\n 'plain `code` ```\\npre\\n``` `__ignored__` plain',\n 'plain `code` ```\\npre\\n``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n 'plain `code` ```\\npre``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n ],\n [\n createEntity('messageEntityCode', 6, 4),\n createEntity('messageEntityPre', 11, 3, { language: '' }),\n createEntity('messageEntityCode', 15, 11),\n ],\n 'plain code pre __ignored__ plain',\n )\n\n test(\n 'plain ```\\npre with ` and ``\\n``` plain',\n [createEntity('messageEntityPre', 6, 17, { language: '' })],\n 'plain pre with ` and `` plain',\n )\n\n test(\n 'plain ```\\npre with \\n`\\n and \\n``\\nend\\n``` plain',\n [createEntity('messageEntityPre', 6, 24, { language: '' })],\n 'plain pre with \\n`\\n and \\n``\\nend plain',\n )\n })\n\n it('should handle links and text mentions', () => {\n test(\n 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) plain',\n [\n createEntity('messageEntityTextUrl', 25, 6, {\n url: 'https://google.com',\n }),\n createEntity('messageEntityMentionName', 39, 11, {\n userId: 36265675,\n }),\n ],\n 'plain https://google.com google @durov Pavel Durov plain',\n )\n\n test(\n '[user](tg://user?id=1234567&hash=aabbccddaabbccdd)',\n [\n createEntity('inputMessageEntityMentionName', 0, 4, {\n userId: {\n _: 'inputUser',\n userId: 1234567,\n accessHash: Long.fromString('aabbccddaabbccdd', 16),\n },\n }),\n ],\n 'user',\n )\n })\n\n it('should handle language in pre', () => {\n test(\n 'plain ```javascript\\nconsole.log(\"Hello, world!\")\\n``` ```\\nsome code\\n``` plain',\n [\n createEntity('messageEntityPre', 6, 28, {\n language: 'javascript',\n }),\n createEntity('messageEntityPre', 35, 9, { language: '' }),\n ],\n 'plain console.log(\"Hello, world!\") some code plain',\n )\n })\n\n it('should support entities on the edges', () => {\n test(\n '**Hello**, **world**',\n [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)],\n 'Hello, world',\n )\n })\n\n it('should return empty array if there are no entities', () => {\n test('Hello, world', [], 'Hello, world')\n })\n\n it('should support overlapping entities', () => {\n test(\n '__Welcome **to the__ gym** zone!',\n [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)],\n 'Welcome to the gym zone!',\n )\n\n // resulting order will depend on the order in which the closing ** or __ are passed,\n // thus we use separate tests\n test(\n 'plain **bold __bold-italic --bold-italic-underline**__ underline-- plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n 'plain bold bold-italic bold-italic-underline underline plain',\n )\n test(\n 'plain **bold __bold-italic --bold-italic-underline__** underline-- plain',\n [\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n 'plain bold bold-italic bold-italic-underline underline plain',\n )\n\n test(\n 'plain **bold __bold-italic --bold-italic-underline** italic-underline__ underline-- plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 50),\n createEntity('messageEntityUnderline', 23, 48),\n ],\n 'plain bold bold-italic bold-italic-underline italic-underline underline plain',\n )\n })\n\n it('should support entities followed by each other', () => {\n test(\n ['plain **Hello,**__ world__ plain', 'plain **Hello,__** world__ plain'],\n [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)],\n 'plain Hello, world plain',\n )\n })\n\n it('should support nested entities', () => {\n test(\n '__Welcome to the **gym zone**!__',\n [createEntity('messageEntityBold', 15, 8), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n\n test(\n 'plain [__google__](https://google.com) plain',\n [\n createEntity('messageEntityItalic', 6, 6),\n createEntity('messageEntityTextUrl', 6, 6, {\n url: 'https://google.com',\n }),\n ],\n 'plain google plain',\n )\n test(\n 'plain [plain __google__ plain](https://google.com) plain',\n [\n createEntity('messageEntityItalic', 12, 6),\n createEntity('messageEntityTextUrl', 6, 18, {\n url: 'https://google.com',\n }),\n ],\n 'plain plain google plain plain',\n )\n })\n\n it('should support nested entities with the same edges', () => {\n // again, order of the entities depends on which closing tag goes first.\n test(\n '__Welcome to the **gym zone!**__',\n [createEntity('messageEntityBold', 15, 9), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n '__Welcome to the **gym zone!__**',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)],\n 'Welcome to the gym zone!',\n )\n\n test(\n '**Welcome to the __gym zone!__**',\n [createEntity('messageEntityItalic', 15, 9), createEntity('messageEntityBold', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n '**Welcome to the __gym zone!**__',\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)],\n 'Welcome to the gym zone!',\n )\n\n test(\n ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'],\n [createEntity('messageEntityBold', 0, 7), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n\n test(\n ['__**Welcome to the gym zone!**__', '**__Welcome to the gym zone!**__'],\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n ['__**Welcome to the gym zone!__**', '**__Welcome to the gym zone!__**'],\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)],\n 'Welcome to the gym zone!',\n )\n })\n\n it('should properly handle emojis', () => {\n test(\n \"__best flower__: **🌸**. __don't__ you even doubt it.\",\n [\n createEntity('messageEntityItalic', 0, 11),\n createEntity('messageEntityBold', 13, 2),\n createEntity('messageEntityItalic', 17, 5),\n ],\n \"best flower: 🌸. don't you even doubt it.\",\n )\n })\n\n it('should handle escaped reserved symbols', () => {\n test(\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'.replace(\n /\\//g,\n '\\\\',\n ),\n [createEntity('messageEntityItalic', 9, 8)],\n '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\\\ \\\\\\\\',\n )\n test(\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\\//g, '\\\\'),\n [createEntity('messageEntityItalic', 9, 8), createEntity('messageEntityItalic', 18, 4)],\n '* ** *** _ __ ___ - -- ---',\n )\n })\n\n it('should ignore empty urls', () => {\n test('[link]() [link]', [], 'link [link]')\n })\n\n describe('malformed input', () => {\n const testThrows = (input: string) => expect(() => md_(input)).throws(Error)\n\n it('should throw an error on malformed links', () => {\n testThrows('plain [link](https://google.com but unclosed')\n })\n\n it('should throw an error on malformed pres', () => {\n testThrows('plain ```pre without linebreaks```')\n testThrows('plain ``` pre without linebreaks but with spaces instead ```')\n })\n\n it('should throw an error on unterminated entity', () => {\n testThrows('plain **bold but unclosed')\n testThrows('plain **bold and __also italic but unclosed')\n })\n })\n })\n\n describe('template', () => {\n const test = (text: TextWithEntities, expectedEntities: tl.TypeMessageEntity[], expectedText: string): void => {\n expect(text.text).eql(expectedText)\n expect(text.entities ?? []).eql(expectedEntities)\n }\n\n it('should add plain strings as is', () => {\n test(md_`${'**plain**'}`, [], '**plain**')\n })\n\n it('should skip falsy values', () => {\n test(md_`some text ${null} more text ${false}`, [], 'some text more text ')\n })\n\n it('should properly dedent', () => {\n test(\n md_`\n some text\n **bold**\n more text\n `,\n [createEntity('messageEntityBold', 10, 4)],\n 'some text\\nbold\\nmore text',\n )\n })\n\n it('should process entities', () => {\n const inner = md_`**bold**`\n\n test(\n md_`some text ${inner} some more text`,\n [createEntity('messageEntityBold', 10, 4)],\n 'some text bold some more text',\n )\n test(\n md_`some text ${inner} some more ${inner} text`,\n [createEntity('messageEntityBold', 10, 4), createEntity('messageEntityBold', 25, 4)],\n 'some text bold some more bold text',\n )\n })\n\n it('should process entities on edges', () => {\n test(\n md_`${md_`**bold**`} and ${md_`__italic__`}`,\n [createEntity('messageEntityBold', 0, 4), createEntity('messageEntityItalic', 9, 6)],\n 'bold and italic',\n )\n })\n\n it('should process nested entities', () => {\n test(\n md_`**bold ${md_`__bold italic__`} more bold**`,\n [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)],\n 'bold bold italic more bold',\n )\n test(\n md_`**bold ${md_`__bold italic__ --and some underline--`} more bold**`,\n [\n createEntity('messageEntityItalic', 5, 11),\n createEntity('messageEntityUnderline', 17, 18),\n createEntity('messageEntityBold', 0, 45),\n ],\n 'bold bold italic and some underline more bold',\n )\n test(\n md_`**${md_`__bold italic --underline--__`}**`,\n [\n createEntity('messageEntityUnderline', 12, 9),\n createEntity('messageEntityItalic', 0, 21),\n createEntity('messageEntityBold', 0, 21),\n ],\n 'bold italic underline',\n )\n })\n\n it('should process MessageEntity', () => {\n test(\n md_`**bold ${new MessageEntity(createEntity('messageEntityItalic', 0, 11), 'bold italic')} more bold**`,\n [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)],\n 'bold bold italic more bold',\n )\n })\n })\n})\n"]}
|