document-ir 0.0.6
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/LICENSE +21 -0
- package/README.md +15 -0
- package/esm/ArrayCollapseTransformer.d.ts +5 -0
- package/esm/ArrayCollapseTransformer.js +18 -0
- package/esm/ArrayCollapseTransformer_test.d.ts +1 -0
- package/esm/ExampleDocument.d.ts +2 -0
- package/esm/IdentityTransformer.d.ts +53 -0
- package/esm/IdentityTransformer.js +688 -0
- package/esm/IdentityTransformer_test.d.ts +1 -0
- package/esm/NodeVisitor.d.ts +53 -0
- package/esm/NodeVisitor.js +369 -0
- package/esm/TextCollapseTransformer.d.ts +5 -0
- package/esm/TextCollapseTransformer.js +36 -0
- package/esm/TextCollapseTransformer_test.d.ts +1 -0
- package/esm/TextVisitor.d.ts +12 -0
- package/esm/TextVisitor.js +36 -0
- package/esm/TextVisitor_test.d.ts +1 -0
- package/esm/WhitespaceStretchingTransformer.d.ts +26 -0
- package/esm/WhitespaceStretchingTransformer.js +119 -0
- package/esm/WhitespaceStretchingTransformer_test.d.ts +1 -0
- package/esm/WhitespaceTransformer.d.ts +12 -0
- package/esm/WhitespaceTransformer.js +75 -0
- package/esm/WhitespaceTransformer_test.d.ts +1 -0
- package/esm/_dnt.test_shims.d.ts +5 -0
- package/esm/deps/deno.land/std@0.192.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.192.0/testing/_diff.d.ts +26 -0
- package/esm/deps/deno.land/std@0.192.0/testing/_format.d.ts +1 -0
- package/esm/deps/deno.land/std@0.192.0/testing/asserts.d.ts +284 -0
- package/esm/index.d.ts +8 -0
- package/esm/index.js +8 -0
- package/esm/package.json +3 -0
- package/esm/types.d.ts +307 -0
- package/esm/types.js +1 -0
- package/package.json +29 -0
- package/script/ArrayCollapseTransformer.d.ts +5 -0
- package/script/ArrayCollapseTransformer.js +22 -0
- package/script/ArrayCollapseTransformer_test.d.ts +1 -0
- package/script/ExampleDocument.d.ts +2 -0
- package/script/IdentityTransformer.d.ts +53 -0
- package/script/IdentityTransformer.js +692 -0
- package/script/IdentityTransformer_test.d.ts +1 -0
- package/script/NodeVisitor.d.ts +53 -0
- package/script/NodeVisitor.js +373 -0
- package/script/TextCollapseTransformer.d.ts +5 -0
- package/script/TextCollapseTransformer.js +40 -0
- package/script/TextCollapseTransformer_test.d.ts +1 -0
- package/script/TextVisitor.d.ts +12 -0
- package/script/TextVisitor.js +40 -0
- package/script/TextVisitor_test.d.ts +1 -0
- package/script/WhitespaceStretchingTransformer.d.ts +26 -0
- package/script/WhitespaceStretchingTransformer.js +123 -0
- package/script/WhitespaceStretchingTransformer_test.d.ts +1 -0
- package/script/WhitespaceTransformer.d.ts +12 -0
- package/script/WhitespaceTransformer.js +79 -0
- package/script/WhitespaceTransformer_test.d.ts +1 -0
- package/script/_dnt.test_shims.d.ts +5 -0
- package/script/deps/deno.land/std@0.192.0/fmt/colors.d.ts +270 -0
- package/script/deps/deno.land/std@0.192.0/testing/_diff.d.ts +26 -0
- package/script/deps/deno.land/std@0.192.0/testing/_format.d.ts +1 -0
- package/script/deps/deno.land/std@0.192.0/testing/asserts.d.ts +284 -0
- package/script/index.d.ts +8 -0
- package/script/index.js +32 -0
- package/script/package.json +3 -0
- package/script/types.d.ts +307 -0
- package/script/types.js +2 -0
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
export class IdentityTransformer {
|
|
2
|
+
async beforeBlock() {
|
|
3
|
+
}
|
|
4
|
+
async afterBlock() {
|
|
5
|
+
}
|
|
6
|
+
async beforeInline() {
|
|
7
|
+
}
|
|
8
|
+
async afterInline() {
|
|
9
|
+
}
|
|
10
|
+
async chooseChildren(nodes) {
|
|
11
|
+
const children = [];
|
|
12
|
+
for (const child of nodes) {
|
|
13
|
+
const resultNode = await this.choose(child);
|
|
14
|
+
if (resultNode) {
|
|
15
|
+
children.push(resultNode);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return children;
|
|
19
|
+
}
|
|
20
|
+
async block(node) {
|
|
21
|
+
await this.beforeBlock();
|
|
22
|
+
const content = await this.chooseChildren(node.content);
|
|
23
|
+
await this.afterBlock();
|
|
24
|
+
return {
|
|
25
|
+
type: "block",
|
|
26
|
+
content,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async blockQuote(node) {
|
|
30
|
+
await this.beforeBlock();
|
|
31
|
+
const content = await this.chooseChildren(node.content);
|
|
32
|
+
await this.afterBlock();
|
|
33
|
+
return {
|
|
34
|
+
type: "block-quote",
|
|
35
|
+
content,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async bold(node) {
|
|
39
|
+
await this.beforeInline();
|
|
40
|
+
const content = await this.chooseChildren(node.content);
|
|
41
|
+
await this.afterInline();
|
|
42
|
+
return {
|
|
43
|
+
type: "bold",
|
|
44
|
+
content,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async break_(_node) {
|
|
48
|
+
await this.beforeBlock();
|
|
49
|
+
await this.afterBlock();
|
|
50
|
+
return {
|
|
51
|
+
type: "break",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async bubble(node) {
|
|
55
|
+
await this.beforeBlock();
|
|
56
|
+
const content = await this.chooseChildren(node.content);
|
|
57
|
+
await this.afterBlock();
|
|
58
|
+
return {
|
|
59
|
+
type: "bubble",
|
|
60
|
+
orientation: node.orientation || "left",
|
|
61
|
+
content,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
async center(node) {
|
|
65
|
+
await this.beforeBlock();
|
|
66
|
+
const content = await this.chooseChildren(node.content);
|
|
67
|
+
await this.afterBlock();
|
|
68
|
+
return {
|
|
69
|
+
type: "center",
|
|
70
|
+
content,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async code(node) {
|
|
74
|
+
await this.beforeInline();
|
|
75
|
+
const content = await this.chooseChildren(node.content);
|
|
76
|
+
await this.afterInline();
|
|
77
|
+
return {
|
|
78
|
+
type: "code",
|
|
79
|
+
content,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async columns(node) {
|
|
83
|
+
const columns = [];
|
|
84
|
+
for (const column of node.columns) {
|
|
85
|
+
await this.beforeBlock();
|
|
86
|
+
columns.push(await this.chooseChildren(column));
|
|
87
|
+
await this.afterBlock();
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type: "columns",
|
|
91
|
+
columns,
|
|
92
|
+
"column-count": node["column-count"],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async definition(node) {
|
|
96
|
+
await this.beforeBlock();
|
|
97
|
+
const abbreviation = await this.chooseChildren(node.abbreviation);
|
|
98
|
+
await this.afterBlock();
|
|
99
|
+
await this.beforeBlock();
|
|
100
|
+
const title = await this.chooseChildren(node.title);
|
|
101
|
+
await this.afterBlock();
|
|
102
|
+
await this.beforeBlock();
|
|
103
|
+
const content = await this.chooseChildren(node.content);
|
|
104
|
+
await this.afterBlock();
|
|
105
|
+
return {
|
|
106
|
+
type: "definition",
|
|
107
|
+
abbreviation,
|
|
108
|
+
title,
|
|
109
|
+
content,
|
|
110
|
+
key: node.key,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async definitionList(node) {
|
|
114
|
+
await this.beforeBlock();
|
|
115
|
+
const children = [];
|
|
116
|
+
for (const child of node.content) {
|
|
117
|
+
const resultNode = await this.definition(child);
|
|
118
|
+
if (resultNode) {
|
|
119
|
+
children.push(resultNode);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
await this.afterBlock();
|
|
123
|
+
return {
|
|
124
|
+
type: "definition-list",
|
|
125
|
+
content: children,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async definitionReference(node) {
|
|
129
|
+
await this.beforeInline();
|
|
130
|
+
const abbreviation = await this.chooseChildren(node.definition.abbreviation);
|
|
131
|
+
await this.afterInline();
|
|
132
|
+
return {
|
|
133
|
+
type: "definition-reference",
|
|
134
|
+
definition: {
|
|
135
|
+
abbreviation,
|
|
136
|
+
key: node.definition.key,
|
|
137
|
+
},
|
|
138
|
+
content: await this.chooseChildren(node.content),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// deno-lint-ignore require-await
|
|
142
|
+
async embed(node) {
|
|
143
|
+
return {
|
|
144
|
+
type: "embed",
|
|
145
|
+
content: {
|
|
146
|
+
...node.content,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// deno-lint-ignore require-await
|
|
151
|
+
async emoji(node) {
|
|
152
|
+
return {
|
|
153
|
+
type: "emoji",
|
|
154
|
+
url: node.url,
|
|
155
|
+
alt: node.alt,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
async figure(node) {
|
|
159
|
+
await this.beforeBlock();
|
|
160
|
+
const content = await this.chooseChildren(node.content);
|
|
161
|
+
await this.afterBlock();
|
|
162
|
+
return {
|
|
163
|
+
type: "figure",
|
|
164
|
+
content,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async figureCaption(node) {
|
|
168
|
+
await this.beforeBlock();
|
|
169
|
+
const content = await this.chooseChildren(node.content);
|
|
170
|
+
await this.afterBlock();
|
|
171
|
+
return {
|
|
172
|
+
type: "figure-caption",
|
|
173
|
+
content,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async figureImage(node) {
|
|
177
|
+
await this.beforeBlock();
|
|
178
|
+
const content = await this.chooseChildren(node.content);
|
|
179
|
+
await this.afterBlock();
|
|
180
|
+
return {
|
|
181
|
+
type: "figure-image",
|
|
182
|
+
alt: node.alt || "",
|
|
183
|
+
blurhash: node.blurhash || "",
|
|
184
|
+
height: node.height,
|
|
185
|
+
width: node.width,
|
|
186
|
+
image: node.image,
|
|
187
|
+
url: node.url,
|
|
188
|
+
content,
|
|
189
|
+
hero: node.hero,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
async formattedText(node) {
|
|
193
|
+
await this.beforeBlock();
|
|
194
|
+
await this.afterBlock();
|
|
195
|
+
return {
|
|
196
|
+
type: "formatted-text",
|
|
197
|
+
text: node.text || "",
|
|
198
|
+
language: node.language,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async header(node) {
|
|
202
|
+
await this.beforeBlock();
|
|
203
|
+
const content = await this.chooseChildren(node.content);
|
|
204
|
+
await this.afterBlock();
|
|
205
|
+
return {
|
|
206
|
+
type: "header",
|
|
207
|
+
content,
|
|
208
|
+
level: node.level || 2,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
async highTechAlert(node) {
|
|
212
|
+
await this.beforeBlock();
|
|
213
|
+
const content = await this.chooseChildren(node.content);
|
|
214
|
+
await this.afterBlock();
|
|
215
|
+
await this.beforeBlock();
|
|
216
|
+
const warning = await this.chooseChildren(node.warning);
|
|
217
|
+
await this.afterBlock();
|
|
218
|
+
return {
|
|
219
|
+
type: "high-tech-alert",
|
|
220
|
+
content,
|
|
221
|
+
warning,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
async horizontalRule(_node) {
|
|
225
|
+
await this.beforeBlock();
|
|
226
|
+
await this.afterBlock();
|
|
227
|
+
return {
|
|
228
|
+
type: "horizontal-rule",
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
async image(node) {
|
|
232
|
+
await this.beforeBlock();
|
|
233
|
+
await this.afterBlock();
|
|
234
|
+
return {
|
|
235
|
+
type: "image",
|
|
236
|
+
alt: node.alt || "",
|
|
237
|
+
blurhash: node.blurhash,
|
|
238
|
+
height: node.height,
|
|
239
|
+
width: node.width,
|
|
240
|
+
image: node.image,
|
|
241
|
+
url: node.url,
|
|
242
|
+
hero: node.hero,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
async italic(node) {
|
|
246
|
+
await this.beforeInline();
|
|
247
|
+
const content = await this.chooseChildren(node.content);
|
|
248
|
+
await this.afterInline();
|
|
249
|
+
return {
|
|
250
|
+
type: "italic",
|
|
251
|
+
content,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
async link(node) {
|
|
255
|
+
await this.beforeInline();
|
|
256
|
+
const content = await this.chooseChildren(node.content);
|
|
257
|
+
await this.afterInline();
|
|
258
|
+
return {
|
|
259
|
+
type: "link",
|
|
260
|
+
content,
|
|
261
|
+
url: node.url,
|
|
262
|
+
title: node.title,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
async array(node) {
|
|
266
|
+
return {
|
|
267
|
+
type: "array",
|
|
268
|
+
content: await this.chooseChildren(node.content),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async note(node) {
|
|
272
|
+
await this.beforeBlock();
|
|
273
|
+
const content = await this.chooseChildren(node.content);
|
|
274
|
+
await this.afterBlock();
|
|
275
|
+
return {
|
|
276
|
+
type: "note",
|
|
277
|
+
content,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
async list(node) {
|
|
281
|
+
const content = [];
|
|
282
|
+
for (const item of node.content) {
|
|
283
|
+
await this.beforeBlock();
|
|
284
|
+
const children = await this.chooseChildren(item.content);
|
|
285
|
+
await this.afterBlock();
|
|
286
|
+
if (children && children.length > 0) {
|
|
287
|
+
content.push({
|
|
288
|
+
type: "list-item",
|
|
289
|
+
content: children,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
type: "list",
|
|
295
|
+
style: node.style || "unordered",
|
|
296
|
+
content,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async paragraph(node) {
|
|
300
|
+
await this.beforeBlock();
|
|
301
|
+
const content = await this.chooseChildren(node.content);
|
|
302
|
+
await this.afterBlock();
|
|
303
|
+
return {
|
|
304
|
+
type: "paragraph",
|
|
305
|
+
content,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
async quote(node) {
|
|
309
|
+
await this.beforeBlock();
|
|
310
|
+
const content = await this.chooseChildren(node.content);
|
|
311
|
+
await this.afterBlock();
|
|
312
|
+
return {
|
|
313
|
+
type: "quote",
|
|
314
|
+
icon: node.icon,
|
|
315
|
+
name: node.name,
|
|
316
|
+
content,
|
|
317
|
+
url: node.url,
|
|
318
|
+
orientation: node.orientation,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
async redacted(node) {
|
|
322
|
+
if (node.style == "block") {
|
|
323
|
+
await this.beforeBlock();
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
await this.beforeInline();
|
|
327
|
+
}
|
|
328
|
+
const content = await this.chooseChildren(node.content);
|
|
329
|
+
if (node.style == "block") {
|
|
330
|
+
await this.afterBlock();
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
await this.afterInline();
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
type: "redacted",
|
|
337
|
+
style: node.style,
|
|
338
|
+
content,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
async region(node) {
|
|
342
|
+
await this.beforeBlock();
|
|
343
|
+
const content = await this.chooseChildren(node.content);
|
|
344
|
+
await this.afterBlock();
|
|
345
|
+
return {
|
|
346
|
+
type: "region",
|
|
347
|
+
mode: node.mode,
|
|
348
|
+
regions: node.regions,
|
|
349
|
+
content,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
// deno-lint-ignore require-await
|
|
353
|
+
async script(node) {
|
|
354
|
+
return {
|
|
355
|
+
type: "script",
|
|
356
|
+
"mime-type": node["mime-type"] || "text/javascript",
|
|
357
|
+
source: node.source,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
async secret(node) {
|
|
361
|
+
await this.beforeInline();
|
|
362
|
+
const content = await this.chooseChildren(node.content);
|
|
363
|
+
await this.afterInline();
|
|
364
|
+
return {
|
|
365
|
+
type: "secret",
|
|
366
|
+
content,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
async smaller(node) {
|
|
370
|
+
await this.beforeInline();
|
|
371
|
+
const content = await this.chooseChildren(node.content);
|
|
372
|
+
await this.afterInline();
|
|
373
|
+
return {
|
|
374
|
+
type: "smaller",
|
|
375
|
+
content,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
async sticker(node) {
|
|
379
|
+
await this.beforeBlock();
|
|
380
|
+
const content = await this.chooseChildren(node.content);
|
|
381
|
+
await this.afterBlock();
|
|
382
|
+
return {
|
|
383
|
+
type: "sticker",
|
|
384
|
+
orientation: node.orientation,
|
|
385
|
+
character: node.character,
|
|
386
|
+
name: node.name,
|
|
387
|
+
size: node.size,
|
|
388
|
+
content,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
async strikeThrough(node) {
|
|
392
|
+
await this.beforeInline();
|
|
393
|
+
const content = await this.chooseChildren(node.content);
|
|
394
|
+
await this.afterInline();
|
|
395
|
+
return {
|
|
396
|
+
type: "strike-through",
|
|
397
|
+
content,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
// deno-lint-ignore require-await
|
|
401
|
+
async text(node) {
|
|
402
|
+
return {
|
|
403
|
+
type: "text",
|
|
404
|
+
text: node.text,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
async table(node) {
|
|
408
|
+
const content = [];
|
|
409
|
+
for (const row of node.content) {
|
|
410
|
+
const cells = [];
|
|
411
|
+
let emptyCount = 0;
|
|
412
|
+
for (const cell of row) {
|
|
413
|
+
await this.beforeBlock();
|
|
414
|
+
const children = await this.chooseChildren(cell.content);
|
|
415
|
+
await this.afterBlock();
|
|
416
|
+
if (children && children.length == 0) {
|
|
417
|
+
emptyCount++;
|
|
418
|
+
}
|
|
419
|
+
cells.push({
|
|
420
|
+
type: "table-cell",
|
|
421
|
+
header: cell.header,
|
|
422
|
+
span: [cell.span[0] || 1, cell.span[1] || 1],
|
|
423
|
+
content: children,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
if (cells.length > 0 && emptyCount != cells.length) {
|
|
427
|
+
content.push(cells);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
type: "table",
|
|
432
|
+
content,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
async social(node) {
|
|
436
|
+
await this.beforeBlock();
|
|
437
|
+
await this.afterBlock();
|
|
438
|
+
return {
|
|
439
|
+
type: node.type,
|
|
440
|
+
id: node.id,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
async underline(node) {
|
|
444
|
+
await this.beforeInline();
|
|
445
|
+
const content = await this.chooseChildren(node.content);
|
|
446
|
+
await this.afterInline();
|
|
447
|
+
return {
|
|
448
|
+
type: "underline",
|
|
449
|
+
content,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
async video(node) {
|
|
453
|
+
await this.beforeBlock();
|
|
454
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
455
|
+
await this.afterBlock();
|
|
456
|
+
return {
|
|
457
|
+
type: "video",
|
|
458
|
+
alt: node.alt,
|
|
459
|
+
blurhash: node.blurhash,
|
|
460
|
+
mp4: node.mp4,
|
|
461
|
+
poster: node.poster,
|
|
462
|
+
autoplay: node.autoplay,
|
|
463
|
+
content,
|
|
464
|
+
height: node.height,
|
|
465
|
+
loop: node.loop,
|
|
466
|
+
muted: node.muted,
|
|
467
|
+
webm: node.webm,
|
|
468
|
+
width: node.width,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
async warning(node) {
|
|
472
|
+
await this.beforeBlock();
|
|
473
|
+
const content = await this.chooseChildren(node.content);
|
|
474
|
+
await this.afterBlock();
|
|
475
|
+
return {
|
|
476
|
+
type: "warning",
|
|
477
|
+
content,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
async card(node) {
|
|
481
|
+
let content;
|
|
482
|
+
if (node.content) {
|
|
483
|
+
await this.beforeBlock();
|
|
484
|
+
const cardContent = await this.chooseChildren(node.content.content);
|
|
485
|
+
if (cardContent && cardContent.length > 0) {
|
|
486
|
+
content = {
|
|
487
|
+
type: "card-content",
|
|
488
|
+
content: cardContent,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
await this.afterBlock();
|
|
492
|
+
}
|
|
493
|
+
let attribution;
|
|
494
|
+
if (node.attribution) {
|
|
495
|
+
attribution = {
|
|
496
|
+
type: "card-attribution",
|
|
497
|
+
archiveUrl: node.attribution.archiveUrl,
|
|
498
|
+
date: node.attribution.date,
|
|
499
|
+
url: node.attribution.url,
|
|
500
|
+
};
|
|
501
|
+
if (node.attribution.title) {
|
|
502
|
+
await this.beforeBlock();
|
|
503
|
+
const title = await this.chooseChildren(node.attribution.title);
|
|
504
|
+
await this.afterBlock();
|
|
505
|
+
attribution.title = title;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
let header;
|
|
509
|
+
if (node.header) {
|
|
510
|
+
await this.beforeBlock();
|
|
511
|
+
const title = await this.chooseChildren(node.header.title);
|
|
512
|
+
await this.afterBlock();
|
|
513
|
+
header = {
|
|
514
|
+
type: "card-header",
|
|
515
|
+
title,
|
|
516
|
+
backgroundBlurhash: node.header.backgroundBlurhash,
|
|
517
|
+
backgroundColor: node.header.backgroundColor,
|
|
518
|
+
backgroundImage: node.header.backgroundImage,
|
|
519
|
+
imageUrl: node.header.imageUrl,
|
|
520
|
+
imageBlurhash: node.header.imageBlurhash,
|
|
521
|
+
url: node.header.url,
|
|
522
|
+
username: node.header.username,
|
|
523
|
+
usernameDomain: node.header.usernameDomain,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
let media;
|
|
527
|
+
if (node.media) {
|
|
528
|
+
const mediaContent = [];
|
|
529
|
+
for (const mediaNode of node.media.content) {
|
|
530
|
+
await this.beforeBlock();
|
|
531
|
+
const transformedNode = await this.choose(mediaNode);
|
|
532
|
+
if (transformedNode) {
|
|
533
|
+
if (transformedNode.type == "image" ||
|
|
534
|
+
transformedNode.type == "video" ||
|
|
535
|
+
transformedNode.type == "embed") {
|
|
536
|
+
mediaContent.push(transformedNode);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
await this.afterBlock();
|
|
540
|
+
}
|
|
541
|
+
if (mediaContent.length > 0) {
|
|
542
|
+
media = {
|
|
543
|
+
type: "card-media",
|
|
544
|
+
content: mediaContent,
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
type: "card",
|
|
550
|
+
content,
|
|
551
|
+
attribution,
|
|
552
|
+
header,
|
|
553
|
+
media,
|
|
554
|
+
original: node.original,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
async choose(node) {
|
|
558
|
+
if (!node || !node.type) {
|
|
559
|
+
throw new Error(`Unexpected node, no type: ${JSON.stringify(node)}`);
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
switch (node.type) {
|
|
563
|
+
case "block":
|
|
564
|
+
return await this.block(node);
|
|
565
|
+
case "block-quote":
|
|
566
|
+
return await this.blockQuote(node);
|
|
567
|
+
case "bold":
|
|
568
|
+
return await this.bold(node);
|
|
569
|
+
case "break":
|
|
570
|
+
return await this.break_(node);
|
|
571
|
+
case "bubble":
|
|
572
|
+
return await this.bubble(node);
|
|
573
|
+
case "card":
|
|
574
|
+
return await this.card(node);
|
|
575
|
+
case "center":
|
|
576
|
+
return await this.center(node);
|
|
577
|
+
case "code":
|
|
578
|
+
return await this.code(node);
|
|
579
|
+
case "columns":
|
|
580
|
+
return await this.columns(node);
|
|
581
|
+
case "definition":
|
|
582
|
+
return await this.definition(node);
|
|
583
|
+
case "definition-list":
|
|
584
|
+
return await this.definitionList(node);
|
|
585
|
+
case "definition-reference":
|
|
586
|
+
return await this.definitionReference(node);
|
|
587
|
+
case "embed":
|
|
588
|
+
return await this.embed(node);
|
|
589
|
+
case "emoji":
|
|
590
|
+
return await this.emoji(node);
|
|
591
|
+
case "figure":
|
|
592
|
+
return await this.figure(node);
|
|
593
|
+
case "figure-caption":
|
|
594
|
+
return await this.figureCaption(node);
|
|
595
|
+
case "figure-image":
|
|
596
|
+
return await this.figureImage(node);
|
|
597
|
+
case "formatted-text":
|
|
598
|
+
return await this.formattedText(node);
|
|
599
|
+
case "header":
|
|
600
|
+
return await this.header(node);
|
|
601
|
+
case "high-tech-alert":
|
|
602
|
+
return await this.highTechAlert(node);
|
|
603
|
+
case "horizontal-rule":
|
|
604
|
+
return await this.horizontalRule(node);
|
|
605
|
+
case "image":
|
|
606
|
+
return await this.image(node);
|
|
607
|
+
case "italic":
|
|
608
|
+
return await this.italic(node);
|
|
609
|
+
case "link":
|
|
610
|
+
return await this.link(node);
|
|
611
|
+
case "array":
|
|
612
|
+
return await this.array(node);
|
|
613
|
+
case "note":
|
|
614
|
+
return await this.note(node);
|
|
615
|
+
case "list":
|
|
616
|
+
return await this.list(node);
|
|
617
|
+
case "paragraph":
|
|
618
|
+
return await this.paragraph(node);
|
|
619
|
+
case "quote":
|
|
620
|
+
return await this.quote(node);
|
|
621
|
+
case "redacted":
|
|
622
|
+
return await this.redacted(node);
|
|
623
|
+
case "region":
|
|
624
|
+
return await this.region(node);
|
|
625
|
+
case "script":
|
|
626
|
+
return await this.script(node);
|
|
627
|
+
case "secret":
|
|
628
|
+
return await this.secret(node);
|
|
629
|
+
case "smaller":
|
|
630
|
+
return await this.smaller(node);
|
|
631
|
+
case "sticker":
|
|
632
|
+
return await this.sticker(node);
|
|
633
|
+
case "strike-through":
|
|
634
|
+
return await this.strikeThrough(node);
|
|
635
|
+
case "table":
|
|
636
|
+
return await this.table(node);
|
|
637
|
+
case "text":
|
|
638
|
+
return await this.text(node);
|
|
639
|
+
case "toot":
|
|
640
|
+
case "tweet":
|
|
641
|
+
case "vimeo":
|
|
642
|
+
case "youtube":
|
|
643
|
+
return await this.social(node);
|
|
644
|
+
case "underline":
|
|
645
|
+
return await this.underline(node);
|
|
646
|
+
case "video":
|
|
647
|
+
return await this.video(node);
|
|
648
|
+
case "warning":
|
|
649
|
+
return await this.warning(node);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
catch (e) {
|
|
653
|
+
console.log(`Got exception while processing node: ${JSON.stringify(node)}`);
|
|
654
|
+
throw e;
|
|
655
|
+
}
|
|
656
|
+
//@ts-ignore fall through
|
|
657
|
+
console.error(`Unsupported type ${node.type}`);
|
|
658
|
+
return null;
|
|
659
|
+
}
|
|
660
|
+
async document(node) {
|
|
661
|
+
await this.beforeBlock();
|
|
662
|
+
const content = await this.chooseChildren(node.content);
|
|
663
|
+
await this.afterBlock();
|
|
664
|
+
await this.beforeBlock();
|
|
665
|
+
const definitions = node.definitions &&
|
|
666
|
+
(await this.chooseChildren(node.definitions)).filter((x) => x.type == "definition");
|
|
667
|
+
await this.afterBlock();
|
|
668
|
+
const result = {
|
|
669
|
+
type: "document",
|
|
670
|
+
title: node.title,
|
|
671
|
+
author: node.author,
|
|
672
|
+
content,
|
|
673
|
+
hidden: node.hidden,
|
|
674
|
+
noindex: node.noindex,
|
|
675
|
+
description: node.description,
|
|
676
|
+
image: node.image,
|
|
677
|
+
guid: node.guid,
|
|
678
|
+
"pub-date": node["pub-date"],
|
|
679
|
+
date: node.date,
|
|
680
|
+
url: node.url,
|
|
681
|
+
definitions,
|
|
682
|
+
};
|
|
683
|
+
return result;
|
|
684
|
+
}
|
|
685
|
+
async transform(node) {
|
|
686
|
+
return await this.document(node);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|