@mdsvex/render 1.0.0-next.0 → 1.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +294 -0
- package/dist/component.js +6 -6
- package/dist/html_cursor.js +3860 -434
- package/dist/index.js +24 -18
- package/dist/mappings.js +151 -8
- package/dist/sourcemap.js +832 -68
- package/package.json +2 -2
- package/src/Node.svelte +158 -99
- package/src/component.ts +8 -8
- package/src/entities.ts +226 -0
- package/src/html_cursor.ts +5457 -523
- package/src/index.ts +33 -9
- package/src/mappings.ts +239 -4
- package/src/scope.ts +127 -0
- package/src/sourcemap.ts +1708 -99
- package/test/component.spec.ts +3 -3
- package/test/escape_text.spec.ts +90 -0
- package/test/highlight.spec.ts +242 -0
- package/test/html_cursor.spec.ts +415 -6
- package/test/mappings.spec.ts +294 -27
- package/test/scripts.spec.ts +225 -0
- package/test/trace.spec.ts +247 -0
- package/test/wire_tree_builder.spec.ts +17 -0
package/test/html_cursor.spec.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
|
|
|
2
2
|
import { PFMParser } from '@mdsvex/parse';
|
|
3
3
|
import { TreeBuilder } from '@mdsvex/parse/tree-builder';
|
|
4
4
|
import { Cursor } from '@mdsvex/parse/cursor';
|
|
5
|
-
import { CursorHTMLRenderer } from '../src/html_cursor';
|
|
5
|
+
import { ComponentScope, CursorHTMLRenderer } from '../src/html_cursor';
|
|
6
6
|
|
|
7
7
|
// Helpers ��
|
|
8
8
|
|
|
@@ -173,17 +173,19 @@ describe('CursorHTMLRenderer', () => {
|
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
it('svelte void tag {@html}', () => {
|
|
176
|
-
expect(render('{@html "<b>bold</b>"}')).toBe(
|
|
177
|
-
'<p>{@html "<b>bold</b>"}</p>'
|
|
178
|
-
);
|
|
176
|
+
expect(render('{@html "<b>bold</b>"}')).toBe('{@html "<b>bold</b>"}');
|
|
179
177
|
});
|
|
180
178
|
|
|
181
179
|
it('svelte void tag {@debug}', () => {
|
|
182
|
-
expect(render('{@debug myVar}')).toBe('
|
|
180
|
+
expect(render('{@debug myVar}')).toBe('{@debug myVar}');
|
|
183
181
|
});
|
|
184
182
|
|
|
185
183
|
it('svelte void tag {@const} no expression', () => {
|
|
186
|
-
expect(render('{@debug}')).toBe('
|
|
184
|
+
expect(render('{@debug}')).toBe('{@debug}');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('svelte void tag with text keeps the paragraph', () => {
|
|
188
|
+
expect(render('{@html raw} after')).toBe('<p>{@html raw} after</p>');
|
|
187
189
|
});
|
|
188
190
|
|
|
189
191
|
it('simple if block', () => {
|
|
@@ -229,3 +231,410 @@ describe('CursorHTMLRenderer', () => {
|
|
|
229
231
|
expect(html).toBe('{#if show}\n<h1>Title</h1>{/if}');
|
|
230
232
|
});
|
|
231
233
|
});
|
|
234
|
+
|
|
235
|
+
describe('static chunk fold', () => {
|
|
236
|
+
function parse(source: string) {
|
|
237
|
+
const tree = new TreeBuilder(source.length >> 3 || 128);
|
|
238
|
+
new PFMParser(tree).parse(source);
|
|
239
|
+
return tree.get_buffer();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
it('keeps output past the composite length cap', () => {
|
|
243
|
+
const html = render('x\n\n' + '***\n\n'.repeat(60));
|
|
244
|
+
expect(html).toBe('<p>x</p>' + '<hr />'.repeat(60));
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('matches the mapped render, which does not fold', () => {
|
|
248
|
+
const source =
|
|
249
|
+
'# Title\n\n> quote\n\n- one\n- two\n\n| a | b |\n|:--|--:|\n| 1 | 2 |\n\n' +
|
|
250
|
+
'[link](/x "t") and  and `code`\n\n---\n\n```js\nx\n```\n\n' +
|
|
251
|
+
'<div class="a">b</div>\n\n<br />\n\n{#if a}\nyes\n{:else}\nno\n{/if}\n\n{@html x}\n';
|
|
252
|
+
const buf = parse(source);
|
|
253
|
+
const folded = new CursorHTMLRenderer({ cache: false });
|
|
254
|
+
folded.update(buf, source);
|
|
255
|
+
const mapped = new CursorHTMLRenderer({ cache: false });
|
|
256
|
+
mapped.update_mapped(buf, source);
|
|
257
|
+
expect(folded.html).toBe(mapped.html);
|
|
258
|
+
const cached = new CursorHTMLRenderer();
|
|
259
|
+
cached.update(buf, source);
|
|
260
|
+
expect(cached.html).toBe(mapped.html);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('raw html attribute values', () => {
|
|
265
|
+
const cases: [string, string][] = [
|
|
266
|
+
['<div title="a & b">x</div>\n', '<div title="a & b">x</div>'],
|
|
267
|
+
['<div title="a & <b>">x</div>\n', '<div title="a & <b>">x</div>'],
|
|
268
|
+
[
|
|
269
|
+
`<div title='"a" & b'>x</div>\n`,
|
|
270
|
+
'<div title=""a" & b">x</div>',
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
'text <span title="<>">x</span>\n',
|
|
274
|
+
'<p>text <span title="<>">x</span></p>',
|
|
275
|
+
],
|
|
276
|
+
];
|
|
277
|
+
|
|
278
|
+
for (const [input, expected] of cases) {
|
|
279
|
+
it(JSON.stringify(input), () => {
|
|
280
|
+
const tree = new TreeBuilder(128);
|
|
281
|
+
new PFMParser(tree).parse(input);
|
|
282
|
+
const buf = tree.get_buffer();
|
|
283
|
+
const folded = new CursorHTMLRenderer({ cache: false });
|
|
284
|
+
folded.update(buf, input);
|
|
285
|
+
expect(folded.html).toBe(expected);
|
|
286
|
+
const mapped = new CursorHTMLRenderer({ cache: false });
|
|
287
|
+
mapped.update_mapped(buf, input);
|
|
288
|
+
expect(mapped.html).toBe(expected);
|
|
289
|
+
const cached = new CursorHTMLRenderer();
|
|
290
|
+
cached.update(buf, input);
|
|
291
|
+
expect(cached.html).toBe(expected);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
describe('character references', () => {
|
|
297
|
+
const cases: [string, string][] = [
|
|
298
|
+
['a < b ©\n', '<p>a < b ©</p>'],
|
|
299
|
+
['<div>a — b</div>\n', '<div>a — b</div>'],
|
|
300
|
+
[
|
|
301
|
+
'{ } &MadeUp; © & \\& `& x`\n',
|
|
302
|
+
'<p>{ } &MadeUp; &copy & &amp; <code>&amp; x</code></p>',
|
|
303
|
+
],
|
|
304
|
+
[
|
|
305
|
+
'> ```\n> < ©\n> ```\n',
|
|
306
|
+
'<blockquote>\n<pre><code>&lt; &copy;</code></pre>\n</blockquote>',
|
|
307
|
+
],
|
|
308
|
+
[
|
|
309
|
+
'[a & b](/x?a&b ""t"") \n',
|
|
310
|
+
'<p><a href="/x?a&b" title=""t"">a & b</a> <img src="/i?a&b" alt="©" /></p>',
|
|
311
|
+
],
|
|
312
|
+
];
|
|
313
|
+
|
|
314
|
+
for (const [input, expected] of cases) {
|
|
315
|
+
it(JSON.stringify(input), () => {
|
|
316
|
+
const tree = new TreeBuilder(128);
|
|
317
|
+
new PFMParser(tree).parse(input);
|
|
318
|
+
const buf = tree.get_buffer();
|
|
319
|
+
const folded = new CursorHTMLRenderer({ cache: false });
|
|
320
|
+
folded.update(buf, input);
|
|
321
|
+
expect(folded.html).toBe(expected);
|
|
322
|
+
const mapped = new CursorHTMLRenderer({ cache: false });
|
|
323
|
+
mapped.update_mapped(buf, input);
|
|
324
|
+
expect(mapped.html).toBe(expected);
|
|
325
|
+
const traced = new CursorHTMLRenderer({ cache: false });
|
|
326
|
+
traced.update_trace(buf, input);
|
|
327
|
+
expect(traced.html).toBe(expected);
|
|
328
|
+
const cached = new CursorHTMLRenderer();
|
|
329
|
+
cached.update(buf, input);
|
|
330
|
+
expect(cached.html).toBe(expected);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
describe('braces in code', () => {
|
|
336
|
+
const cases: [string, string][] = [
|
|
337
|
+
[
|
|
338
|
+
'Use `{ a: 1 }` here.\n',
|
|
339
|
+
'<p>Use <code>{ a: 1 }</code> here.</p>',
|
|
340
|
+
],
|
|
341
|
+
[
|
|
342
|
+
'```js {1}\nconst o = { a: 1 };\n```\n',
|
|
343
|
+
'<pre><code class="language-js">const o = { a: 1 };</code></pre>',
|
|
344
|
+
],
|
|
345
|
+
[
|
|
346
|
+
'> ```\n> {a} <\n> ```\n',
|
|
347
|
+
'<blockquote>\n<pre><code>{a} &lt;</code></pre>\n</blockquote>',
|
|
348
|
+
],
|
|
349
|
+
[
|
|
350
|
+
'```sh title="shell" {1}\nls\n```\n',
|
|
351
|
+
'<pre><code class="language-sh">ls</code></pre>',
|
|
352
|
+
],
|
|
353
|
+
];
|
|
354
|
+
|
|
355
|
+
for (const [input, expected] of cases) {
|
|
356
|
+
it(JSON.stringify(input), () => {
|
|
357
|
+
const tree = new TreeBuilder(128);
|
|
358
|
+
new PFMParser(tree).parse(input);
|
|
359
|
+
const buf = tree.get_buffer();
|
|
360
|
+
const folded = new CursorHTMLRenderer({ cache: false });
|
|
361
|
+
folded.update(buf, input);
|
|
362
|
+
expect(folded.html).toBe(expected);
|
|
363
|
+
const mapped = new CursorHTMLRenderer({ cache: false });
|
|
364
|
+
mapped.update_mapped(buf, input);
|
|
365
|
+
expect(mapped.html).toBe(expected);
|
|
366
|
+
const traced = new CursorHTMLRenderer({ cache: false });
|
|
367
|
+
traced.update_trace(buf, input);
|
|
368
|
+
expect(traced.html).toBe(expected);
|
|
369
|
+
const cached = new CursorHTMLRenderer();
|
|
370
|
+
cached.update(buf, input);
|
|
371
|
+
expect(cached.html).toBe(expected);
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
describe('paragraphs around tags and components', () => {
|
|
377
|
+
const cases: [string, string][] = [
|
|
378
|
+
['<X />\n', '<X />'],
|
|
379
|
+
['<X /> <Y />\n', '<X /> <Y />'],
|
|
380
|
+
['<X />\n<Y />\n', '<X />\n<Y />'],
|
|
381
|
+
['<X>child</X>\n', '<X>child</X>'],
|
|
382
|
+
['<img src="a.png">\n', '<img src="a.png">'],
|
|
383
|
+
['<!-- note -->\n', '<!-- note -->'],
|
|
384
|
+
['<X /> hello\n', '<p><X /> hello</p>'],
|
|
385
|
+
['<X />\nhello *world*\n', '<p><X />\nhello <strong>world</strong></p>'],
|
|
386
|
+
['hello\n<X />\n', '<p>hello\n<X /></p>'],
|
|
387
|
+
['a <X />\n<Y />\n', '<p>a <X />\n<Y /></p>'],
|
|
388
|
+
['<X>child</X> after\n', '<p><X>child</X> after</p>'],
|
|
389
|
+
['{title}\n', '<p>{title}</p>'],
|
|
390
|
+
['<div><p>hi</p></div>\n', '<div><p>hi</p></div>'],
|
|
391
|
+
['<div>a</div>\n', '<div>a</div>'],
|
|
392
|
+
['<div>*a*</div>\n', '<div><strong>a</strong></div>'],
|
|
393
|
+
['<div>a</div> b\n', '<div>a</div> b'],
|
|
394
|
+
['<div>\n# hi\n</div>\n', '<div><h1>hi</h1></div>'],
|
|
395
|
+
[
|
|
396
|
+
'<details><summary>Title</summary>\n\nBody\n\n</details>\n',
|
|
397
|
+
'<details><summary>Title</summary><p>Body</p></details>',
|
|
398
|
+
],
|
|
399
|
+
['<p>\ntext\n</p>\n', '<p>text</p>'],
|
|
400
|
+
['<span>\ntext\n</span>\n', '<span>text</span>'],
|
|
401
|
+
];
|
|
402
|
+
|
|
403
|
+
for (const [input, expected] of cases) {
|
|
404
|
+
it(JSON.stringify(input), () => {
|
|
405
|
+
expect(render(input).replace(/\n+$/, '')).toBe(expected);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
describe('directives no component replaces', () => {
|
|
411
|
+
const cases: [string, string][] = [
|
|
412
|
+
['::x[a *b*]\n', ''],
|
|
413
|
+
[':::x[a *b*]\nbody\n:::\n', '<p>body</p>'],
|
|
414
|
+
['a\n\n::x[`l` :y[i]](k=v)\n\nc\n', '<p>a</p><p>c</p>'],
|
|
415
|
+
];
|
|
416
|
+
it.each(cases)('every walk leaves out the label of %j', (source, html) => {
|
|
417
|
+
const parse = () => {
|
|
418
|
+
const tree = new TreeBuilder(64);
|
|
419
|
+
new PFMParser(tree).parse(source);
|
|
420
|
+
return tree.get_buffer();
|
|
421
|
+
};
|
|
422
|
+
expect(render(source)).toBe(html);
|
|
423
|
+
const cached = new CursorHTMLRenderer();
|
|
424
|
+
cached.update(parse(), source);
|
|
425
|
+
expect(cached.html).toBe(html);
|
|
426
|
+
const mapped = new CursorHTMLRenderer({ cache: false });
|
|
427
|
+
mapped.update_mapped(parse(), source);
|
|
428
|
+
expect(mapped.html).toBe(html);
|
|
429
|
+
const traced = new CursorHTMLRenderer({ cache: false });
|
|
430
|
+
traced.update_trace(parse(), source);
|
|
431
|
+
expect(traced.html).toBe(html);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
describe('code fences inside block quotes', () => {
|
|
436
|
+
const cases: [string, string, string][] = [
|
|
437
|
+
[
|
|
438
|
+
'depth 1',
|
|
439
|
+
'> ```js\n> a\n> b\n> ```\n',
|
|
440
|
+
'<blockquote>\n<pre><code class="language-js">a\nb</code></pre>\n</blockquote>',
|
|
441
|
+
],
|
|
442
|
+
[
|
|
443
|
+
'depth 2',
|
|
444
|
+
'> > ```\n> > a\n> > b\n> > ```\n',
|
|
445
|
+
'<blockquote>\n<blockquote>\n<pre><code>a\nb</code></pre>\n</blockquote>\n</blockquote>',
|
|
446
|
+
],
|
|
447
|
+
[
|
|
448
|
+
'a blank > line',
|
|
449
|
+
'> ```\n> a\n>\n> b\n> ```\n',
|
|
450
|
+
'<blockquote>\n<pre><code>a\n\nb</code></pre>\n</blockquote>',
|
|
451
|
+
],
|
|
452
|
+
[
|
|
453
|
+
'indented content',
|
|
454
|
+
'> ```\n> a\n> b\n> ```\n',
|
|
455
|
+
'<blockquote>\n<pre><code>a\n b</code></pre>\n</blockquote>',
|
|
456
|
+
],
|
|
457
|
+
[
|
|
458
|
+
'markers without a space',
|
|
459
|
+
'>```\n>a\n>>b\n>```\n',
|
|
460
|
+
'<blockquote>\n<pre><code>a\n>b</code></pre>\n</blockquote>',
|
|
461
|
+
],
|
|
462
|
+
];
|
|
463
|
+
it.each(cases)('every walk strips the markers, %s', (_, source, html) => {
|
|
464
|
+
const parse = () => {
|
|
465
|
+
const tree = new TreeBuilder(64);
|
|
466
|
+
new PFMParser(tree).parse(source);
|
|
467
|
+
return tree.get_buffer();
|
|
468
|
+
};
|
|
469
|
+
expect(render(source)).toBe(html);
|
|
470
|
+
const cached = new CursorHTMLRenderer();
|
|
471
|
+
cached.update(parse(), source);
|
|
472
|
+
expect(cached.html).toBe(html);
|
|
473
|
+
const mapped = new CursorHTMLRenderer({ cache: false });
|
|
474
|
+
mapped.update_mapped(parse(), source);
|
|
475
|
+
expect(mapped.html).toBe(html);
|
|
476
|
+
const traced = new CursorHTMLRenderer({ cache: false });
|
|
477
|
+
traced.update_trace(parse(), source);
|
|
478
|
+
expect(traced.html).toBe(html);
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
describe('extended tables', () => {
|
|
483
|
+
function parse(source: string) {
|
|
484
|
+
const tree = new TreeBuilder(source.length >> 3 || 128);
|
|
485
|
+
new PFMParser(tree).parse(source);
|
|
486
|
+
return tree.get_buffer();
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** the html every walk renders, the cached one only without replacements */
|
|
490
|
+
function every_walk(source: string, scope?: ComponentScope): string {
|
|
491
|
+
const walks: string[] = [];
|
|
492
|
+
const folded = new CursorHTMLRenderer({ cache: false });
|
|
493
|
+
const mapped = new CursorHTMLRenderer({ cache: false });
|
|
494
|
+
const traced = new CursorHTMLRenderer({ cache: false });
|
|
495
|
+
if (scope) folded.scope = mapped.scope = traced.scope = scope;
|
|
496
|
+
folded.update(parse(source), source);
|
|
497
|
+
mapped.update_mapped(parse(source), source);
|
|
498
|
+
traced.update_trace(parse(source), source);
|
|
499
|
+
walks.push(folded.html, mapped.html, traced.html);
|
|
500
|
+
if (!scope) {
|
|
501
|
+
const cached = new CursorHTMLRenderer();
|
|
502
|
+
cached.update(parse(source), source);
|
|
503
|
+
walks.push(cached.html);
|
|
504
|
+
}
|
|
505
|
+
for (const html of walks) expect(html).toBe(walks[0]);
|
|
506
|
+
return walks[0];
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const table = (head: string, body: string) =>
|
|
510
|
+
`<table>\n<thead>\n<tr>\n${head}</tr>\n</thead>\n<tbody>\n${body}</tbody>\n</table>`;
|
|
511
|
+
|
|
512
|
+
const cases: [string, string, string][] = [
|
|
513
|
+
[
|
|
514
|
+
'left header columns',
|
|
515
|
+
'| h || a | b |\n|---||---|---|\n| 1 || 2 | 3 |\n',
|
|
516
|
+
table(
|
|
517
|
+
'<th>h</th>\n<th>a</th>\n<th>b</th>\n',
|
|
518
|
+
'<tr>\n<th scope="row">1</th>\n<td>2</td>\n<td>3</td>\n</tr>\n'
|
|
519
|
+
),
|
|
520
|
+
],
|
|
521
|
+
[
|
|
522
|
+
'right header columns',
|
|
523
|
+
'| a | b || r |\n|---|---||---|\n| 1 | 2 || 3 |\n',
|
|
524
|
+
table(
|
|
525
|
+
'<th>a</th>\n<th>b</th>\n<th>r</th>\n',
|
|
526
|
+
'<tr>\n<td>1</td>\n<td>2</td>\n<th scope="row">3</th>\n</tr>\n'
|
|
527
|
+
),
|
|
528
|
+
],
|
|
529
|
+
[
|
|
530
|
+
'header columns on both sides',
|
|
531
|
+
'| l || a || r |\n|:--||---||--:|\n| 1 || 2 || 3 |\n',
|
|
532
|
+
table(
|
|
533
|
+
'<th align="left">l</th>\n<th>a</th>\n<th align="right">r</th>\n',
|
|
534
|
+
'<tr>\n<th scope="row" align="left">1</th>\n<td>2</td>\n<th scope="row" align="right">3</th>\n</tr>\n'
|
|
535
|
+
),
|
|
536
|
+
],
|
|
537
|
+
[
|
|
538
|
+
'colspan in the header row',
|
|
539
|
+
'| a | b |> | c |\n|---|---|---|---|\n| 1 | 2 | 3 | 4 |\n',
|
|
540
|
+
table(
|
|
541
|
+
'<th>a</th>\n<th colspan="2">b</th>\n<th>c</th>\n',
|
|
542
|
+
'<tr>\n<td>1</td>\n<td>2</td>\n<td>3</td>\n<td>4</td>\n</tr>\n'
|
|
543
|
+
),
|
|
544
|
+
],
|
|
545
|
+
[
|
|
546
|
+
'colspan in body rows',
|
|
547
|
+
'| a | b | c |\n|---|---|---|\n| 1 | 2 |> |\n| x |> |> |\n',
|
|
548
|
+
table(
|
|
549
|
+
'<th>a</th>\n<th>b</th>\n<th>c</th>\n',
|
|
550
|
+
'<tr>\n<td>1</td>\n<td colspan="2">2</td>\n</tr>\n' +
|
|
551
|
+
'<tr>\n<td colspan="3">x</td>\n</tr>\n'
|
|
552
|
+
),
|
|
553
|
+
],
|
|
554
|
+
[
|
|
555
|
+
'rowspan',
|
|
556
|
+
'| a | b |\n|---|---|\n| 1 | 2 |\n|^ | 3 |\n|^ | 4 |\n',
|
|
557
|
+
table(
|
|
558
|
+
'<th>a</th>\n<th>b</th>\n',
|
|
559
|
+
'<tr>\n<td rowspan="3">1</td>\n<td>2</td>\n</tr>\n' +
|
|
560
|
+
'<tr>\n<td>3</td>\n</tr>\n<tr>\n<td>4</td>\n</tr>\n'
|
|
561
|
+
),
|
|
562
|
+
],
|
|
563
|
+
[
|
|
564
|
+
'a merged rectangle',
|
|
565
|
+
'| a | b | c |\n|---|---|---|\n| x |> | 1 |\n|^ |^ | 2 |\n',
|
|
566
|
+
table(
|
|
567
|
+
'<th>a</th>\n<th>b</th>\n<th>c</th>\n',
|
|
568
|
+
'<tr>\n<td colspan="2" rowspan="2">x</td>\n<td>1</td>\n</tr>\n' +
|
|
569
|
+
'<tr>\n<td>2</td>\n</tr>\n'
|
|
570
|
+
),
|
|
571
|
+
],
|
|
572
|
+
[
|
|
573
|
+
'cells after a merged cell keep their column alignment',
|
|
574
|
+
'| a | b | c | d |\n|:-:|---|--:|:--|\n| x |> | r | l |\n|^ |^ | s | m |\n',
|
|
575
|
+
table(
|
|
576
|
+
'<th align="center">a</th>\n<th>b</th>\n<th align="right">c</th>\n<th align="left">d</th>\n',
|
|
577
|
+
'<tr>\n<td align="center" colspan="2" rowspan="2">x</td>\n<td align="right">r</td>\n<td align="left">l</td>\n</tr>\n' +
|
|
578
|
+
'<tr>\n<td align="right">s</td>\n<td align="left">m</td>\n</tr>\n'
|
|
579
|
+
),
|
|
580
|
+
],
|
|
581
|
+
[
|
|
582
|
+
'spans next to header columns',
|
|
583
|
+
'| h || a | b |\n|---||---|---|\n| 1 || x |> |\n|^ || y | z |\n',
|
|
584
|
+
table(
|
|
585
|
+
'<th>h</th>\n<th>a</th>\n<th>b</th>\n',
|
|
586
|
+
'<tr>\n<th scope="row" rowspan="2">1</th>\n<td colspan="2">x</td>\n</tr>\n' +
|
|
587
|
+
'<tr>\n<td>y</td>\n<td>z</td>\n</tr>\n'
|
|
588
|
+
),
|
|
589
|
+
],
|
|
590
|
+
];
|
|
591
|
+
|
|
592
|
+
it.each(cases)('%s', (_, source, html) => {
|
|
593
|
+
expect(every_walk(source)).toBe(html);
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
it('markers with nothing to merge into stay text in a plain table', () => {
|
|
597
|
+
expect(every_walk('| a | b |\n|:--|--:|\n| > | ^ |\n| 1 | 2 |\n')).toBe(
|
|
598
|
+
table(
|
|
599
|
+
'<th align="left">a</th>\n<th align="right">b</th>\n',
|
|
600
|
+
'<tr>\n<td align="left">></td>\n<td align="right">^</td>\n</tr>\n' +
|
|
601
|
+
'<tr>\n<td align="left">1</td>\n<td align="right">2</td>\n</tr>\n'
|
|
602
|
+
)
|
|
603
|
+
);
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
it('replaced th and td take scope and spans as they take align', () => {
|
|
607
|
+
const scope = new ComponentScope(
|
|
608
|
+
[{ specifier: 'm', names: ['th', 'td'] }],
|
|
609
|
+
'G'
|
|
610
|
+
);
|
|
611
|
+
const html = every_walk(
|
|
612
|
+
'| h || a | b |\n|---||:-:|---|\n| 1 || x |> |\n|^ || y | z |\n',
|
|
613
|
+
scope
|
|
614
|
+
);
|
|
615
|
+
expect(html.replace(/^<script>[^]*?<\/script>/, '')).toBe(
|
|
616
|
+
table(
|
|
617
|
+
'<Th_MDSVEX_G>h</Th_MDSVEX_G>\n<Th_MDSVEX_G align="center">a</Th_MDSVEX_G>\n<Th_MDSVEX_G>b</Th_MDSVEX_G>\n',
|
|
618
|
+
'<tr>\n<Th_MDSVEX_G scope="row" rowspan="2">1</Th_MDSVEX_G>\n<Td_MDSVEX_G align="center" colspan="2">x</Td_MDSVEX_G>\n</tr>\n' +
|
|
619
|
+
'<tr>\n<Td_MDSVEX_G align="center">y</Td_MDSVEX_G>\n<Td_MDSVEX_G>z</Td_MDSVEX_G>\n</tr>\n'
|
|
620
|
+
)
|
|
621
|
+
);
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it('a row header uses a replaced th even when no header cell is replaced', () => {
|
|
625
|
+
const scope = new ComponentScope([{ specifier: 'm', names: ['th'] }], 'G');
|
|
626
|
+
const html = every_walk('| a || b |\n|---||---|\n| 1 || 2 |\n', scope);
|
|
627
|
+
expect(html).toContain("import { th as Th_MDSVEX_G } from 'm';");
|
|
628
|
+
expect(html).toContain(
|
|
629
|
+
'<Th_MDSVEX_G scope="row">1</Th_MDSVEX_G>\n<td>2</td>'
|
|
630
|
+
);
|
|
631
|
+
const only_td = new ComponentScope(
|
|
632
|
+
[{ specifier: 'm', names: ['td'] }],
|
|
633
|
+
'G'
|
|
634
|
+
);
|
|
635
|
+
const td_html = every_walk('| a || b |\n|---||---|\n| 1 || 2 |\n', only_td);
|
|
636
|
+
expect(td_html).toContain(
|
|
637
|
+
'<th scope="row">1</th>\n<Td_MDSVEX_G>2</Td_MDSVEX_G>'
|
|
638
|
+
);
|
|
639
|
+
});
|
|
640
|
+
});
|