@markuplint/html-parser 3.11.0 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +0,0 @@
1
- const {
2
- isStartsHeadTagOrBodyTag,
3
- optimizeStartsHeadTagOrBodyTagSetup,
4
- } = require('../lib/optimize-starts-head-or-body');
5
-
6
- test('isStartsHeadTagOrBodyTag', () => {
7
- expect(isStartsHeadTagOrBodyTag('<head>')).toBeTruthy();
8
- expect(isStartsHeadTagOrBodyTag(' <head>')).toBeTruthy();
9
- expect(isStartsHeadTagOrBodyTag('<body>')).toBeTruthy();
10
- expect(isStartsHeadTagOrBodyTag(' <body>')).toBeTruthy();
11
- expect(isStartsHeadTagOrBodyTag('<html>')).toBeFalsy();
12
- expect(isStartsHeadTagOrBodyTag('<!doctype>')).toBeFalsy();
13
- });
14
-
15
- test('optimizeStartsHeadTagOrBodyTagSetup', () => {
16
- expect(
17
- optimizeStartsHeadTagOrBodyTagSetup(
18
- '<head attr></Head></head><body>body</head>head<body></BODY attr><headline />',
19
- ),
20
- ).toStrictEqual({
21
- heads: ['head', 'Head', 'head', 'head'],
22
- bodies: ['body', 'body', 'BODY'],
23
- code: '<x-�h attr></x-�h></x-�h><x-�b>body</x-�h>head<x-�b></x-�b attr><headline />',
24
- });
25
- });
@@ -1,483 +0,0 @@
1
- const parseRawTag = require('../lib/parse-raw-tag').default;
2
-
3
- test('tag only', () => {
4
- expect(parseRawTag('<div>', 1, 1, 0)).toMatchObject({
5
- tagName: 'div',
6
- attrs: [],
7
- });
8
- });
9
-
10
- test('tag only has space', () => {
11
- expect(parseRawTag('<div >', 1, 1, 0)).toMatchObject({
12
- tagName: 'div',
13
- attrs: [],
14
- });
15
- });
16
-
17
- test('tag only has spaces', () => {
18
- expect(parseRawTag('<div >', 1, 1, 0)).toMatchObject({
19
- tagName: 'div',
20
- attrs: [],
21
- selfClosingSolidus: {
22
- raw: '',
23
- },
24
- endSpace: {
25
- raw: ' ',
26
- },
27
- });
28
- });
29
-
30
- test('self closing tag', () => {
31
- expect(parseRawTag('<div />', 1, 1, 0)).toMatchObject({
32
- tagName: 'div',
33
- attrs: [],
34
- selfClosingSolidus: {
35
- raw: ' /',
36
- },
37
- endSpace: {
38
- raw: '',
39
- },
40
- });
41
- });
42
-
43
- test('has attribute', () => {
44
- expect(parseRawTag('<div a>', 1, 1, 0)).toMatchObject({
45
- tagName: 'div',
46
- attrs: [
47
- {
48
- raw: 'a',
49
- startLine: 1,
50
- endLine: 1,
51
- startCol: 6,
52
- endCol: 7,
53
- startOffset: 5,
54
- endOffset: 6,
55
- spacesBeforeName: {
56
- raw: ' ',
57
- startLine: 1,
58
- endLine: 1,
59
- startCol: 5,
60
- endCol: 6,
61
- startOffset: 4,
62
- endOffset: 5,
63
- },
64
- name: {
65
- raw: 'a',
66
- startLine: 1,
67
- endLine: 1,
68
- startCol: 6,
69
- endCol: 7,
70
- startOffset: 5,
71
- endOffset: 6,
72
- },
73
- },
74
- ],
75
- });
76
- });
77
-
78
- test('2 attributes', () => {
79
- expect(parseRawTag('<div b c>', 1, 1, 0)).toMatchObject({
80
- tagName: 'div',
81
- attrs: [
82
- {
83
- raw: 'b',
84
- startLine: 1,
85
- endLine: 1,
86
- startCol: 6,
87
- endCol: 7,
88
- startOffset: 5,
89
- endOffset: 6,
90
- spacesBeforeName: {
91
- raw: ' ',
92
- startLine: 1,
93
- endLine: 1,
94
- startCol: 5,
95
- endCol: 6,
96
- startOffset: 4,
97
- endOffset: 5,
98
- },
99
- name: {
100
- raw: 'b',
101
- startLine: 1,
102
- endLine: 1,
103
- startCol: 6,
104
- endCol: 7,
105
- startOffset: 5,
106
- endOffset: 6,
107
- },
108
- },
109
- {
110
- raw: 'c',
111
- startLine: 1,
112
- endLine: 1,
113
- startCol: 8,
114
- endCol: 9,
115
- startOffset: 7,
116
- endOffset: 8,
117
- spacesBeforeName: {
118
- raw: ' ',
119
- startLine: 1,
120
- endLine: 1,
121
- startCol: 7,
122
- endCol: 8,
123
- startOffset: 6,
124
- endOffset: 7,
125
- },
126
- name: {
127
- raw: 'c',
128
- startLine: 1,
129
- endLine: 1,
130
- startCol: 8,
131
- endCol: 9,
132
- startOffset: 7,
133
- endOffset: 8,
134
- },
135
- },
136
- ],
137
- });
138
- });
139
-
140
- test('3 attributes', () => {
141
- expect(parseRawTag('<div a a a>', 1, 1, 0).attrs.length).toBe(3);
142
- });
143
-
144
- test('has line break', () => {
145
- expect(
146
- parseRawTag(
147
- `<div
148
- a>`,
149
- 1,
150
- 1,
151
- 0,
152
- ),
153
- ).toMatchObject({
154
- tagName: 'div',
155
- attrs: [
156
- {
157
- raw: 'a',
158
- startLine: 2,
159
- endLine: 2,
160
- startCol: 1,
161
- endCol: 2,
162
- startOffset: 5,
163
- endOffset: 6,
164
- spacesBeforeName: {
165
- raw: '\n',
166
- startLine: 1,
167
- endLine: 2,
168
- startCol: 5,
169
- endCol: 1,
170
- startOffset: 4,
171
- endOffset: 5,
172
- },
173
- name: {
174
- raw: 'a',
175
- startLine: 2,
176
- endLine: 2,
177
- startCol: 1,
178
- endCol: 2,
179
- startOffset: 5,
180
- endOffset: 6,
181
- },
182
- },
183
- ],
184
- });
185
- });
186
-
187
- test('has multiple line breaks', () => {
188
- expect(
189
- parseRawTag(
190
- `<div
191
-
192
-
193
- a>`,
194
- 1,
195
- 1,
196
- 0,
197
- ),
198
- ).toMatchObject({
199
- tagName: 'div',
200
- attrs: [
201
- {
202
- raw: 'a',
203
- startLine: 4,
204
- endLine: 4,
205
- startCol: 4,
206
- endCol: 5,
207
- startOffset: 10,
208
- endOffset: 11,
209
- spacesBeforeName: {
210
- raw: '\n\n\n\t\t\t',
211
- startLine: 1,
212
- endLine: 4,
213
- startCol: 5,
214
- endCol: 4,
215
- startOffset: 4,
216
- endOffset: 10,
217
- },
218
- name: {
219
- raw: 'a',
220
- startLine: 4,
221
- endLine: 4,
222
- startCol: 4,
223
- endCol: 5,
224
- startOffset: 10,
225
- endOffset: 11,
226
- },
227
- },
228
- ],
229
- });
230
- });
231
-
232
- test('after line break', () => {
233
- const { attrs } = parseRawTag(
234
- `<div attr
235
- attr2="value"
236
- attr3
237
- >`,
238
- 1,
239
- 1,
240
- 0,
241
- );
242
- expect(attrs[1]).toMatchObject({
243
- spacesBeforeName: {
244
- raw: '\n\t\t\t\t',
245
- startLine: 1,
246
- endLine: 2,
247
- startCol: 10,
248
- endCol: 5,
249
- startOffset: 9,
250
- endOffset: 14,
251
- },
252
- });
253
- });
254
-
255
- test('standard', () => {
256
- expect(
257
- parseRawTag(
258
- `<div
259
- a
260
- b c
261
- d>
262
- `,
263
- 1,
264
- 1,
265
- 0,
266
- ),
267
- ).toMatchObject({
268
- tagName: 'div',
269
- attrs: [
270
- {
271
- name: {
272
- raw: 'a',
273
- },
274
- startLine: 2,
275
- startCol: 6,
276
- raw: 'a',
277
- },
278
- {
279
- name: {
280
- raw: 'b',
281
- },
282
- startLine: 3,
283
- startCol: 7,
284
- raw: 'b',
285
- },
286
- {
287
- name: {
288
- raw: 'c',
289
- },
290
- startLine: 3,
291
- startCol: 9,
292
- raw: 'c',
293
- },
294
- {
295
- name: {
296
- raw: 'd',
297
- },
298
- startLine: 4,
299
- startCol: 7,
300
- raw: 'd',
301
- },
302
- ],
303
- });
304
- });
305
-
306
- test('standard', () => {
307
- expect(parseRawTag('<div a=a>', 1, 1, 0)).toMatchObject({
308
- tagName: 'div',
309
- attrs: [
310
- {
311
- raw: 'a=a',
312
- spacesBeforeName: { raw: ' ' },
313
- name: { raw: 'a' },
314
- spacesBeforeEqual: { raw: '' },
315
- equal: { raw: '=' },
316
- spacesAfterEqual: { raw: '' },
317
- startQuote: { raw: '' },
318
- value: { raw: 'a' },
319
- endQuote: { raw: '' },
320
- startLine: 1,
321
- startCol: 6,
322
- },
323
- ],
324
- });
325
- });
326
-
327
- test('standard', () => {
328
- expect(
329
- parseRawTag(
330
- `<div
331
- a
332
- =
333
- "ab
334
- c"
335
- >`,
336
- 1,
337
- 1,
338
- 0,
339
- ),
340
- ).toMatchObject({
341
- tagName: 'div',
342
- attrs: [
343
- {
344
- raw: 'a\n\t=\n\t"ab\nc"',
345
- startLine: 2,
346
- endLine: 5,
347
- startCol: 1,
348
- endCol: 3,
349
- startOffset: 5,
350
- endOffset: 17,
351
- spacesBeforeName: {
352
- raw: '\n',
353
- startLine: 1,
354
- endLine: 2,
355
- startCol: 5,
356
- endCol: 1,
357
- startOffset: 4,
358
- endOffset: 5,
359
- },
360
- name: {
361
- raw: 'a',
362
- startLine: 2,
363
- endLine: 2,
364
- startCol: 1,
365
- endCol: 2,
366
- startOffset: 5,
367
- endOffset: 6,
368
- },
369
- spacesBeforeEqual: {
370
- raw: '\n\t',
371
- startLine: 2,
372
- endLine: 3,
373
- startCol: 2,
374
- endCol: 2,
375
- startOffset: 6,
376
- endOffset: 8,
377
- },
378
- equal: {
379
- raw: '=',
380
- startLine: 3,
381
- endLine: 3,
382
- startCol: 2,
383
- endCol: 3,
384
- startOffset: 8,
385
- endOffset: 9,
386
- },
387
- spacesAfterEqual: {
388
- raw: '\n\t',
389
- startLine: 3,
390
- endLine: 4,
391
- startCol: 3,
392
- endCol: 2,
393
- startOffset: 9,
394
- endOffset: 11,
395
- },
396
- startQuote: {
397
- raw: '"',
398
- startLine: 4,
399
- endLine: 4,
400
- startCol: 2,
401
- endCol: 3,
402
- startOffset: 11,
403
- endOffset: 12,
404
- },
405
- value: {
406
- raw: 'ab\nc',
407
- startLine: 4,
408
- endLine: 5,
409
- startCol: 3,
410
- endCol: 2,
411
- startOffset: 12,
412
- endOffset: 16,
413
- },
414
- endQuote: {
415
- raw: '"',
416
- startLine: 5,
417
- endLine: 5,
418
- startCol: 2,
419
- endCol: 3,
420
- startOffset: 16,
421
- endOffset: 17,
422
- },
423
- },
424
- ],
425
- });
426
- });
427
-
428
- test('void element', () => {
429
- expect(parseRawTag('<img/>', 1, 1, 0)).toMatchObject({
430
- tagName: 'img',
431
- attrs: [],
432
- });
433
- });
434
-
435
- test('void element', () => {
436
- expect(parseRawTag('<void />', 1, 1, 0)).toMatchObject({
437
- tagName: 'void',
438
- attrs: [],
439
- });
440
- });
441
-
442
- test('namespace', () => {
443
- expect(parseRawTag('<ns:div>', 1, 1, 0)).toMatchObject({
444
- tagName: 'ns:div',
445
- attrs: [],
446
- });
447
- });
448
-
449
- test('custom element', () => {
450
- expect(parseRawTag('<a😁-element>', 1, 1, 0)).toMatchObject({
451
- tagName: 'a😁-element',
452
- attrs: [],
453
- });
454
- });
455
-
456
- test('custom element with full-width space', () => {
457
- expect(parseRawTag('<a -element>', 1, 1, 0)).toMatchObject({
458
- tagName: 'a -element',
459
- attrs: [],
460
- });
461
- });
462
-
463
- describe('error', () => {
464
- test('SyntaxError: <div', () => {
465
- expect(() => parseRawTag('<div', 1, 1, 0)).toThrow('Invalid tag syntax: "<div"');
466
- });
467
-
468
- test('SyntaxError: <>', () => {
469
- expect(() => parseRawTag('<>', 1, 1, 0)).toThrow('Invalid tag syntax: "<>"');
470
- });
471
-
472
- test('SyntaxError: < >', () => {
473
- expect(() => parseRawTag('< >', 1, 1, 0)).toThrow('Invalid tag name: "" in < >');
474
- });
475
-
476
- test('SyntaxError: <要素>', () => {
477
- expect(() => parseRawTag('<要素>', 1, 1, 0)).toThrow('Invalid tag name: "要素" in <要素>');
478
- });
479
- });
480
-
481
- test('include gt sign', () => {
482
- expect(parseRawTag('<div a=" > ">', 1, 1, 0).attrs[0].raw).toBe('a=" > "');
483
- });