@uniweb/content-reader 1.0.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.
- package/.eslintrc.json +28 -0
- package/LICENSE +674 -0
- package/README.md +174 -0
- package/package.json +44 -0
- package/src/index.js +22 -0
- package/src/parser/block.js +170 -0
- package/src/parser/index.js +54 -0
- package/src/parser/inline.js +117 -0
- package/src/parser/lists.js +106 -0
- package/src/parser/patterns.js +46 -0
- package/src/parser/tables.js +75 -0
- package/src/parser/utils.js +24 -0
- package/src/schema/index.js +144 -0
- package/src/utils.js +63 -0
- package/tests/code.test.js +122 -0
- package/tests/lists.test.js +260 -0
- package/tests/parser.test.js +343 -0
- package/tests/sample.md +44 -0
- package/tests/tables.test.js +335 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { markdownToProseMirror } from "../src/index.js";
|
|
2
|
+
|
|
3
|
+
describe("Table Parsing", () => {
|
|
4
|
+
test("parses basic table", () => {
|
|
5
|
+
const markdown = `
|
|
6
|
+
| Column 1 | Column 2 |
|
|
7
|
+
|----------|----------|
|
|
8
|
+
| Cell 1 | Cell 2 |
|
|
9
|
+
| Cell 3 | Cell 4 |`;
|
|
10
|
+
|
|
11
|
+
const result = markdownToProseMirror(markdown);
|
|
12
|
+
|
|
13
|
+
expect(result).toEqual({
|
|
14
|
+
type: "doc",
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: "table",
|
|
18
|
+
content: [
|
|
19
|
+
{
|
|
20
|
+
type: "tableRow",
|
|
21
|
+
content: [
|
|
22
|
+
{
|
|
23
|
+
type: "tableCell",
|
|
24
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: true },
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: "paragraph",
|
|
28
|
+
content: [{ type: "text", text: "Column 1" }],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "tableCell",
|
|
34
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: true },
|
|
35
|
+
content: [
|
|
36
|
+
{
|
|
37
|
+
type: "paragraph",
|
|
38
|
+
content: [{ type: "text", text: "Column 2" }],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "tableRow",
|
|
46
|
+
content: [
|
|
47
|
+
{
|
|
48
|
+
type: "tableCell",
|
|
49
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: false },
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: "paragraph",
|
|
53
|
+
content: [{ type: "text", text: "Cell 1" }],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: "tableCell",
|
|
59
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: false },
|
|
60
|
+
content: [
|
|
61
|
+
{
|
|
62
|
+
type: "paragraph",
|
|
63
|
+
content: [{ type: "text", text: "Cell 2" }],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: "tableRow",
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
type: "tableCell",
|
|
74
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: false },
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: "paragraph",
|
|
78
|
+
content: [{ type: "text", text: "Cell 3" }],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: "tableCell",
|
|
84
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: false },
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: "paragraph",
|
|
88
|
+
content: [{ type: "text", text: "Cell 4" }],
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("parses table with alignments", () => {
|
|
101
|
+
const markdown = `
|
|
102
|
+
| Left | Center | Right |
|
|
103
|
+
|:-----|:------:|------:|
|
|
104
|
+
| 1 | 2 | 3 |`;
|
|
105
|
+
|
|
106
|
+
const result = markdownToProseMirror(markdown);
|
|
107
|
+
|
|
108
|
+
expect(result).toEqual({
|
|
109
|
+
type: "doc",
|
|
110
|
+
content: [
|
|
111
|
+
{
|
|
112
|
+
type: "table",
|
|
113
|
+
content: [
|
|
114
|
+
{
|
|
115
|
+
type: "tableRow",
|
|
116
|
+
content: [
|
|
117
|
+
{
|
|
118
|
+
type: "tableCell",
|
|
119
|
+
attrs: {
|
|
120
|
+
colspan: 1,
|
|
121
|
+
rowspan: 1,
|
|
122
|
+
align: "left",
|
|
123
|
+
header: true,
|
|
124
|
+
},
|
|
125
|
+
content: [
|
|
126
|
+
{
|
|
127
|
+
type: "paragraph",
|
|
128
|
+
content: [{ type: "text", text: "Left" }],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
type: "tableCell",
|
|
134
|
+
attrs: {
|
|
135
|
+
colspan: 1,
|
|
136
|
+
rowspan: 1,
|
|
137
|
+
align: "center",
|
|
138
|
+
header: true,
|
|
139
|
+
},
|
|
140
|
+
content: [
|
|
141
|
+
{
|
|
142
|
+
type: "paragraph",
|
|
143
|
+
content: [{ type: "text", text: "Center" }],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
type: "tableCell",
|
|
149
|
+
attrs: {
|
|
150
|
+
colspan: 1,
|
|
151
|
+
rowspan: 1,
|
|
152
|
+
align: "right",
|
|
153
|
+
header: true,
|
|
154
|
+
},
|
|
155
|
+
content: [
|
|
156
|
+
{
|
|
157
|
+
type: "paragraph",
|
|
158
|
+
content: [{ type: "text", text: "Right" }],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
type: "tableRow",
|
|
166
|
+
content: [
|
|
167
|
+
{
|
|
168
|
+
type: "tableCell",
|
|
169
|
+
attrs: {
|
|
170
|
+
colspan: 1,
|
|
171
|
+
rowspan: 1,
|
|
172
|
+
align: "left",
|
|
173
|
+
header: false,
|
|
174
|
+
},
|
|
175
|
+
content: [
|
|
176
|
+
{
|
|
177
|
+
type: "paragraph",
|
|
178
|
+
content: [{ type: "text", text: "1" }],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
type: "tableCell",
|
|
184
|
+
attrs: {
|
|
185
|
+
colspan: 1,
|
|
186
|
+
rowspan: 1,
|
|
187
|
+
align: "center",
|
|
188
|
+
header: false,
|
|
189
|
+
},
|
|
190
|
+
content: [
|
|
191
|
+
{
|
|
192
|
+
type: "paragraph",
|
|
193
|
+
content: [{ type: "text", text: "2" }],
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
type: "tableCell",
|
|
199
|
+
attrs: {
|
|
200
|
+
colspan: 1,
|
|
201
|
+
rowspan: 1,
|
|
202
|
+
align: "right",
|
|
203
|
+
header: false,
|
|
204
|
+
},
|
|
205
|
+
content: [
|
|
206
|
+
{
|
|
207
|
+
type: "paragraph",
|
|
208
|
+
content: [{ type: "text", text: "3" }],
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("parses table with formatted content", () => {
|
|
221
|
+
const markdown = `
|
|
222
|
+
| Style | Example |
|
|
223
|
+
|-------|---------|
|
|
224
|
+
| Bold | **text** |
|
|
225
|
+
| Link | [link](https://example.com) |`;
|
|
226
|
+
|
|
227
|
+
const result = markdownToProseMirror(markdown);
|
|
228
|
+
|
|
229
|
+
expect(result).toEqual({
|
|
230
|
+
type: "doc",
|
|
231
|
+
content: [
|
|
232
|
+
{
|
|
233
|
+
type: "table",
|
|
234
|
+
content: [
|
|
235
|
+
{
|
|
236
|
+
type: "tableRow",
|
|
237
|
+
content: [
|
|
238
|
+
{
|
|
239
|
+
type: "tableCell",
|
|
240
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: true },
|
|
241
|
+
content: [
|
|
242
|
+
{
|
|
243
|
+
type: "paragraph",
|
|
244
|
+
content: [{ type: "text", text: "Style" }],
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: "tableCell",
|
|
250
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: true },
|
|
251
|
+
content: [
|
|
252
|
+
{
|
|
253
|
+
type: "paragraph",
|
|
254
|
+
content: [{ type: "text", text: "Example" }],
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
type: "tableRow",
|
|
262
|
+
content: [
|
|
263
|
+
{
|
|
264
|
+
type: "tableCell",
|
|
265
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: false },
|
|
266
|
+
content: [
|
|
267
|
+
{
|
|
268
|
+
type: "paragraph",
|
|
269
|
+
content: [{ type: "text", text: "Bold" }],
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
type: "tableCell",
|
|
275
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: false },
|
|
276
|
+
content: [
|
|
277
|
+
{
|
|
278
|
+
type: "paragraph",
|
|
279
|
+
content: [
|
|
280
|
+
{
|
|
281
|
+
type: "text",
|
|
282
|
+
marks: [{ type: "bold" }],
|
|
283
|
+
text: "text",
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
type: "tableRow",
|
|
293
|
+
content: [
|
|
294
|
+
{
|
|
295
|
+
type: "tableCell",
|
|
296
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: false },
|
|
297
|
+
content: [
|
|
298
|
+
{
|
|
299
|
+
type: "paragraph",
|
|
300
|
+
content: [{ type: "text", text: "Link" }],
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
type: "tableCell",
|
|
306
|
+
attrs: { colspan: 1, rowspan: 1, align: null, header: false },
|
|
307
|
+
content: [
|
|
308
|
+
{
|
|
309
|
+
type: "paragraph",
|
|
310
|
+
content: [
|
|
311
|
+
{
|
|
312
|
+
type: "text",
|
|
313
|
+
marks: [
|
|
314
|
+
{
|
|
315
|
+
type: "link",
|
|
316
|
+
attrs: {
|
|
317
|
+
href: "https://example.com",
|
|
318
|
+
title: null,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
text: "link",
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
});
|