document-ir 0.0.9 → 0.0.11
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/esm/IdentityTransformer.d.ts +6 -1
- package/esm/IdentityTransformer.js +182 -41
- package/esm/NodeVisitor.d.ts +6 -1
- package/esm/NodeVisitor.js +38 -0
- package/esm/TextVisitor.d.ts +3 -1
- package/esm/TextVisitor.js +10 -0
- package/esm/types.d.ts +35 -3
- package/package.json +1 -1
- package/script/IdentityTransformer.d.ts +6 -1
- package/script/IdentityTransformer.js +182 -41
- package/script/NodeVisitor.d.ts +6 -1
- package/script/NodeVisitor.js +38 -0
- package/script/TextVisitor.d.ts +3 -1
- package/script/TextVisitor.js +10 -0
- package/script/types.d.ts +35 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StickerNode, StrikeThroughNode, TableNode, TextNode, UnderlineNode, VideoNode, WarningNode } from "./types.js";
|
|
1
|
+
import { ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TextNode, TimeNode, UnderlineNode, VideoNode, WarningNode } from "./types.js";
|
|
2
2
|
export declare class IdentityTransformer {
|
|
3
3
|
protected beforeBlock(): Promise<void>;
|
|
4
4
|
protected afterBlock(): Promise<void>;
|
|
@@ -47,6 +47,11 @@ export declare class IdentityTransformer {
|
|
|
47
47
|
protected video(node: VideoNode): Promise<Node | null>;
|
|
48
48
|
protected warning(node: WarningNode): Promise<Node | null>;
|
|
49
49
|
protected card(node: CardNode): Promise<Node | null>;
|
|
50
|
+
protected date(node: DateNode): Promise<Node | null>;
|
|
51
|
+
protected time(node: TimeNode): Promise<Node | null>;
|
|
52
|
+
protected datetime(node: DateTimeNode): Promise<Node | null>;
|
|
53
|
+
protected subText(node: SubTextNode): Promise<Node | null>;
|
|
54
|
+
protected superText(node: SuperTextNode): Promise<Node | null>;
|
|
50
55
|
protected choose(node: Node): Promise<Node | null>;
|
|
51
56
|
protected document(node: DocumentNode): Promise<DocumentNode>;
|
|
52
57
|
transform(node: DocumentNode): Promise<DocumentNode>;
|
|
@@ -177,17 +177,22 @@ export class IdentityTransformer {
|
|
|
177
177
|
await this.beforeBlock();
|
|
178
178
|
const content = await this.chooseChildren(node.content);
|
|
179
179
|
await this.afterBlock();
|
|
180
|
-
|
|
180
|
+
const result = {
|
|
181
181
|
type: "figure-image",
|
|
182
182
|
alt: node.alt || "",
|
|
183
183
|
blurhash: node.blurhash || "",
|
|
184
184
|
height: node.height,
|
|
185
185
|
width: node.width,
|
|
186
|
-
image: node.image,
|
|
187
186
|
url: node.url,
|
|
188
187
|
content,
|
|
189
|
-
hero: node.hero,
|
|
190
188
|
};
|
|
189
|
+
if (node.hero) {
|
|
190
|
+
result.hero = node.hero;
|
|
191
|
+
}
|
|
192
|
+
if (node.image) {
|
|
193
|
+
result.image = node.image;
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
191
196
|
}
|
|
192
197
|
async formattedText(node) {
|
|
193
198
|
await this.beforeBlock();
|
|
@@ -202,11 +207,15 @@ export class IdentityTransformer {
|
|
|
202
207
|
await this.beforeBlock();
|
|
203
208
|
const content = await this.chooseChildren(node.content);
|
|
204
209
|
await this.afterBlock();
|
|
205
|
-
|
|
210
|
+
const result = {
|
|
206
211
|
type: "header",
|
|
207
212
|
content,
|
|
208
213
|
level: node.level || 2,
|
|
209
214
|
};
|
|
215
|
+
if (node.htmlId) {
|
|
216
|
+
result.htmlId = node.htmlId;
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
210
219
|
}
|
|
211
220
|
async highTechAlert(node) {
|
|
212
221
|
await this.beforeBlock();
|
|
@@ -231,16 +240,27 @@ export class IdentityTransformer {
|
|
|
231
240
|
async image(node) {
|
|
232
241
|
await this.beforeBlock();
|
|
233
242
|
await this.afterBlock();
|
|
234
|
-
|
|
243
|
+
const result = {
|
|
235
244
|
type: "image",
|
|
236
245
|
alt: node.alt || "",
|
|
237
|
-
blurhash: node.blurhash,
|
|
238
|
-
height: node.height,
|
|
239
|
-
width: node.width,
|
|
240
|
-
image: node.image,
|
|
241
246
|
url: node.url,
|
|
242
|
-
hero: node.hero,
|
|
243
247
|
};
|
|
248
|
+
if (node.hero) {
|
|
249
|
+
result.hero = node.hero;
|
|
250
|
+
}
|
|
251
|
+
if (node.blurhash) {
|
|
252
|
+
result.blurhash = node.blurhash;
|
|
253
|
+
}
|
|
254
|
+
if (node.height) {
|
|
255
|
+
result.height = node.height;
|
|
256
|
+
}
|
|
257
|
+
if (node.width) {
|
|
258
|
+
result.width = node.width;
|
|
259
|
+
}
|
|
260
|
+
if (node.image) {
|
|
261
|
+
result.image = node.image;
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
244
264
|
}
|
|
245
265
|
async italic(node) {
|
|
246
266
|
await this.beforeInline();
|
|
@@ -309,14 +329,17 @@ export class IdentityTransformer {
|
|
|
309
329
|
await this.beforeBlock();
|
|
310
330
|
const content = await this.chooseChildren(node.content);
|
|
311
331
|
await this.afterBlock();
|
|
312
|
-
|
|
332
|
+
const result = {
|
|
313
333
|
type: "quote",
|
|
314
334
|
icon: node.icon,
|
|
315
335
|
name: node.name,
|
|
316
336
|
content,
|
|
317
337
|
url: node.url,
|
|
318
|
-
orientation: node.orientation,
|
|
319
338
|
};
|
|
339
|
+
if (node.orientation) {
|
|
340
|
+
result.orientation = node.orientation;
|
|
341
|
+
}
|
|
342
|
+
return result;
|
|
320
343
|
}
|
|
321
344
|
async redacted(node) {
|
|
322
345
|
if (node.style == "block") {
|
|
@@ -379,14 +402,23 @@ export class IdentityTransformer {
|
|
|
379
402
|
await this.beforeBlock();
|
|
380
403
|
const content = await this.chooseChildren(node.content);
|
|
381
404
|
await this.afterBlock();
|
|
382
|
-
|
|
405
|
+
const result = {
|
|
383
406
|
type: "sticker",
|
|
384
407
|
orientation: node.orientation,
|
|
385
408
|
character: node.character,
|
|
386
409
|
name: node.name,
|
|
387
|
-
size: node.size,
|
|
388
410
|
content,
|
|
389
411
|
};
|
|
412
|
+
if (node.size) {
|
|
413
|
+
result.size = node.size;
|
|
414
|
+
}
|
|
415
|
+
if (node.width) {
|
|
416
|
+
result.width = node.width;
|
|
417
|
+
}
|
|
418
|
+
if (node.height) {
|
|
419
|
+
result.height = node.height;
|
|
420
|
+
}
|
|
421
|
+
return result;
|
|
390
422
|
}
|
|
391
423
|
async strikeThrough(node) {
|
|
392
424
|
await this.beforeInline();
|
|
@@ -416,12 +448,15 @@ export class IdentityTransformer {
|
|
|
416
448
|
if (children && children.length == 0) {
|
|
417
449
|
emptyCount++;
|
|
418
450
|
}
|
|
419
|
-
|
|
451
|
+
const cellResult = {
|
|
420
452
|
type: "table-cell",
|
|
421
|
-
header: cell.header,
|
|
422
453
|
span: [cell.span[0] || 1, cell.span[1] || 1],
|
|
423
454
|
content: children,
|
|
424
|
-
}
|
|
455
|
+
};
|
|
456
|
+
if (cell.header) {
|
|
457
|
+
cellResult.header = cell.header;
|
|
458
|
+
}
|
|
459
|
+
cells.push(cellResult);
|
|
425
460
|
}
|
|
426
461
|
if (cells.length > 0 && emptyCount != cells.length) {
|
|
427
462
|
content.push(cells);
|
|
@@ -453,20 +488,40 @@ export class IdentityTransformer {
|
|
|
453
488
|
await this.beforeBlock();
|
|
454
489
|
const content = node.content && await this.chooseChildren(node.content);
|
|
455
490
|
await this.afterBlock();
|
|
456
|
-
|
|
491
|
+
const result = {
|
|
457
492
|
type: "video",
|
|
458
493
|
alt: node.alt,
|
|
459
|
-
blurhash: node.blurhash,
|
|
460
494
|
mp4: node.mp4,
|
|
461
495
|
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
496
|
};
|
|
497
|
+
if (node.autoplay) {
|
|
498
|
+
result.autoplay = node.autoplay;
|
|
499
|
+
}
|
|
500
|
+
if (node.blurhash) {
|
|
501
|
+
result.blurhash = node.blurhash;
|
|
502
|
+
}
|
|
503
|
+
if (content) {
|
|
504
|
+
result.content = content;
|
|
505
|
+
}
|
|
506
|
+
if (node.controls) {
|
|
507
|
+
result.controls = node.controls;
|
|
508
|
+
}
|
|
509
|
+
if (node.height) {
|
|
510
|
+
result.height = node.height;
|
|
511
|
+
}
|
|
512
|
+
if (node.width) {
|
|
513
|
+
result.width = node.width;
|
|
514
|
+
}
|
|
515
|
+
if (node.loop) {
|
|
516
|
+
result.loop = node.loop;
|
|
517
|
+
}
|
|
518
|
+
if (node.muted) {
|
|
519
|
+
result.muted = node.muted;
|
|
520
|
+
}
|
|
521
|
+
if (node.webm) {
|
|
522
|
+
result.webm = node.webm;
|
|
523
|
+
}
|
|
524
|
+
return result;
|
|
470
525
|
}
|
|
471
526
|
async warning(node) {
|
|
472
527
|
await this.beforeBlock();
|
|
@@ -494,10 +549,16 @@ export class IdentityTransformer {
|
|
|
494
549
|
if (node.attribution) {
|
|
495
550
|
attribution = {
|
|
496
551
|
type: "card-attribution",
|
|
497
|
-
archiveUrl: node.attribution.archiveUrl,
|
|
498
|
-
date: node.attribution.date,
|
|
499
|
-
url: node.attribution.url,
|
|
500
552
|
};
|
|
553
|
+
if (node.attribution.archiveUrl) {
|
|
554
|
+
attribution.archiveUrl = node.attribution.archiveUrl;
|
|
555
|
+
}
|
|
556
|
+
if (node.attribution.url) {
|
|
557
|
+
attribution.url = node.attribution.url;
|
|
558
|
+
}
|
|
559
|
+
if (node.attribution.date) {
|
|
560
|
+
attribution.date = node.attribution.date;
|
|
561
|
+
}
|
|
501
562
|
if (node.attribution.title) {
|
|
502
563
|
await this.beforeBlock();
|
|
503
564
|
const title = await this.chooseChildren(node.attribution.title);
|
|
@@ -518,10 +579,16 @@ export class IdentityTransformer {
|
|
|
518
579
|
backgroundImage: node.header.backgroundImage,
|
|
519
580
|
imageUrl: node.header.imageUrl,
|
|
520
581
|
imageBlurhash: node.header.imageBlurhash,
|
|
521
|
-
url: node.header.url,
|
|
522
|
-
username: node.header.username,
|
|
523
|
-
usernameDomain: node.header.usernameDomain,
|
|
524
582
|
};
|
|
583
|
+
if (node.header.url) {
|
|
584
|
+
header.url = node.header.url;
|
|
585
|
+
}
|
|
586
|
+
if (node.header.username) {
|
|
587
|
+
header.username = node.header.username;
|
|
588
|
+
}
|
|
589
|
+
if (node.header.usernameDomain) {
|
|
590
|
+
header.usernameDomain = node.header.usernameDomain;
|
|
591
|
+
}
|
|
525
592
|
}
|
|
526
593
|
let media;
|
|
527
594
|
if (node.media) {
|
|
@@ -554,6 +621,48 @@ export class IdentityTransformer {
|
|
|
554
621
|
original: node.original,
|
|
555
622
|
};
|
|
556
623
|
}
|
|
624
|
+
async date(node) {
|
|
625
|
+
await this.beforeInline();
|
|
626
|
+
await this.afterInline();
|
|
627
|
+
return {
|
|
628
|
+
type: "date",
|
|
629
|
+
isoDate: `${node.isoDate}`,
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
async time(node) {
|
|
633
|
+
await this.beforeInline();
|
|
634
|
+
await this.afterInline();
|
|
635
|
+
return {
|
|
636
|
+
type: "time",
|
|
637
|
+
isoTime: `${node.isoTime}`,
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
async datetime(node) {
|
|
641
|
+
await this.beforeInline();
|
|
642
|
+
await this.afterInline();
|
|
643
|
+
return {
|
|
644
|
+
type: "datetime",
|
|
645
|
+
iso8601: `${node.iso8601}`,
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
async subText(node) {
|
|
649
|
+
await this.beforeInline();
|
|
650
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
651
|
+
await this.afterInline();
|
|
652
|
+
return {
|
|
653
|
+
type: "sub",
|
|
654
|
+
content,
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
async superText(node) {
|
|
658
|
+
await this.beforeInline();
|
|
659
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
660
|
+
await this.afterInline();
|
|
661
|
+
return {
|
|
662
|
+
type: "super",
|
|
663
|
+
content,
|
|
664
|
+
};
|
|
665
|
+
}
|
|
557
666
|
async choose(node) {
|
|
558
667
|
if (!node || !node.type) {
|
|
559
668
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(node)}`);
|
|
@@ -647,6 +756,16 @@ export class IdentityTransformer {
|
|
|
647
756
|
return await this.video(node);
|
|
648
757
|
case "warning":
|
|
649
758
|
return await this.warning(node);
|
|
759
|
+
case "date":
|
|
760
|
+
return await this.date(node);
|
|
761
|
+
case "time":
|
|
762
|
+
return await this.time(node);
|
|
763
|
+
case "datetime":
|
|
764
|
+
return await this.datetime(node);
|
|
765
|
+
case "super":
|
|
766
|
+
return await this.superText(node);
|
|
767
|
+
case "sub":
|
|
768
|
+
return await this.subText(node);
|
|
650
769
|
}
|
|
651
770
|
}
|
|
652
771
|
catch (e) {
|
|
@@ -664,22 +783,44 @@ export class IdentityTransformer {
|
|
|
664
783
|
await this.beforeBlock();
|
|
665
784
|
const definitions = node.definitions &&
|
|
666
785
|
(await this.chooseChildren(node.definitions)).filter((x) => x.type == "definition");
|
|
786
|
+
const hierarchy = node.hierarchy;
|
|
667
787
|
await this.afterBlock();
|
|
668
788
|
const result = {
|
|
669
789
|
type: "document",
|
|
670
790
|
title: node.title,
|
|
671
|
-
author: node.author,
|
|
672
791
|
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
792
|
url: node.url,
|
|
681
|
-
definitions,
|
|
682
793
|
};
|
|
794
|
+
if (node.image) {
|
|
795
|
+
result.image = node.image;
|
|
796
|
+
}
|
|
797
|
+
if (node.guid) {
|
|
798
|
+
result.guid = node.guid;
|
|
799
|
+
}
|
|
800
|
+
if (node["pub-date"]) {
|
|
801
|
+
result["pub-date"] = node["pub-date"];
|
|
802
|
+
}
|
|
803
|
+
if (node.description) {
|
|
804
|
+
result.description = node.description;
|
|
805
|
+
}
|
|
806
|
+
if (node.date) {
|
|
807
|
+
result.date = node.date;
|
|
808
|
+
}
|
|
809
|
+
if (hierarchy) {
|
|
810
|
+
result.hierarchy = hierarchy;
|
|
811
|
+
}
|
|
812
|
+
if (definitions) {
|
|
813
|
+
result.definitions = definitions;
|
|
814
|
+
}
|
|
815
|
+
if (node.noindex) {
|
|
816
|
+
result.noindex = node.noindex;
|
|
817
|
+
}
|
|
818
|
+
if (node.author) {
|
|
819
|
+
result.author = node.author;
|
|
820
|
+
}
|
|
821
|
+
if (node.hidden) {
|
|
822
|
+
result.hidden = node.hidden;
|
|
823
|
+
}
|
|
683
824
|
return result;
|
|
684
825
|
}
|
|
685
826
|
async transform(node) {
|
package/esm/NodeVisitor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StickerNode, StrikeThroughNode, TableNode, TextNode, UnderlineNode, VideoNode, WarningNode } from "./types.js";
|
|
1
|
+
import { ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TextNode, TimeNode, UnderlineNode, VideoNode, WarningNode } from "./types.js";
|
|
2
2
|
export declare class NodeVisitor {
|
|
3
3
|
protected beforeBlock(): void;
|
|
4
4
|
protected afterBlock(): void;
|
|
@@ -47,6 +47,11 @@ export declare class NodeVisitor {
|
|
|
47
47
|
protected video(node: VideoNode): void;
|
|
48
48
|
protected warning(node: WarningNode): void;
|
|
49
49
|
protected card(node: CardNode): void;
|
|
50
|
+
protected date(node: DateNode): void;
|
|
51
|
+
protected time(node: TimeNode): void;
|
|
52
|
+
protected datetime(node: DateTimeNode): void;
|
|
53
|
+
protected subText(node: SubTextNode): void;
|
|
54
|
+
protected superText(node: SuperTextNode): void;
|
|
50
55
|
protected choose(node: Node): void;
|
|
51
56
|
protected document(node: DocumentNode): void;
|
|
52
57
|
visit(node: DocumentNode | Node): void;
|
package/esm/NodeVisitor.js
CHANGED
|
@@ -246,6 +246,34 @@ export class NodeVisitor {
|
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
+
date(node) {
|
|
250
|
+
this.text({
|
|
251
|
+
type: "text",
|
|
252
|
+
text: node.isoDate,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
time(node) {
|
|
256
|
+
this.text({
|
|
257
|
+
type: "text",
|
|
258
|
+
text: node.isoTime,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
datetime(node) {
|
|
262
|
+
this.text({
|
|
263
|
+
type: "text",
|
|
264
|
+
text: node.iso8601,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
subText(node) {
|
|
268
|
+
this.beforeInline();
|
|
269
|
+
this.chooseChildren(node.content);
|
|
270
|
+
this.afterInline();
|
|
271
|
+
}
|
|
272
|
+
superText(node) {
|
|
273
|
+
this.beforeInline();
|
|
274
|
+
this.chooseChildren(node.content);
|
|
275
|
+
this.afterInline();
|
|
276
|
+
}
|
|
249
277
|
choose(node) {
|
|
250
278
|
if (!node || !node.type) {
|
|
251
279
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(node)}`);
|
|
@@ -339,6 +367,16 @@ export class NodeVisitor {
|
|
|
339
367
|
return this.video(node);
|
|
340
368
|
case "warning":
|
|
341
369
|
return this.warning(node);
|
|
370
|
+
case "date":
|
|
371
|
+
return this.date(node);
|
|
372
|
+
case "time":
|
|
373
|
+
return this.time(node);
|
|
374
|
+
case "datetime":
|
|
375
|
+
return this.datetime(node);
|
|
376
|
+
case "sub":
|
|
377
|
+
return this.subText(node);
|
|
378
|
+
case "super":
|
|
379
|
+
return this.superText(node);
|
|
342
380
|
}
|
|
343
381
|
}
|
|
344
382
|
catch (e) {
|
package/esm/TextVisitor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmojiNode, FigureImageNode, ImageNode, TextNode, VideoNode } from "./types.js";
|
|
1
|
+
import { DefinitionNode, DefinitionReferenceNode, EmojiNode, FigureImageNode, ImageNode, TextNode, VideoNode } from "./types.js";
|
|
2
2
|
import { NodeVisitor } from "./NodeVisitor.js";
|
|
3
3
|
export declare class TextVisitor extends NodeVisitor {
|
|
4
4
|
private textList;
|
|
@@ -8,5 +8,7 @@ export declare class TextVisitor extends NodeVisitor {
|
|
|
8
8
|
protected image(node: ImageNode): void;
|
|
9
9
|
protected emoji(node: EmojiNode): void;
|
|
10
10
|
protected figureImage(node: FigureImageNode): void;
|
|
11
|
+
protected definitionReference(node: DefinitionReferenceNode): void;
|
|
12
|
+
protected definition(node: DefinitionNode): void;
|
|
11
13
|
getText(): string;
|
|
12
14
|
}
|
package/esm/TextVisitor.js
CHANGED
|
@@ -30,6 +30,16 @@ export class TextVisitor extends NodeVisitor {
|
|
|
30
30
|
this.textList.push(node.alt);
|
|
31
31
|
super.figureImage(node);
|
|
32
32
|
}
|
|
33
|
+
definitionReference(node) {
|
|
34
|
+
this.chooseChildren(node.content);
|
|
35
|
+
}
|
|
36
|
+
definition(node) {
|
|
37
|
+
this.chooseChildren(node.title);
|
|
38
|
+
this.textList.push(" (");
|
|
39
|
+
this.chooseChildren(node.abbreviation);
|
|
40
|
+
this.textList.push("): ");
|
|
41
|
+
this.chooseChildren(node.content);
|
|
42
|
+
}
|
|
33
43
|
getText() {
|
|
34
44
|
return this.textList.join("");
|
|
35
45
|
}
|
package/esm/types.d.ts
CHANGED
|
@@ -85,8 +85,8 @@ export interface FigureCaptionNode {
|
|
|
85
85
|
export interface FigureImageNode {
|
|
86
86
|
type: "figure-image";
|
|
87
87
|
content: Node[];
|
|
88
|
-
width
|
|
89
|
-
height
|
|
88
|
+
width?: number;
|
|
89
|
+
height?: number;
|
|
90
90
|
blurhash?: string;
|
|
91
91
|
url: string;
|
|
92
92
|
image?: string;
|
|
@@ -102,6 +102,7 @@ export interface HeaderNode {
|
|
|
102
102
|
type: "header";
|
|
103
103
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
104
104
|
content: Node[];
|
|
105
|
+
htmlId?: string;
|
|
105
106
|
}
|
|
106
107
|
export interface HighTechAlertNode {
|
|
107
108
|
type: "high-tech-alert";
|
|
@@ -196,6 +197,8 @@ export interface StickerNode {
|
|
|
196
197
|
character: string;
|
|
197
198
|
content: Node[];
|
|
198
199
|
name: string;
|
|
200
|
+
width?: number;
|
|
201
|
+
height?: number;
|
|
199
202
|
}
|
|
200
203
|
export interface TableNode {
|
|
201
204
|
type: "table";
|
|
@@ -228,6 +231,7 @@ export interface VideoNode {
|
|
|
228
231
|
autoplay?: true;
|
|
229
232
|
loop?: true;
|
|
230
233
|
content?: Node[];
|
|
234
|
+
controls?: true;
|
|
231
235
|
}
|
|
232
236
|
export interface WarningNode {
|
|
233
237
|
type: "warning";
|
|
@@ -286,7 +290,27 @@ export interface CardNode {
|
|
|
286
290
|
attribution?: CardAttribution;
|
|
287
291
|
original?: Node;
|
|
288
292
|
}
|
|
289
|
-
export
|
|
293
|
+
export interface SuperTextNode {
|
|
294
|
+
type: "super";
|
|
295
|
+
content: Node[];
|
|
296
|
+
}
|
|
297
|
+
export interface SubTextNode {
|
|
298
|
+
type: "sub";
|
|
299
|
+
content: Node[];
|
|
300
|
+
}
|
|
301
|
+
export interface DateNode {
|
|
302
|
+
type: "date";
|
|
303
|
+
isoDate: string;
|
|
304
|
+
}
|
|
305
|
+
export interface TimeNode {
|
|
306
|
+
type: "time";
|
|
307
|
+
isoTime: string;
|
|
308
|
+
}
|
|
309
|
+
export interface DateTimeNode {
|
|
310
|
+
type: "datetime";
|
|
311
|
+
iso8601: string;
|
|
312
|
+
}
|
|
313
|
+
export type Node = ArrayNode | BlockNode | BlockQuoteNode | BoldNode | BreakNode | BubbleNode | CardNode | CenterNode | CodeNode | ColumnsNode | DefinitionNode | DefinitionListNode | DefinitionReferenceNode | EmbedNode | EmojiNode | FigureNode | FigureCaptionNode | FigureImageNode | FormattedTextNode | HeaderNode | HighTechAlertNode | HorizontalRuleNode | ImageNode | ItalicNode | LinkNode | ListNode | NoteNode | ParagraphNode | QuoteNode | RedactedNode | RegionNode | ScriptNode | SecretNode | SmallerNode | StickerNode | StrikeThroughNode | TextNode | TableNode | SocialNode | UnderlineNode | VideoNode | DateNode | TimeNode | DateTimeNode | SuperTextNode | SubTextNode | WarningNode;
|
|
290
314
|
export interface DocumentMeta {
|
|
291
315
|
hidden?: boolean;
|
|
292
316
|
noindex?: boolean;
|
|
@@ -300,8 +324,16 @@ export interface DocumentMeta {
|
|
|
300
324
|
url: string;
|
|
301
325
|
contentDigest?: string;
|
|
302
326
|
}
|
|
327
|
+
export interface DocumentHierarchy {
|
|
328
|
+
headerText: string;
|
|
329
|
+
headerId?: string;
|
|
330
|
+
words: number;
|
|
331
|
+
totalWords: number;
|
|
332
|
+
children: DocumentHierarchy[];
|
|
333
|
+
}
|
|
303
334
|
export interface DocumentNode extends DocumentMeta {
|
|
304
335
|
type: "document";
|
|
305
336
|
content: Node[];
|
|
306
337
|
definitions?: DefinitionNode[];
|
|
338
|
+
hierarchy?: DocumentHierarchy;
|
|
307
339
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StickerNode, StrikeThroughNode, TableNode, TextNode, UnderlineNode, VideoNode, WarningNode } from "./types.js";
|
|
1
|
+
import { ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TextNode, TimeNode, UnderlineNode, VideoNode, WarningNode } from "./types.js";
|
|
2
2
|
export declare class IdentityTransformer {
|
|
3
3
|
protected beforeBlock(): Promise<void>;
|
|
4
4
|
protected afterBlock(): Promise<void>;
|
|
@@ -47,6 +47,11 @@ export declare class IdentityTransformer {
|
|
|
47
47
|
protected video(node: VideoNode): Promise<Node | null>;
|
|
48
48
|
protected warning(node: WarningNode): Promise<Node | null>;
|
|
49
49
|
protected card(node: CardNode): Promise<Node | null>;
|
|
50
|
+
protected date(node: DateNode): Promise<Node | null>;
|
|
51
|
+
protected time(node: TimeNode): Promise<Node | null>;
|
|
52
|
+
protected datetime(node: DateTimeNode): Promise<Node | null>;
|
|
53
|
+
protected subText(node: SubTextNode): Promise<Node | null>;
|
|
54
|
+
protected superText(node: SuperTextNode): Promise<Node | null>;
|
|
50
55
|
protected choose(node: Node): Promise<Node | null>;
|
|
51
56
|
protected document(node: DocumentNode): Promise<DocumentNode>;
|
|
52
57
|
transform(node: DocumentNode): Promise<DocumentNode>;
|
|
@@ -180,17 +180,22 @@ class IdentityTransformer {
|
|
|
180
180
|
await this.beforeBlock();
|
|
181
181
|
const content = await this.chooseChildren(node.content);
|
|
182
182
|
await this.afterBlock();
|
|
183
|
-
|
|
183
|
+
const result = {
|
|
184
184
|
type: "figure-image",
|
|
185
185
|
alt: node.alt || "",
|
|
186
186
|
blurhash: node.blurhash || "",
|
|
187
187
|
height: node.height,
|
|
188
188
|
width: node.width,
|
|
189
|
-
image: node.image,
|
|
190
189
|
url: node.url,
|
|
191
190
|
content,
|
|
192
|
-
hero: node.hero,
|
|
193
191
|
};
|
|
192
|
+
if (node.hero) {
|
|
193
|
+
result.hero = node.hero;
|
|
194
|
+
}
|
|
195
|
+
if (node.image) {
|
|
196
|
+
result.image = node.image;
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
194
199
|
}
|
|
195
200
|
async formattedText(node) {
|
|
196
201
|
await this.beforeBlock();
|
|
@@ -205,11 +210,15 @@ class IdentityTransformer {
|
|
|
205
210
|
await this.beforeBlock();
|
|
206
211
|
const content = await this.chooseChildren(node.content);
|
|
207
212
|
await this.afterBlock();
|
|
208
|
-
|
|
213
|
+
const result = {
|
|
209
214
|
type: "header",
|
|
210
215
|
content,
|
|
211
216
|
level: node.level || 2,
|
|
212
217
|
};
|
|
218
|
+
if (node.htmlId) {
|
|
219
|
+
result.htmlId = node.htmlId;
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
213
222
|
}
|
|
214
223
|
async highTechAlert(node) {
|
|
215
224
|
await this.beforeBlock();
|
|
@@ -234,16 +243,27 @@ class IdentityTransformer {
|
|
|
234
243
|
async image(node) {
|
|
235
244
|
await this.beforeBlock();
|
|
236
245
|
await this.afterBlock();
|
|
237
|
-
|
|
246
|
+
const result = {
|
|
238
247
|
type: "image",
|
|
239
248
|
alt: node.alt || "",
|
|
240
|
-
blurhash: node.blurhash,
|
|
241
|
-
height: node.height,
|
|
242
|
-
width: node.width,
|
|
243
|
-
image: node.image,
|
|
244
249
|
url: node.url,
|
|
245
|
-
hero: node.hero,
|
|
246
250
|
};
|
|
251
|
+
if (node.hero) {
|
|
252
|
+
result.hero = node.hero;
|
|
253
|
+
}
|
|
254
|
+
if (node.blurhash) {
|
|
255
|
+
result.blurhash = node.blurhash;
|
|
256
|
+
}
|
|
257
|
+
if (node.height) {
|
|
258
|
+
result.height = node.height;
|
|
259
|
+
}
|
|
260
|
+
if (node.width) {
|
|
261
|
+
result.width = node.width;
|
|
262
|
+
}
|
|
263
|
+
if (node.image) {
|
|
264
|
+
result.image = node.image;
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
247
267
|
}
|
|
248
268
|
async italic(node) {
|
|
249
269
|
await this.beforeInline();
|
|
@@ -312,14 +332,17 @@ class IdentityTransformer {
|
|
|
312
332
|
await this.beforeBlock();
|
|
313
333
|
const content = await this.chooseChildren(node.content);
|
|
314
334
|
await this.afterBlock();
|
|
315
|
-
|
|
335
|
+
const result = {
|
|
316
336
|
type: "quote",
|
|
317
337
|
icon: node.icon,
|
|
318
338
|
name: node.name,
|
|
319
339
|
content,
|
|
320
340
|
url: node.url,
|
|
321
|
-
orientation: node.orientation,
|
|
322
341
|
};
|
|
342
|
+
if (node.orientation) {
|
|
343
|
+
result.orientation = node.orientation;
|
|
344
|
+
}
|
|
345
|
+
return result;
|
|
323
346
|
}
|
|
324
347
|
async redacted(node) {
|
|
325
348
|
if (node.style == "block") {
|
|
@@ -382,14 +405,23 @@ class IdentityTransformer {
|
|
|
382
405
|
await this.beforeBlock();
|
|
383
406
|
const content = await this.chooseChildren(node.content);
|
|
384
407
|
await this.afterBlock();
|
|
385
|
-
|
|
408
|
+
const result = {
|
|
386
409
|
type: "sticker",
|
|
387
410
|
orientation: node.orientation,
|
|
388
411
|
character: node.character,
|
|
389
412
|
name: node.name,
|
|
390
|
-
size: node.size,
|
|
391
413
|
content,
|
|
392
414
|
};
|
|
415
|
+
if (node.size) {
|
|
416
|
+
result.size = node.size;
|
|
417
|
+
}
|
|
418
|
+
if (node.width) {
|
|
419
|
+
result.width = node.width;
|
|
420
|
+
}
|
|
421
|
+
if (node.height) {
|
|
422
|
+
result.height = node.height;
|
|
423
|
+
}
|
|
424
|
+
return result;
|
|
393
425
|
}
|
|
394
426
|
async strikeThrough(node) {
|
|
395
427
|
await this.beforeInline();
|
|
@@ -419,12 +451,15 @@ class IdentityTransformer {
|
|
|
419
451
|
if (children && children.length == 0) {
|
|
420
452
|
emptyCount++;
|
|
421
453
|
}
|
|
422
|
-
|
|
454
|
+
const cellResult = {
|
|
423
455
|
type: "table-cell",
|
|
424
|
-
header: cell.header,
|
|
425
456
|
span: [cell.span[0] || 1, cell.span[1] || 1],
|
|
426
457
|
content: children,
|
|
427
|
-
}
|
|
458
|
+
};
|
|
459
|
+
if (cell.header) {
|
|
460
|
+
cellResult.header = cell.header;
|
|
461
|
+
}
|
|
462
|
+
cells.push(cellResult);
|
|
428
463
|
}
|
|
429
464
|
if (cells.length > 0 && emptyCount != cells.length) {
|
|
430
465
|
content.push(cells);
|
|
@@ -456,20 +491,40 @@ class IdentityTransformer {
|
|
|
456
491
|
await this.beforeBlock();
|
|
457
492
|
const content = node.content && await this.chooseChildren(node.content);
|
|
458
493
|
await this.afterBlock();
|
|
459
|
-
|
|
494
|
+
const result = {
|
|
460
495
|
type: "video",
|
|
461
496
|
alt: node.alt,
|
|
462
|
-
blurhash: node.blurhash,
|
|
463
497
|
mp4: node.mp4,
|
|
464
498
|
poster: node.poster,
|
|
465
|
-
autoplay: node.autoplay,
|
|
466
|
-
content,
|
|
467
|
-
height: node.height,
|
|
468
|
-
loop: node.loop,
|
|
469
|
-
muted: node.muted,
|
|
470
|
-
webm: node.webm,
|
|
471
|
-
width: node.width,
|
|
472
499
|
};
|
|
500
|
+
if (node.autoplay) {
|
|
501
|
+
result.autoplay = node.autoplay;
|
|
502
|
+
}
|
|
503
|
+
if (node.blurhash) {
|
|
504
|
+
result.blurhash = node.blurhash;
|
|
505
|
+
}
|
|
506
|
+
if (content) {
|
|
507
|
+
result.content = content;
|
|
508
|
+
}
|
|
509
|
+
if (node.controls) {
|
|
510
|
+
result.controls = node.controls;
|
|
511
|
+
}
|
|
512
|
+
if (node.height) {
|
|
513
|
+
result.height = node.height;
|
|
514
|
+
}
|
|
515
|
+
if (node.width) {
|
|
516
|
+
result.width = node.width;
|
|
517
|
+
}
|
|
518
|
+
if (node.loop) {
|
|
519
|
+
result.loop = node.loop;
|
|
520
|
+
}
|
|
521
|
+
if (node.muted) {
|
|
522
|
+
result.muted = node.muted;
|
|
523
|
+
}
|
|
524
|
+
if (node.webm) {
|
|
525
|
+
result.webm = node.webm;
|
|
526
|
+
}
|
|
527
|
+
return result;
|
|
473
528
|
}
|
|
474
529
|
async warning(node) {
|
|
475
530
|
await this.beforeBlock();
|
|
@@ -497,10 +552,16 @@ class IdentityTransformer {
|
|
|
497
552
|
if (node.attribution) {
|
|
498
553
|
attribution = {
|
|
499
554
|
type: "card-attribution",
|
|
500
|
-
archiveUrl: node.attribution.archiveUrl,
|
|
501
|
-
date: node.attribution.date,
|
|
502
|
-
url: node.attribution.url,
|
|
503
555
|
};
|
|
556
|
+
if (node.attribution.archiveUrl) {
|
|
557
|
+
attribution.archiveUrl = node.attribution.archiveUrl;
|
|
558
|
+
}
|
|
559
|
+
if (node.attribution.url) {
|
|
560
|
+
attribution.url = node.attribution.url;
|
|
561
|
+
}
|
|
562
|
+
if (node.attribution.date) {
|
|
563
|
+
attribution.date = node.attribution.date;
|
|
564
|
+
}
|
|
504
565
|
if (node.attribution.title) {
|
|
505
566
|
await this.beforeBlock();
|
|
506
567
|
const title = await this.chooseChildren(node.attribution.title);
|
|
@@ -521,10 +582,16 @@ class IdentityTransformer {
|
|
|
521
582
|
backgroundImage: node.header.backgroundImage,
|
|
522
583
|
imageUrl: node.header.imageUrl,
|
|
523
584
|
imageBlurhash: node.header.imageBlurhash,
|
|
524
|
-
url: node.header.url,
|
|
525
|
-
username: node.header.username,
|
|
526
|
-
usernameDomain: node.header.usernameDomain,
|
|
527
585
|
};
|
|
586
|
+
if (node.header.url) {
|
|
587
|
+
header.url = node.header.url;
|
|
588
|
+
}
|
|
589
|
+
if (node.header.username) {
|
|
590
|
+
header.username = node.header.username;
|
|
591
|
+
}
|
|
592
|
+
if (node.header.usernameDomain) {
|
|
593
|
+
header.usernameDomain = node.header.usernameDomain;
|
|
594
|
+
}
|
|
528
595
|
}
|
|
529
596
|
let media;
|
|
530
597
|
if (node.media) {
|
|
@@ -557,6 +624,48 @@ class IdentityTransformer {
|
|
|
557
624
|
original: node.original,
|
|
558
625
|
};
|
|
559
626
|
}
|
|
627
|
+
async date(node) {
|
|
628
|
+
await this.beforeInline();
|
|
629
|
+
await this.afterInline();
|
|
630
|
+
return {
|
|
631
|
+
type: "date",
|
|
632
|
+
isoDate: `${node.isoDate}`,
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
async time(node) {
|
|
636
|
+
await this.beforeInline();
|
|
637
|
+
await this.afterInline();
|
|
638
|
+
return {
|
|
639
|
+
type: "time",
|
|
640
|
+
isoTime: `${node.isoTime}`,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
async datetime(node) {
|
|
644
|
+
await this.beforeInline();
|
|
645
|
+
await this.afterInline();
|
|
646
|
+
return {
|
|
647
|
+
type: "datetime",
|
|
648
|
+
iso8601: `${node.iso8601}`,
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
async subText(node) {
|
|
652
|
+
await this.beforeInline();
|
|
653
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
654
|
+
await this.afterInline();
|
|
655
|
+
return {
|
|
656
|
+
type: "sub",
|
|
657
|
+
content,
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
async superText(node) {
|
|
661
|
+
await this.beforeInline();
|
|
662
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
663
|
+
await this.afterInline();
|
|
664
|
+
return {
|
|
665
|
+
type: "super",
|
|
666
|
+
content,
|
|
667
|
+
};
|
|
668
|
+
}
|
|
560
669
|
async choose(node) {
|
|
561
670
|
if (!node || !node.type) {
|
|
562
671
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(node)}`);
|
|
@@ -650,6 +759,16 @@ class IdentityTransformer {
|
|
|
650
759
|
return await this.video(node);
|
|
651
760
|
case "warning":
|
|
652
761
|
return await this.warning(node);
|
|
762
|
+
case "date":
|
|
763
|
+
return await this.date(node);
|
|
764
|
+
case "time":
|
|
765
|
+
return await this.time(node);
|
|
766
|
+
case "datetime":
|
|
767
|
+
return await this.datetime(node);
|
|
768
|
+
case "super":
|
|
769
|
+
return await this.superText(node);
|
|
770
|
+
case "sub":
|
|
771
|
+
return await this.subText(node);
|
|
653
772
|
}
|
|
654
773
|
}
|
|
655
774
|
catch (e) {
|
|
@@ -667,22 +786,44 @@ class IdentityTransformer {
|
|
|
667
786
|
await this.beforeBlock();
|
|
668
787
|
const definitions = node.definitions &&
|
|
669
788
|
(await this.chooseChildren(node.definitions)).filter((x) => x.type == "definition");
|
|
789
|
+
const hierarchy = node.hierarchy;
|
|
670
790
|
await this.afterBlock();
|
|
671
791
|
const result = {
|
|
672
792
|
type: "document",
|
|
673
793
|
title: node.title,
|
|
674
|
-
author: node.author,
|
|
675
794
|
content,
|
|
676
|
-
hidden: node.hidden,
|
|
677
|
-
noindex: node.noindex,
|
|
678
|
-
description: node.description,
|
|
679
|
-
image: node.image,
|
|
680
|
-
guid: node.guid,
|
|
681
|
-
"pub-date": node["pub-date"],
|
|
682
|
-
date: node.date,
|
|
683
795
|
url: node.url,
|
|
684
|
-
definitions,
|
|
685
796
|
};
|
|
797
|
+
if (node.image) {
|
|
798
|
+
result.image = node.image;
|
|
799
|
+
}
|
|
800
|
+
if (node.guid) {
|
|
801
|
+
result.guid = node.guid;
|
|
802
|
+
}
|
|
803
|
+
if (node["pub-date"]) {
|
|
804
|
+
result["pub-date"] = node["pub-date"];
|
|
805
|
+
}
|
|
806
|
+
if (node.description) {
|
|
807
|
+
result.description = node.description;
|
|
808
|
+
}
|
|
809
|
+
if (node.date) {
|
|
810
|
+
result.date = node.date;
|
|
811
|
+
}
|
|
812
|
+
if (hierarchy) {
|
|
813
|
+
result.hierarchy = hierarchy;
|
|
814
|
+
}
|
|
815
|
+
if (definitions) {
|
|
816
|
+
result.definitions = definitions;
|
|
817
|
+
}
|
|
818
|
+
if (node.noindex) {
|
|
819
|
+
result.noindex = node.noindex;
|
|
820
|
+
}
|
|
821
|
+
if (node.author) {
|
|
822
|
+
result.author = node.author;
|
|
823
|
+
}
|
|
824
|
+
if (node.hidden) {
|
|
825
|
+
result.hidden = node.hidden;
|
|
826
|
+
}
|
|
686
827
|
return result;
|
|
687
828
|
}
|
|
688
829
|
async transform(node) {
|
package/script/NodeVisitor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StickerNode, StrikeThroughNode, TableNode, TextNode, UnderlineNode, VideoNode, WarningNode } from "./types.js";
|
|
1
|
+
import { ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TextNode, TimeNode, UnderlineNode, VideoNode, WarningNode } from "./types.js";
|
|
2
2
|
export declare class NodeVisitor {
|
|
3
3
|
protected beforeBlock(): void;
|
|
4
4
|
protected afterBlock(): void;
|
|
@@ -47,6 +47,11 @@ export declare class NodeVisitor {
|
|
|
47
47
|
protected video(node: VideoNode): void;
|
|
48
48
|
protected warning(node: WarningNode): void;
|
|
49
49
|
protected card(node: CardNode): void;
|
|
50
|
+
protected date(node: DateNode): void;
|
|
51
|
+
protected time(node: TimeNode): void;
|
|
52
|
+
protected datetime(node: DateTimeNode): void;
|
|
53
|
+
protected subText(node: SubTextNode): void;
|
|
54
|
+
protected superText(node: SuperTextNode): void;
|
|
50
55
|
protected choose(node: Node): void;
|
|
51
56
|
protected document(node: DocumentNode): void;
|
|
52
57
|
visit(node: DocumentNode | Node): void;
|
package/script/NodeVisitor.js
CHANGED
|
@@ -249,6 +249,34 @@ class NodeVisitor {
|
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
+
date(node) {
|
|
253
|
+
this.text({
|
|
254
|
+
type: "text",
|
|
255
|
+
text: node.isoDate,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
time(node) {
|
|
259
|
+
this.text({
|
|
260
|
+
type: "text",
|
|
261
|
+
text: node.isoTime,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
datetime(node) {
|
|
265
|
+
this.text({
|
|
266
|
+
type: "text",
|
|
267
|
+
text: node.iso8601,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
subText(node) {
|
|
271
|
+
this.beforeInline();
|
|
272
|
+
this.chooseChildren(node.content);
|
|
273
|
+
this.afterInline();
|
|
274
|
+
}
|
|
275
|
+
superText(node) {
|
|
276
|
+
this.beforeInline();
|
|
277
|
+
this.chooseChildren(node.content);
|
|
278
|
+
this.afterInline();
|
|
279
|
+
}
|
|
252
280
|
choose(node) {
|
|
253
281
|
if (!node || !node.type) {
|
|
254
282
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(node)}`);
|
|
@@ -342,6 +370,16 @@ class NodeVisitor {
|
|
|
342
370
|
return this.video(node);
|
|
343
371
|
case "warning":
|
|
344
372
|
return this.warning(node);
|
|
373
|
+
case "date":
|
|
374
|
+
return this.date(node);
|
|
375
|
+
case "time":
|
|
376
|
+
return this.time(node);
|
|
377
|
+
case "datetime":
|
|
378
|
+
return this.datetime(node);
|
|
379
|
+
case "sub":
|
|
380
|
+
return this.subText(node);
|
|
381
|
+
case "super":
|
|
382
|
+
return this.superText(node);
|
|
345
383
|
}
|
|
346
384
|
}
|
|
347
385
|
catch (e) {
|
package/script/TextVisitor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmojiNode, FigureImageNode, ImageNode, TextNode, VideoNode } from "./types.js";
|
|
1
|
+
import { DefinitionNode, DefinitionReferenceNode, EmojiNode, FigureImageNode, ImageNode, TextNode, VideoNode } from "./types.js";
|
|
2
2
|
import { NodeVisitor } from "./NodeVisitor.js";
|
|
3
3
|
export declare class TextVisitor extends NodeVisitor {
|
|
4
4
|
private textList;
|
|
@@ -8,5 +8,7 @@ export declare class TextVisitor extends NodeVisitor {
|
|
|
8
8
|
protected image(node: ImageNode): void;
|
|
9
9
|
protected emoji(node: EmojiNode): void;
|
|
10
10
|
protected figureImage(node: FigureImageNode): void;
|
|
11
|
+
protected definitionReference(node: DefinitionReferenceNode): void;
|
|
12
|
+
protected definition(node: DefinitionNode): void;
|
|
11
13
|
getText(): string;
|
|
12
14
|
}
|
package/script/TextVisitor.js
CHANGED
|
@@ -33,6 +33,16 @@ class TextVisitor extends NodeVisitor_js_1.NodeVisitor {
|
|
|
33
33
|
this.textList.push(node.alt);
|
|
34
34
|
super.figureImage(node);
|
|
35
35
|
}
|
|
36
|
+
definitionReference(node) {
|
|
37
|
+
this.chooseChildren(node.content);
|
|
38
|
+
}
|
|
39
|
+
definition(node) {
|
|
40
|
+
this.chooseChildren(node.title);
|
|
41
|
+
this.textList.push(" (");
|
|
42
|
+
this.chooseChildren(node.abbreviation);
|
|
43
|
+
this.textList.push("): ");
|
|
44
|
+
this.chooseChildren(node.content);
|
|
45
|
+
}
|
|
36
46
|
getText() {
|
|
37
47
|
return this.textList.join("");
|
|
38
48
|
}
|
package/script/types.d.ts
CHANGED
|
@@ -85,8 +85,8 @@ export interface FigureCaptionNode {
|
|
|
85
85
|
export interface FigureImageNode {
|
|
86
86
|
type: "figure-image";
|
|
87
87
|
content: Node[];
|
|
88
|
-
width
|
|
89
|
-
height
|
|
88
|
+
width?: number;
|
|
89
|
+
height?: number;
|
|
90
90
|
blurhash?: string;
|
|
91
91
|
url: string;
|
|
92
92
|
image?: string;
|
|
@@ -102,6 +102,7 @@ export interface HeaderNode {
|
|
|
102
102
|
type: "header";
|
|
103
103
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
104
104
|
content: Node[];
|
|
105
|
+
htmlId?: string;
|
|
105
106
|
}
|
|
106
107
|
export interface HighTechAlertNode {
|
|
107
108
|
type: "high-tech-alert";
|
|
@@ -196,6 +197,8 @@ export interface StickerNode {
|
|
|
196
197
|
character: string;
|
|
197
198
|
content: Node[];
|
|
198
199
|
name: string;
|
|
200
|
+
width?: number;
|
|
201
|
+
height?: number;
|
|
199
202
|
}
|
|
200
203
|
export interface TableNode {
|
|
201
204
|
type: "table";
|
|
@@ -228,6 +231,7 @@ export interface VideoNode {
|
|
|
228
231
|
autoplay?: true;
|
|
229
232
|
loop?: true;
|
|
230
233
|
content?: Node[];
|
|
234
|
+
controls?: true;
|
|
231
235
|
}
|
|
232
236
|
export interface WarningNode {
|
|
233
237
|
type: "warning";
|
|
@@ -286,7 +290,27 @@ export interface CardNode {
|
|
|
286
290
|
attribution?: CardAttribution;
|
|
287
291
|
original?: Node;
|
|
288
292
|
}
|
|
289
|
-
export
|
|
293
|
+
export interface SuperTextNode {
|
|
294
|
+
type: "super";
|
|
295
|
+
content: Node[];
|
|
296
|
+
}
|
|
297
|
+
export interface SubTextNode {
|
|
298
|
+
type: "sub";
|
|
299
|
+
content: Node[];
|
|
300
|
+
}
|
|
301
|
+
export interface DateNode {
|
|
302
|
+
type: "date";
|
|
303
|
+
isoDate: string;
|
|
304
|
+
}
|
|
305
|
+
export interface TimeNode {
|
|
306
|
+
type: "time";
|
|
307
|
+
isoTime: string;
|
|
308
|
+
}
|
|
309
|
+
export interface DateTimeNode {
|
|
310
|
+
type: "datetime";
|
|
311
|
+
iso8601: string;
|
|
312
|
+
}
|
|
313
|
+
export type Node = ArrayNode | BlockNode | BlockQuoteNode | BoldNode | BreakNode | BubbleNode | CardNode | CenterNode | CodeNode | ColumnsNode | DefinitionNode | DefinitionListNode | DefinitionReferenceNode | EmbedNode | EmojiNode | FigureNode | FigureCaptionNode | FigureImageNode | FormattedTextNode | HeaderNode | HighTechAlertNode | HorizontalRuleNode | ImageNode | ItalicNode | LinkNode | ListNode | NoteNode | ParagraphNode | QuoteNode | RedactedNode | RegionNode | ScriptNode | SecretNode | SmallerNode | StickerNode | StrikeThroughNode | TextNode | TableNode | SocialNode | UnderlineNode | VideoNode | DateNode | TimeNode | DateTimeNode | SuperTextNode | SubTextNode | WarningNode;
|
|
290
314
|
export interface DocumentMeta {
|
|
291
315
|
hidden?: boolean;
|
|
292
316
|
noindex?: boolean;
|
|
@@ -300,8 +324,16 @@ export interface DocumentMeta {
|
|
|
300
324
|
url: string;
|
|
301
325
|
contentDigest?: string;
|
|
302
326
|
}
|
|
327
|
+
export interface DocumentHierarchy {
|
|
328
|
+
headerText: string;
|
|
329
|
+
headerId?: string;
|
|
330
|
+
words: number;
|
|
331
|
+
totalWords: number;
|
|
332
|
+
children: DocumentHierarchy[];
|
|
333
|
+
}
|
|
303
334
|
export interface DocumentNode extends DocumentMeta {
|
|
304
335
|
type: "document";
|
|
305
336
|
content: Node[];
|
|
306
337
|
definitions?: DefinitionNode[];
|
|
338
|
+
hierarchy?: DocumentHierarchy;
|
|
307
339
|
}
|