leaflet.pub astro loader
1import { expect, test } from "vitest";
2import { parseTextBlock } from "../lib/utils";
3
4test("should correctly parse a text block without facets", () => {
5 const html = parseTextBlock({
6 $type: "pub.leaflet.blocks.text",
7 facets: [],
8 plaintext: "just plaintext no facets",
9 });
10
11 expect(html).toMatchInlineSnapshot(`"<p>just plaintext no facets</p>"`);
12});
13
14test("should correctly parse a text block with bolded text", () => {
15 const html = parseTextBlock({
16 $type: "pub.leaflet.blocks.text",
17 facets: [
18 {
19 index: {
20 byteEnd: 11,
21 byteStart: 0,
22 },
23 features: [
24 {
25 $type: "pub.leaflet.richtext.facet#bold",
26 },
27 ],
28 },
29 ],
30 plaintext: "bolded text with some plaintext",
31 });
32
33 expect(html).toMatchInlineSnapshot(
34 `"<p><b>bolded text</b> with some plaintext</p>"`,
35 );
36});
37
38test("should correctly parse a text block with an inline link", () => {
39 const html = parseTextBlock({
40 $type: "pub.leaflet.blocks.text",
41 facets: [
42 {
43 index: {
44 byteEnd: 27,
45 byteStart: 0,
46 },
47 features: [
48 {
49 uri: "https://blacksky.community/",
50 $type: "pub.leaflet.richtext.facet#link",
51 },
52 ],
53 },
54 ],
55 plaintext: "https://blacksky.community/",
56 });
57
58 expect(html).toMatchInlineSnapshot(
59 `"<p><a href="https://blacksky.community/" target="_blank" rel="noopener noreferrer">https://blacksky.community/</a></p>"`,
60 );
61});
62
63test("should correctly parse a text block with strikethrough text", () => {
64 const html = parseTextBlock({
65 $type: "pub.leaflet.blocks.text",
66 facets: [
67 {
68 index: {
69 byteEnd: 13,
70 byteStart: 0,
71 },
72 features: [
73 {
74 $type: "pub.leaflet.richtext.facet#strikethrough",
75 },
76 ],
77 },
78 ],
79 plaintext: "strikethrough text with some plaintext",
80 });
81
82 expect(html).toMatchInlineSnapshot(
83 `"<p><s>strikethrough</s> text with some plaintext</p>"`,
84 );
85});
86
87test("should correctly parse a text block with underlined text", () => {
88 const html = parseTextBlock({
89 $type: "pub.leaflet.blocks.text",
90 facets: [
91 {
92 index: {
93 byteEnd: 10,
94 byteStart: 0,
95 },
96 features: [
97 {
98 $type: "pub.leaflet.richtext.facet#underline",
99 },
100 ],
101 },
102 ],
103 plaintext: "underlined text with some plaintext",
104 });
105
106 expect(html).toMatchInlineSnapshot(
107 `"<p><span style="text-decoration:underline;">underlined</span> text with some plaintext</p>"`,
108 );
109});
110
111test("should correctly parse a text block with italicized text", () => {
112 const html = parseTextBlock({
113 $type: "pub.leaflet.blocks.text",
114 facets: [
115 {
116 index: {
117 byteEnd: 10,
118 byteStart: 0,
119 },
120 features: [
121 {
122 $type: "pub.leaflet.richtext.facet#italic",
123 },
124 ],
125 },
126 ],
127 plaintext: "italicized text with some plaintext",
128 });
129
130 expect(html).toMatchInlineSnapshot(
131 `"<p><i>italicized</i> text with some plaintext</p>"`,
132 );
133});