Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

nativeMarkdownText.test.ts

965 lines25.9 KB

1import { describe, expect, it } from "vite-plus/test";
2import type { MarkdownNode } from "react-native-nitro-markdown/headless";
3​
4import {
5 nativeMarkdownChunkSpacing,
6 nativeMarkdownDocumentChunks,
7 nativeMarkdownDocumentRuns,
8 nativeMarkdownListItemBlocks,
9 nativeMarkdownTextRuns,
10 nativeMarkdownWithPreservedSoftBreaks,
11} from "@t3tools/mobile-markdown-text/markdown";
12​
13describe("nativeMarkdownTextRuns", () => {
14 it("links a path-shaped code span without changing the same path in prose", () => {
15 expect(
16 nativeMarkdownTextRuns({
17 type: "paragraph",
18 children: [
19 { type: "text", content: "/tmp/frame.png " },
20 { type: "code_inline", content: "/tmp/frame.png" },
21 ],
22 }),
23 ).toEqual([
24 { text: "/tmp/frame.png " },
25 { text: "frame.png", href: "/tmp/frame.png", fileIcon: "image" },
26 ]);
27 });
28​
29 it("preserves the destination of a link with a code-formatted label", () => {
30 expect(
31 nativeMarkdownTextRuns({
32 type: "paragraph",
33 children: [
34 {
35 type: "link",
36 href: "https://example.com/docs",
37 children: [{ type: "code_inline", content: "src/main.ts" }],
38 },
39 ],
40 }),
41 ).toEqual([
42 {
43 text: "src/main.ts",
44 code: true,
45 href: "https://example.com/docs",
46 externalHost: "example.com",
47 },
48 ]);
49 });
50​
51 it("preserves inline emphasis and code styles", () => {
52 const node: MarkdownNode = {
53 type: "paragraph",
54 children: [
55 { type: "text", content: "plain " },
56 { type: "bold", children: [{ type: "text", content: "bold" }] },
57 { type: "text", content: " " },
58 { type: "code_inline", content: "const value = 1" },
59 ],
60 };
61​
62 expect(nativeMarkdownTextRuns(node)).toEqual([
63 { text: "plain " },
64 { text: "bold", bold: true },
65 { text: " " },
66 { text: "const value = 1", code: true },
67 ]);
68 });
69​
70 it("normalizes external and file links for native presentation", () => {
71 const node: MarkdownNode = {
72 type: "paragraph",
73 children: [
74 {
75 type: "link",
76 href: "https://example.com/docs",
77 children: [{ type: "text", content: "Docs" }],
78 },
79 { type: "text", content: " " },
80 {
81 type: "link",
82 href: "file:///repo/README.md#L12",
83 children: [{ type: "text", content: "ignored label" }],
84 },
85 ],
86 };
87​
88 expect(nativeMarkdownTextRuns(node)).toEqual([
89 {
90 text: "Docs",
91 href: "https://example.com/docs",
92 externalHost: "example.com",
93 },
94 { text: " " },
95 {
96 text: "README.md:12",
97 href: "file:///repo/README.md#L12",
98 fileIcon: "readme",
99 },
100 ]);
101 });
102​
103 it("keeps hard breaks and collapses soft breaks", () => {
104 const node: MarkdownNode = {
105 type: "paragraph",
106 children: [
107 { type: "text", content: "first" },
108 { type: "soft_break" },
109 { type: "text", content: "second" },
110 { type: "line_break" },
111 { type: "text", content: "third" },
112 ],
113 };
114​
115 expect(nativeMarkdownTextRuns(node)).toEqual([{ text: "first second\nthird" }]);
116 });
117​
118 it("can preserve soft breaks for authored user messages", () => {
119 const node: MarkdownNode = {
120 type: "paragraph",
121 children: [
122 { type: "text", content: "first" },
123 { type: "soft_break" },
124 { type: "text", content: "second" },
125 ],
126 };
127​
128 expect(nativeMarkdownTextRuns(nativeMarkdownWithPreservedSoftBreaks(node))).toEqual([
129 { text: "first\nsecond" },
130 ]);
131 });
132​
133 it("normalizes common inline HTML and entities", () => {
134 const node: MarkdownNode = {
135 type: "paragraph",
136 children: [
137 { type: "text", content: "Less than: < " },
138 { type: "html_inline", content: "<kbd>" },
139 { type: "text", content: "⌘" },
140 { type: "html_inline", content: "</kbd>" },
141 { type: "html_inline", content: "<br />" },
142 { type: "html_inline", content: "<mark>highlighted</mark>" },
143 ],
144 };
145​
146 expect(nativeMarkdownTextRuns(node)).toEqual([{ text: "Less than: < ⌘\nhighlighted" }]);
147 });
148​
149 it("normalizes double-encoded entities and inline tags emitted as text", () => {
150 const node: MarkdownNode = {
151 type: "paragraph",
152 children: [
153 {
154 type: "text",
155 content:
156 "Keyboard: <kbd>⌘</kbd> + <kbd>K</kbd>; Less than: &amp;lt;; Greater than: &amp;gt;",
157 },
158 ],
159 };
160​
161 expect(nativeMarkdownTextRuns(node)).toEqual([
162 { text: "Keyboard: ⌘ + K; Less than: <; Greater than: >" },
163 ]);
164 });
165​
166 it.each([
167 ["&#128512;", "😀"],
168 ["&#x1f680;", "🚀"],
169 ["&#9999999999;", "&#9999999999;"],
170 ["&#x110000;", "&#x110000;"],
171 ["&amp;#9999999999;", "&#9999999999;"],
172 ["&amp;#x110000;", "&#x110000;"],
173 ])("normalizes numeric entity %s without throwing", (content, expected) => {
174 const node: MarkdownNode = {
175 type: "paragraph",
176 children: [{ type: "text", content }],
177 };
178​
179 expect(nativeMarkdownTextRuns(node)).toEqual([{ text: expected }]);
180 });
181​
182 it("reads inline content from nested text nodes", () => {
183 const node: MarkdownNode = {
184 type: "paragraph",
185 children: [
186 {
187 type: "text",
188 children: [{ type: "text", content: "Plain text" }],
189 },
190 { type: "text", content: " and " },
191 {
192 type: "code_inline",
193 children: [{ type: "text", content: "inline code" }],
194 },
195 ],
196 };
197​
198 expect(nativeMarkdownTextRuns(node)).toEqual([
199 { text: "Plain text and " },
200 { text: "inline code", code: true },
201 ]);
202 });
203});
204​
205describe("nativeMarkdownDocumentRuns", () => {
206 it("decorates known skill references as selectable skill links", () => {
207 const node: MarkdownNode = {
208 type: "document",
209 children: [
210 {
211 type: "paragraph",
212 children: [{ type: "text", content: "Use $ui for this." }],
213 },
214 ],
215 };
216​
217 expect(nativeMarkdownDocumentRuns(node, [{ name: "ui", displayName: "UI" }])).toEqual([
218 { text: "Use ", role: "body" },
219 {
220 text: "$ui",
221 role: "body",
222 skillName: "ui",
223 skillLabel: "UI",
224 },
225 { text: " for this.", role: "body" },
226 ]);
227 });
228​
229 it("decorates known skill references that begin with a digit", () => {
230 const node: MarkdownNode = {
231 type: "document",
232 children: [
233 {
234 type: "paragraph",
235 children: [{ type: "text", content: "Use $2spec for this." }],
236 },
237 ],
238 };
239​
240 expect(nativeMarkdownDocumentRuns(node, [{ name: "2spec", displayName: "2Spec" }])).toEqual([
241 { text: "Use ", role: "body" },
242 {
243 text: "$2spec",
244 role: "body",
245 skillName: "2spec",
246 skillLabel: "2Spec",
247 },
248 { text: " for this.", role: "body" },
249 ]);
250 });
251​
252 it("decorates known skill references inside blockquotes", () => {
253 const node: MarkdownNode = {
254 type: "blockquote",
255 children: [
256 {
257 type: "paragraph",
258 children: [{ type: "text", content: "Use $ui for this." }],
259 },
260 ],
261 };
262​
263 expect(nativeMarkdownDocumentRuns(node, [{ name: "ui", displayName: "UI" }])).toContainEqual({
264 text: "$ui",
265 role: "body",
266 skillName: "ui",
267 skillLabel: "UI",
268 });
269 });
270​
271 it("leaves unknown skill-like text unchanged", () => {
272 const node: MarkdownNode = {
273 type: "document",
274 children: [
275 {
276 type: "paragraph",
277 children: [{ type: "text", content: "Use $unknown for this." }],
278 },
279 ],
280 };
281​
282 expect(nativeMarkdownDocumentRuns(node, [])).toEqual([
283 { text: "Use $unknown for this.", role: "body" },
284 ]);
285 });
286​
287 it("keeps headings, paragraphs, and lists in one continuous document", () => {
288 const node: MarkdownNode = {
289 type: "document",
290 children: [
291 {
292 type: "heading",
293 level: 1,
294 children: [{ type: "text", content: "Header One" }],
295 },
296 {
297 type: "paragraph",
298 children: [
299 { type: "text", content: "A paragraph with " },
300 { type: "bold", children: [{ type: "text", content: "bold text" }] },
301 { type: "text", content: "." },
302 ],
303 },
304 {
305 type: "list",
306 ordered: false,
307 children: [
308 {
309 type: "list_item",
310 children: [
311 {
312 type: "paragraph",
313 children: [{ type: "text", content: "First item" }],
314 },
315 ],
316 },
317 {
318 type: "list_item",
319 children: [
320 {
321 type: "paragraph",
322 children: [{ type: "text", content: "Second item" }],
323 },
324 ],
325 },
326 ],
327 },
328 ],
329 };
330​
331 const runs = nativeMarkdownDocumentRuns(node);
332 expect(runs.map((run) => run.text).join("")).toBe(
333 "Header One\n\nA paragraph with bold text.\n\n•\tFirst item\n•\tSecond item",
334 );
335 expect(runs).toContainEqual({
336 text: "Header One\n",
337 role: "heading",
338 headingLevel: 1,
339 });
340 expect(runs).toContainEqual({
341 text: "bold text",
342 bold: true,
343 role: "body",
344 });
345 expect(runs).toContainEqual({
346 text: "•\t",
347 role: "list-marker",
348 depth: 1,
349 firstLineHeadIndent: 0,
350 headIndent: 24,
351 paragraphSpacing: 2,
352 });
353 });
354​
355 it("uses distinct section, heading-content, and body spacing", () => {
356 const node: MarkdownNode = {
357 type: "document",
358 children: [
359 {
360 type: "paragraph",
361 children: [{ type: "text", content: "Intro" }],
362 },
363 {
364 type: "heading",
365 level: 2,
366 children: [{ type: "text", content: "Section" }],
367 },
368 {
369 type: "paragraph",
370 children: [{ type: "text", content: "First paragraph" }],
371 },
372 {
373 type: "paragraph",
374 children: [{ type: "text", content: "Second paragraph" }],
375 },
376 ],
377 };
378​
379 expect(
380 nativeMarkdownDocumentRuns(node)
381 .filter((run) => run.role === "spacer")
382 .map((run) => run.spacing),
383 ).toEqual([20, 10, 12]);
384 });
385​
386 it("renders tight list items whose inline nodes are direct children", () => {
387 const node: MarkdownNode = {
388 type: "document",
389 children: [
390 {
391 type: "list",
392 children: [
393 {
394 type: "list_item",
395 children: [
396 {
397 type: "bold",
398 children: [{ type: "text", content: "Finding:" }],
399 },
400 { type: "text", content: " details with " },
401 { type: "code_inline", content: "inline code" },
402 { type: "text", content: "." },
403 ],
404 },
405 ],
406 },
407 ],
408 };
409​
410 expect(nativeMarkdownDocumentRuns(node)).toEqual([
411 {
412 text: "•\t",
413 role: "list-marker",
414 depth: 1,
415 firstLineHeadIndent: 0,
416 headIndent: 24,
417 paragraphSpacing: 2,
418 },
419 { text: "Finding:", bold: true, role: "body", depth: 1 },
420 { text: " details with ", role: "body", depth: 1 },
421 { text: "inline code", code: true, role: "body", depth: 1 },
422 { text: ".", role: "body", depth: 1 },
423 ]);
424 });
425​
426 it("preserves quotes and fenced code in document runs", () => {
427 const node: MarkdownNode = {
428 type: "document",
429 children: [
430 {
431 type: "blockquote",
432 children: [
433 {
434 type: "paragraph",
435 children: [{ type: "text", content: "Read this" }],
436 },
437 ],
438 },
439 {
440 type: "code_block",
441 language: "ts",
442 content: "const answer = 42;",
443 },
444 ],
445 };
446​
447 const runs = nativeMarkdownDocumentRuns(node);
448 expect(runs.map((run) => run.text).join("")).toBe("│\u00a0Read this\n\nTS\nconst answer = 42;");
449 expect(runs).toContainEqual({
450 text: "const answer = 42;",
451 code: true,
452 role: "code-block",
453 });
454 });
455​
456 it("reads fenced code content from child text nodes", () => {
457 const node: MarkdownNode = {
458 type: "document",
459 children: [
460 {
461 type: "code_block",
462 language: "bash",
463 children: [{ type: "text", content: "pnpm install\n" }],
464 },
465 ],
466 };
467​
468 expect(
469 nativeMarkdownDocumentRuns(node)
470 .map((run) => run.text)
471 .join(""),
472 ).toBe("BASH\npnpm install");
473 });
474});
475​
476describe("nativeMarkdownListItemBlocks", () => {
477 it("groups consecutive inline nodes into one paragraph block", () => {
478 const item: MarkdownNode = {
479 type: "list_item",
480 children: [
481 { type: "text", content: "Finding: " },
482 { type: "bold", children: [{ type: "text", content: "important" }] },
483 { type: "text", content: " details." },
484 {
485 type: "list",
486 children: [
487 {
488 type: "list_item",
489 children: [{ type: "text", content: "Nested" }],
490 },
491 ],
492 },
493 { type: "text", content: "Trailing prose." },
494 ],
495 };
496​
497 expect(nativeMarkdownListItemBlocks(item)).toEqual([
498 {
499 type: "paragraph",
500 children: item.children?.slice(0, 3),
501 },
502 item.children?.[3],
503 {
504 type: "paragraph",
505 children: [item.children?.[4]],
506 },
507 ]);
508 });
509});
510​
511describe("nativeMarkdownDocumentChunks", () => {
512 it("renders plain blockquotes as rich blocks so their marker spans wrapped lines", () => {
513 const blockquote: MarkdownNode = {
514 type: "blockquote",
515 beg: 0,
516 end: 120,
517 children: [
518 {
519 type: "paragraph",
520 children: [
521 {
522 type: "text",
523 content:
524 "Persistent random per-result keys are the strongest design, even when this text wraps.",
525 },
526 ],
527 },
528 ],
529 };
530​
531 expect(
532 nativeMarkdownDocumentChunks({
533 type: "document",
534 children: [blockquote],
535 }),
536 ).toEqual([
537 {
538 kind: "rich",
539 key: "rich:blockquote:offset:0",
540 node: blockquote,
541 },
542 ]);
543 });
544​
545 it("keeps headings and plain lists in one selectable document", () => {
546 const document: MarkdownNode = {
547 type: "document",
548 children: [
549 {
550 type: "heading",
551 level: 2,
552 children: [{ type: "text", content: "Tasks" }],
553 },
554 {
555 type: "list",
556 children: [
557 {
558 type: "task_list_item",
559 checked: true,
560 children: [
561 {
562 type: "paragraph",
563 children: [{ type: "text", content: "Completed" }],
564 },
565 ],
566 },
567 {
568 type: "list_item",
569 children: [
570 {
571 type: "paragraph",
572 children: [{ type: "text", content: "Parent" }],
573 },
574 {
575 type: "list",
576 children: [
577 {
578 type: "list_item",
579 children: [
580 {
581 type: "paragraph",
582 children: [{ type: "text", content: "Nested" }],
583 },
584 ],
585 },
586 ],
587 },
588 ],
589 },
590 ],
591 },
592 ],
593 };
594​
595 const chunks = nativeMarkdownDocumentChunks(document);
596 expect(chunks).toHaveLength(1);
597 expect(chunks[0]).toMatchObject({ kind: "selectable" });
598 expect(
599 nativeMarkdownDocumentRuns(chunks[0]?.node ?? document)
600 .map((run) => run.text)
601 .join(""),
602 ).toBe("Tasks\n\n☑︎\tCompleted\n•\tParent\n◦\tNested");
603 });
604​
605 it("aligns ordered markers while keeping the list in one selectable string", () => {
606 const document: MarkdownNode = {
607 type: "document",
608 children: [
609 {
610 type: "list",
611 ordered: true,
612 start: 9,
613 children: [
614 {
615 type: "list_item",
616 children: [{ type: "text", content: "Ninth" }],
617 },
618 {
619 type: "list_item",
620 children: [{ type: "text", content: "Tenth" }],
621 },
622 ],
623 },
624 ],
625 };
626​
627 expect(
628 nativeMarkdownDocumentRuns(document)
629 .map((run) => run.text)
630 .join(""),
631 ).toBe("\u20079.\tNinth\n10.\tTenth");
632 });
633​
634 it("keeps prose selectable while exposing rich AST blocks", () => {
635 const document: MarkdownNode = {
636 type: "document",
637 children: [
638 {
639 type: "heading",
640 level: 1,
641 beg: 0,
642 end: 9,
643 children: [{ type: "text", content: "Install" }],
644 },
645 {
646 type: "code_block",
647 language: "bash",
648 beg: 11,
649 end: 35,
650 children: [{ type: "text", content: "pnpm install\n" }],
651 },
652 {
653 type: "paragraph",
654 beg: 37,
655 end: 42,
656 children: [{ type: "text", content: "Done." }],
657 },
658 ],
659 };
660​
661 const chunks = nativeMarkdownDocumentChunks(document);
662 expect(chunks).toHaveLength(3);
663 expect(chunks[0]).toMatchObject({ kind: "selectable" });
664 expect(chunks[1]).toEqual({
665 kind: "rich",
666 key: "rich:code_block:offset:11",
667 node: document.children?.[1],
668 });
669 expect(chunks[2]).toMatchObject({ kind: "selectable" });
670 });
671​
672 it("keeps a list containing fenced code as one rich AST container", () => {
673 const document: MarkdownNode = {
674 type: "document",
675 children: [
676 {
677 type: "list",
678 beg: 0,
679 end: 45,
680 children: [
681 {
682 type: "list_item",
683 children: [
684 {
685 type: "paragraph",
686 children: [{ type: "text", content: "Install" }],
687 },
688 {
689 type: "code_block",
690 language: "bash",
691 children: [{ type: "text", content: "pnpm install\n" }],
692 },
693 ],
694 },
695 ],
696 },
697 ],
698 };
699​
700 expect(nativeMarkdownDocumentChunks(document)).toEqual([
701 {
702 kind: "rich",
703 key: "rich:list:offset:0",
704 node: document.children?.[0],
705 },
706 ]);
707 });
708​
709 it("keeps surrounding prose selectable when rich nodes have no source offsets", () => {
710 const document: MarkdownNode = {
711 type: "document",
712 children: [
713 {
714 type: "heading",
715 level: 1,
716 children: [{ type: "text", content: "Before" }],
717 },
718 { type: "horizontal_rule" },
719 {
720 type: "paragraph",
721 children: [{ type: "text", content: "After." }],
722 },
723 ],
724 };
725​
726 const chunks = nativeMarkdownDocumentChunks(document);
727 expect(chunks).toHaveLength(3);
728 expect(chunks[0]).toMatchObject({ kind: "selectable" });
729 expect(chunks[1]).toEqual({
730 kind: "rich",
731 key: "rich:horizontal_rule:index:1",
732 node: document.children?.[1],
733 });
734 expect(chunks[2]).toMatchObject({ kind: "selectable" });
735 });
736​
737 it("keeps offset-free structural lists isolated without promoting the whole document", () => {
738 const document: MarkdownNode = {
739 type: "document",
740 children: [
741 {
742 type: "paragraph",
743 children: [{ type: "text", content: "Before." }],
744 },
745 {
746 type: "list",
747 ordered: true,
748 children: [
749 {
750 type: "list_item",
751 children: [
752 {
753 type: "paragraph",
754 children: [{ type: "text", content: "Install" }],
755 },
756 {
757 type: "code_block",
758 language: "bash",
759 children: [{ type: "text", content: "pnpm install\n" }],
760 },
761 ],
762 },
763 ],
764 },
765 {
766 type: "paragraph",
767 children: [{ type: "text", content: "After." }],
768 },
769 ],
770 };
771​
772 const chunks = nativeMarkdownDocumentChunks(document);
773 expect(chunks).toHaveLength(3);
774 expect(chunks[0]).toMatchObject({ kind: "selectable" });
775 expect(chunks[1]).toEqual({
776 kind: "rich",
777 key: "rich:list:index:1",
778 node: document.children?.[1],
779 });
780 expect(chunks[2]).toMatchObject({ kind: "selectable" });
781 });
782​
783 it("never collapses a rich subtree into a second markdown parsing pass", () => {
784 const document: MarkdownNode = {
785 type: "document",
786 children: [
787 {
788 type: "paragraph",
789 children: [{ type: "text", content: "Before." }],
790 },
791 {
792 type: "blockquote",
793 children: [
794 {
795 type: "list",
796 children: [
797 {
798 type: "list_item",
799 children: [
800 { type: "text", content: "Run this" },
801 {
802 type: "code_block",
803 language: "sh",
804 children: [{ type: "text", content: "vp check\n" }],
805 },
806 ],
807 },
808 ],
809 },
810 ],
811 },
812 {
813 type: "paragraph",
814 children: [{ type: "text", content: "After." }],
815 },
816 ],
817 };
818​
819 const chunks = nativeMarkdownDocumentChunks(document);
820 expect(chunks.map((chunk) => chunk.kind)).toEqual(["selectable", "rich", "selectable"]);
821 expect(chunks[1]).toMatchObject({
822 kind: "rich",
823 node: { type: "blockquote" },
824 });
825 });
826​
827 it("keys positioned and offset-free siblings in separate namespaces", () => {
828 const positioned: MarkdownNode = {
829 type: "blockquote",
830 beg: 1,
831 end: 10,
832 children: [{ type: "paragraph", children: [{ type: "text", content: "Positioned" }] }],
833 };
834 const offsetFree: MarkdownNode = {
835 type: "blockquote",
836 children: [{ type: "paragraph", children: [{ type: "text", content: "Generated" }] }],
837 };
838 const chunks = nativeMarkdownDocumentChunks({
839 type: "document",
840 children: [
841 { type: "paragraph", beg: 0, end: 0, children: [] },
842 offsetFree,
843 positioned,
844 { type: "paragraph", children: [{ type: "text", content: "Tail" }] },
845 ],
846 });
847​
848 expect(chunks.map((chunk) => chunk.key)).toEqual([
849 "selectable:offset:0",
850 "rich:blockquote:index:1",
851 "rich:blockquote:offset:1",
852 "selectable:index:3",
853 ]);
854 });
855​
856 it("gives every offset-free selectable group its own key", () => {
857 const chunks = nativeMarkdownDocumentChunks({
858 type: "document",
859 children: [
860 { type: "paragraph", children: [{ type: "text", content: "One" }] },
861 { type: "horizontal_rule" },
862 { type: "paragraph", children: [{ type: "text", content: "Two" }] },
863 { type: "horizontal_rule" },
864 { type: "paragraph", children: [{ type: "text", content: "Three" }] },
865 ],
866 });
867​
868 expect(chunks.map((chunk) => chunk.key)).toEqual([
869 "selectable:index:0",
870 "rich:horizontal_rule:index:1",
871 "selectable:index:2",
872 "rich:horizontal_rule:index:3",
873 "selectable:index:4",
874 ]);
875 });
876​
877 it("keeps positioned chunk keys stable while text streams in", () => {
878 const before: MarkdownNode = {
879 type: "document",
880 children: [
881 { type: "paragraph", beg: 0, end: 5, children: [{ type: "text", content: "Intro" }] },
882 {
883 type: "code_block",
884 language: "ts",
885 beg: 7,
886 end: 20,
887 children: [{ type: "text", content: "const a" }],
888 },
889 ],
890 };
891 const after: MarkdownNode = {
892 type: "document",
893 children: [
894 { type: "paragraph", beg: 0, end: 5, children: [{ type: "text", content: "Intro" }] },
895 {
896 type: "code_block",
897 language: "ts",
898 beg: 7,
899 end: 40,
900 children: [{ type: "text", content: "const a = 1;\nconst b" }],
901 },
902 ],
903 };
904​
905 expect(nativeMarkdownDocumentChunks(after).map((chunk) => chunk.key)).toEqual(
906 nativeMarkdownDocumentChunks(before).map((chunk) => chunk.key),
907 );
908 });
909​
910 it("keeps a plain list in one selectable native text container", () => {
911 const list: MarkdownNode = {
912 type: "list",
913 ordered: false,
914 children: [
915 {
916 type: "list_item",
917 children: [{ type: "text", content: "First" }],
918 },
919 ],
920 };
921​
922 const chunks = nativeMarkdownDocumentChunks({
923 type: "document",
924 children: [list],
925 });
926​
927 expect(chunks).toHaveLength(1);
928 expect(chunks[0]).toMatchObject({
929 kind: "selectable",
930 node: { type: "document", children: [list] },
931 });
932 });
933​
934 it("separates sections more than related rich blocks", () => {
935 const headingChunk = {
936 kind: "selectable" as const,
937 key: "heading",
938 node: {
939 type: "document",
940 children: [
941 {
942 type: "heading",
943 level: 2,
944 children: [{ type: "text", content: "Section" }],
945 },
946 ],
947 } satisfies MarkdownNode,
948 };
949 const firstList = {
950 kind: "rich" as const,
951 key: "list-1",
952 node: { type: "list", children: [] } satisfies MarkdownNode,
953 };
954 const secondList = {
955 kind: "rich" as const,
956 key: "list-2",
957 node: { type: "list", children: [] } satisfies MarkdownNode,
958 };
959​
960 expect(nativeMarkdownChunkSpacing(undefined, headingChunk)).toBe(0);
961 expect(nativeMarkdownChunkSpacing(headingChunk, firstList)).toBe(10);
962 expect(nativeMarkdownChunkSpacing(firstList, secondList)).toBe(12);
963 expect(nativeMarkdownChunkSpacing(firstList, headingChunk)).toBe(20);
964 });
965});