document-ir 0.0.8 → 0.0.10
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 +177 -40
- 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 +177 -40
- 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();
|
|
@@ -231,16 +236,27 @@ export class IdentityTransformer {
|
|
|
231
236
|
async image(node) {
|
|
232
237
|
await this.beforeBlock();
|
|
233
238
|
await this.afterBlock();
|
|
234
|
-
|
|
239
|
+
const result = {
|
|
235
240
|
type: "image",
|
|
236
241
|
alt: node.alt || "",
|
|
237
|
-
blurhash: node.blurhash,
|
|
238
|
-
height: node.height,
|
|
239
|
-
width: node.width,
|
|
240
|
-
image: node.image,
|
|
241
242
|
url: node.url,
|
|
242
|
-
hero: node.hero,
|
|
243
243
|
};
|
|
244
|
+
if (node.hero) {
|
|
245
|
+
result.hero = node.hero;
|
|
246
|
+
}
|
|
247
|
+
if (node.blurhash) {
|
|
248
|
+
result.blurhash = node.blurhash;
|
|
249
|
+
}
|
|
250
|
+
if (node.height) {
|
|
251
|
+
result.height = node.height;
|
|
252
|
+
}
|
|
253
|
+
if (node.width) {
|
|
254
|
+
result.width = node.width;
|
|
255
|
+
}
|
|
256
|
+
if (node.image) {
|
|
257
|
+
result.image = node.image;
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
244
260
|
}
|
|
245
261
|
async italic(node) {
|
|
246
262
|
await this.beforeInline();
|
|
@@ -309,14 +325,17 @@ export class IdentityTransformer {
|
|
|
309
325
|
await this.beforeBlock();
|
|
310
326
|
const content = await this.chooseChildren(node.content);
|
|
311
327
|
await this.afterBlock();
|
|
312
|
-
|
|
328
|
+
const result = {
|
|
313
329
|
type: "quote",
|
|
314
330
|
icon: node.icon,
|
|
315
331
|
name: node.name,
|
|
316
332
|
content,
|
|
317
333
|
url: node.url,
|
|
318
|
-
orientation: node.orientation,
|
|
319
334
|
};
|
|
335
|
+
if (node.orientation) {
|
|
336
|
+
result.orientation = node.orientation;
|
|
337
|
+
}
|
|
338
|
+
return result;
|
|
320
339
|
}
|
|
321
340
|
async redacted(node) {
|
|
322
341
|
if (node.style == "block") {
|
|
@@ -379,14 +398,23 @@ export class IdentityTransformer {
|
|
|
379
398
|
await this.beforeBlock();
|
|
380
399
|
const content = await this.chooseChildren(node.content);
|
|
381
400
|
await this.afterBlock();
|
|
382
|
-
|
|
401
|
+
const result = {
|
|
383
402
|
type: "sticker",
|
|
384
403
|
orientation: node.orientation,
|
|
385
404
|
character: node.character,
|
|
386
405
|
name: node.name,
|
|
387
|
-
size: node.size,
|
|
388
406
|
content,
|
|
389
407
|
};
|
|
408
|
+
if (node.size) {
|
|
409
|
+
result.size = node.size;
|
|
410
|
+
}
|
|
411
|
+
if (node.width) {
|
|
412
|
+
result.width = node.width;
|
|
413
|
+
}
|
|
414
|
+
if (node.height) {
|
|
415
|
+
result.height = node.height;
|
|
416
|
+
}
|
|
417
|
+
return result;
|
|
390
418
|
}
|
|
391
419
|
async strikeThrough(node) {
|
|
392
420
|
await this.beforeInline();
|
|
@@ -416,12 +444,15 @@ export class IdentityTransformer {
|
|
|
416
444
|
if (children && children.length == 0) {
|
|
417
445
|
emptyCount++;
|
|
418
446
|
}
|
|
419
|
-
|
|
447
|
+
const cellResult = {
|
|
420
448
|
type: "table-cell",
|
|
421
|
-
header: cell.header,
|
|
422
449
|
span: [cell.span[0] || 1, cell.span[1] || 1],
|
|
423
450
|
content: children,
|
|
424
|
-
}
|
|
451
|
+
};
|
|
452
|
+
if (cell.header) {
|
|
453
|
+
cellResult.header = cell.header;
|
|
454
|
+
}
|
|
455
|
+
cells.push(cellResult);
|
|
425
456
|
}
|
|
426
457
|
if (cells.length > 0 && emptyCount != cells.length) {
|
|
427
458
|
content.push(cells);
|
|
@@ -453,20 +484,40 @@ export class IdentityTransformer {
|
|
|
453
484
|
await this.beforeBlock();
|
|
454
485
|
const content = node.content && await this.chooseChildren(node.content);
|
|
455
486
|
await this.afterBlock();
|
|
456
|
-
|
|
487
|
+
const result = {
|
|
457
488
|
type: "video",
|
|
458
489
|
alt: node.alt,
|
|
459
|
-
blurhash: node.blurhash,
|
|
460
490
|
mp4: node.mp4,
|
|
461
491
|
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
492
|
};
|
|
493
|
+
if (node.autoplay) {
|
|
494
|
+
result.autoplay = node.autoplay;
|
|
495
|
+
}
|
|
496
|
+
if (node.blurhash) {
|
|
497
|
+
result.blurhash = node.blurhash;
|
|
498
|
+
}
|
|
499
|
+
if (content) {
|
|
500
|
+
result.content = content;
|
|
501
|
+
}
|
|
502
|
+
if (node.controls) {
|
|
503
|
+
result.controls = node.controls;
|
|
504
|
+
}
|
|
505
|
+
if (node.height) {
|
|
506
|
+
result.height = node.height;
|
|
507
|
+
}
|
|
508
|
+
if (node.width) {
|
|
509
|
+
result.width = node.width;
|
|
510
|
+
}
|
|
511
|
+
if (node.loop) {
|
|
512
|
+
result.loop = node.loop;
|
|
513
|
+
}
|
|
514
|
+
if (node.muted) {
|
|
515
|
+
result.muted = node.muted;
|
|
516
|
+
}
|
|
517
|
+
if (node.webm) {
|
|
518
|
+
result.webm = node.webm;
|
|
519
|
+
}
|
|
520
|
+
return result;
|
|
470
521
|
}
|
|
471
522
|
async warning(node) {
|
|
472
523
|
await this.beforeBlock();
|
|
@@ -494,10 +545,16 @@ export class IdentityTransformer {
|
|
|
494
545
|
if (node.attribution) {
|
|
495
546
|
attribution = {
|
|
496
547
|
type: "card-attribution",
|
|
497
|
-
archiveUrl: node.attribution.archiveUrl,
|
|
498
|
-
date: node.attribution.date,
|
|
499
|
-
url: node.attribution.url,
|
|
500
548
|
};
|
|
549
|
+
if (node.attribution.archiveUrl) {
|
|
550
|
+
attribution.archiveUrl = node.attribution.archiveUrl;
|
|
551
|
+
}
|
|
552
|
+
if (node.attribution.url) {
|
|
553
|
+
attribution.url = node.attribution.url;
|
|
554
|
+
}
|
|
555
|
+
if (node.attribution.date) {
|
|
556
|
+
attribution.date = node.attribution.date;
|
|
557
|
+
}
|
|
501
558
|
if (node.attribution.title) {
|
|
502
559
|
await this.beforeBlock();
|
|
503
560
|
const title = await this.chooseChildren(node.attribution.title);
|
|
@@ -518,10 +575,16 @@ export class IdentityTransformer {
|
|
|
518
575
|
backgroundImage: node.header.backgroundImage,
|
|
519
576
|
imageUrl: node.header.imageUrl,
|
|
520
577
|
imageBlurhash: node.header.imageBlurhash,
|
|
521
|
-
url: node.header.url,
|
|
522
|
-
username: node.header.username,
|
|
523
|
-
usernameDomain: node.header.usernameDomain,
|
|
524
578
|
};
|
|
579
|
+
if (node.header.url) {
|
|
580
|
+
header.url = node.header.url;
|
|
581
|
+
}
|
|
582
|
+
if (node.header.username) {
|
|
583
|
+
header.username = node.header.username;
|
|
584
|
+
}
|
|
585
|
+
if (node.header.usernameDomain) {
|
|
586
|
+
header.usernameDomain = node.header.usernameDomain;
|
|
587
|
+
}
|
|
525
588
|
}
|
|
526
589
|
let media;
|
|
527
590
|
if (node.media) {
|
|
@@ -554,6 +617,48 @@ export class IdentityTransformer {
|
|
|
554
617
|
original: node.original,
|
|
555
618
|
};
|
|
556
619
|
}
|
|
620
|
+
async date(node) {
|
|
621
|
+
await this.beforeInline();
|
|
622
|
+
await this.afterInline();
|
|
623
|
+
return {
|
|
624
|
+
type: "date",
|
|
625
|
+
isoDate: `${node.isoDate}`,
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
async time(node) {
|
|
629
|
+
await this.beforeInline();
|
|
630
|
+
await this.afterInline();
|
|
631
|
+
return {
|
|
632
|
+
type: "time",
|
|
633
|
+
isoTime: `${node.isoTime}`,
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
async datetime(node) {
|
|
637
|
+
await this.beforeInline();
|
|
638
|
+
await this.afterInline();
|
|
639
|
+
return {
|
|
640
|
+
type: "datetime",
|
|
641
|
+
iso8601: `${node.iso8601}`,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
async subText(node) {
|
|
645
|
+
await this.beforeInline();
|
|
646
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
647
|
+
await this.afterInline();
|
|
648
|
+
return {
|
|
649
|
+
type: "sub",
|
|
650
|
+
content,
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
async superText(node) {
|
|
654
|
+
await this.beforeInline();
|
|
655
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
656
|
+
await this.afterInline();
|
|
657
|
+
return {
|
|
658
|
+
type: "super",
|
|
659
|
+
content,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
557
662
|
async choose(node) {
|
|
558
663
|
if (!node || !node.type) {
|
|
559
664
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(node)}`);
|
|
@@ -647,6 +752,16 @@ export class IdentityTransformer {
|
|
|
647
752
|
return await this.video(node);
|
|
648
753
|
case "warning":
|
|
649
754
|
return await this.warning(node);
|
|
755
|
+
case "date":
|
|
756
|
+
return await this.date(node);
|
|
757
|
+
case "time":
|
|
758
|
+
return await this.time(node);
|
|
759
|
+
case "datetime":
|
|
760
|
+
return await this.datetime(node);
|
|
761
|
+
case "super":
|
|
762
|
+
return await this.superText(node);
|
|
763
|
+
case "sub":
|
|
764
|
+
return await this.subText(node);
|
|
650
765
|
}
|
|
651
766
|
}
|
|
652
767
|
catch (e) {
|
|
@@ -664,22 +779,44 @@ export class IdentityTransformer {
|
|
|
664
779
|
await this.beforeBlock();
|
|
665
780
|
const definitions = node.definitions &&
|
|
666
781
|
(await this.chooseChildren(node.definitions)).filter((x) => x.type == "definition");
|
|
782
|
+
const hierarchy = node.hierarchy;
|
|
667
783
|
await this.afterBlock();
|
|
668
784
|
const result = {
|
|
669
785
|
type: "document",
|
|
670
786
|
title: node.title,
|
|
671
|
-
author: node.author,
|
|
672
787
|
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
788
|
url: node.url,
|
|
681
|
-
definitions,
|
|
682
789
|
};
|
|
790
|
+
if (node.image) {
|
|
791
|
+
result.image = node.image;
|
|
792
|
+
}
|
|
793
|
+
if (node.guid) {
|
|
794
|
+
result.guid = node.guid;
|
|
795
|
+
}
|
|
796
|
+
if (node["pub-date"]) {
|
|
797
|
+
result["pub-date"] = node["pub-date"];
|
|
798
|
+
}
|
|
799
|
+
if (node.description) {
|
|
800
|
+
result.description = node.description;
|
|
801
|
+
}
|
|
802
|
+
if (node.date) {
|
|
803
|
+
result.date = node.date;
|
|
804
|
+
}
|
|
805
|
+
if (hierarchy) {
|
|
806
|
+
result.hierarchy = hierarchy;
|
|
807
|
+
}
|
|
808
|
+
if (definitions) {
|
|
809
|
+
result.definitions = definitions;
|
|
810
|
+
}
|
|
811
|
+
if (node.noindex) {
|
|
812
|
+
result.noindex = node.noindex;
|
|
813
|
+
}
|
|
814
|
+
if (node.author) {
|
|
815
|
+
result.author = node.author;
|
|
816
|
+
}
|
|
817
|
+
if (node.hidden) {
|
|
818
|
+
result.hidden = node.hidden;
|
|
819
|
+
}
|
|
683
820
|
return result;
|
|
684
821
|
}
|
|
685
822
|
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();
|
|
@@ -234,16 +239,27 @@ class IdentityTransformer {
|
|
|
234
239
|
async image(node) {
|
|
235
240
|
await this.beforeBlock();
|
|
236
241
|
await this.afterBlock();
|
|
237
|
-
|
|
242
|
+
const result = {
|
|
238
243
|
type: "image",
|
|
239
244
|
alt: node.alt || "",
|
|
240
|
-
blurhash: node.blurhash,
|
|
241
|
-
height: node.height,
|
|
242
|
-
width: node.width,
|
|
243
|
-
image: node.image,
|
|
244
245
|
url: node.url,
|
|
245
|
-
hero: node.hero,
|
|
246
246
|
};
|
|
247
|
+
if (node.hero) {
|
|
248
|
+
result.hero = node.hero;
|
|
249
|
+
}
|
|
250
|
+
if (node.blurhash) {
|
|
251
|
+
result.blurhash = node.blurhash;
|
|
252
|
+
}
|
|
253
|
+
if (node.height) {
|
|
254
|
+
result.height = node.height;
|
|
255
|
+
}
|
|
256
|
+
if (node.width) {
|
|
257
|
+
result.width = node.width;
|
|
258
|
+
}
|
|
259
|
+
if (node.image) {
|
|
260
|
+
result.image = node.image;
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
247
263
|
}
|
|
248
264
|
async italic(node) {
|
|
249
265
|
await this.beforeInline();
|
|
@@ -312,14 +328,17 @@ class IdentityTransformer {
|
|
|
312
328
|
await this.beforeBlock();
|
|
313
329
|
const content = await this.chooseChildren(node.content);
|
|
314
330
|
await this.afterBlock();
|
|
315
|
-
|
|
331
|
+
const result = {
|
|
316
332
|
type: "quote",
|
|
317
333
|
icon: node.icon,
|
|
318
334
|
name: node.name,
|
|
319
335
|
content,
|
|
320
336
|
url: node.url,
|
|
321
|
-
orientation: node.orientation,
|
|
322
337
|
};
|
|
338
|
+
if (node.orientation) {
|
|
339
|
+
result.orientation = node.orientation;
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
323
342
|
}
|
|
324
343
|
async redacted(node) {
|
|
325
344
|
if (node.style == "block") {
|
|
@@ -382,14 +401,23 @@ class IdentityTransformer {
|
|
|
382
401
|
await this.beforeBlock();
|
|
383
402
|
const content = await this.chooseChildren(node.content);
|
|
384
403
|
await this.afterBlock();
|
|
385
|
-
|
|
404
|
+
const result = {
|
|
386
405
|
type: "sticker",
|
|
387
406
|
orientation: node.orientation,
|
|
388
407
|
character: node.character,
|
|
389
408
|
name: node.name,
|
|
390
|
-
size: node.size,
|
|
391
409
|
content,
|
|
392
410
|
};
|
|
411
|
+
if (node.size) {
|
|
412
|
+
result.size = node.size;
|
|
413
|
+
}
|
|
414
|
+
if (node.width) {
|
|
415
|
+
result.width = node.width;
|
|
416
|
+
}
|
|
417
|
+
if (node.height) {
|
|
418
|
+
result.height = node.height;
|
|
419
|
+
}
|
|
420
|
+
return result;
|
|
393
421
|
}
|
|
394
422
|
async strikeThrough(node) {
|
|
395
423
|
await this.beforeInline();
|
|
@@ -419,12 +447,15 @@ class IdentityTransformer {
|
|
|
419
447
|
if (children && children.length == 0) {
|
|
420
448
|
emptyCount++;
|
|
421
449
|
}
|
|
422
|
-
|
|
450
|
+
const cellResult = {
|
|
423
451
|
type: "table-cell",
|
|
424
|
-
header: cell.header,
|
|
425
452
|
span: [cell.span[0] || 1, cell.span[1] || 1],
|
|
426
453
|
content: children,
|
|
427
|
-
}
|
|
454
|
+
};
|
|
455
|
+
if (cell.header) {
|
|
456
|
+
cellResult.header = cell.header;
|
|
457
|
+
}
|
|
458
|
+
cells.push(cellResult);
|
|
428
459
|
}
|
|
429
460
|
if (cells.length > 0 && emptyCount != cells.length) {
|
|
430
461
|
content.push(cells);
|
|
@@ -456,20 +487,40 @@ class IdentityTransformer {
|
|
|
456
487
|
await this.beforeBlock();
|
|
457
488
|
const content = node.content && await this.chooseChildren(node.content);
|
|
458
489
|
await this.afterBlock();
|
|
459
|
-
|
|
490
|
+
const result = {
|
|
460
491
|
type: "video",
|
|
461
492
|
alt: node.alt,
|
|
462
|
-
blurhash: node.blurhash,
|
|
463
493
|
mp4: node.mp4,
|
|
464
494
|
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
495
|
};
|
|
496
|
+
if (node.autoplay) {
|
|
497
|
+
result.autoplay = node.autoplay;
|
|
498
|
+
}
|
|
499
|
+
if (node.blurhash) {
|
|
500
|
+
result.blurhash = node.blurhash;
|
|
501
|
+
}
|
|
502
|
+
if (content) {
|
|
503
|
+
result.content = content;
|
|
504
|
+
}
|
|
505
|
+
if (node.controls) {
|
|
506
|
+
result.controls = node.controls;
|
|
507
|
+
}
|
|
508
|
+
if (node.height) {
|
|
509
|
+
result.height = node.height;
|
|
510
|
+
}
|
|
511
|
+
if (node.width) {
|
|
512
|
+
result.width = node.width;
|
|
513
|
+
}
|
|
514
|
+
if (node.loop) {
|
|
515
|
+
result.loop = node.loop;
|
|
516
|
+
}
|
|
517
|
+
if (node.muted) {
|
|
518
|
+
result.muted = node.muted;
|
|
519
|
+
}
|
|
520
|
+
if (node.webm) {
|
|
521
|
+
result.webm = node.webm;
|
|
522
|
+
}
|
|
523
|
+
return result;
|
|
473
524
|
}
|
|
474
525
|
async warning(node) {
|
|
475
526
|
await this.beforeBlock();
|
|
@@ -497,10 +548,16 @@ class IdentityTransformer {
|
|
|
497
548
|
if (node.attribution) {
|
|
498
549
|
attribution = {
|
|
499
550
|
type: "card-attribution",
|
|
500
|
-
archiveUrl: node.attribution.archiveUrl,
|
|
501
|
-
date: node.attribution.date,
|
|
502
|
-
url: node.attribution.url,
|
|
503
551
|
};
|
|
552
|
+
if (node.attribution.archiveUrl) {
|
|
553
|
+
attribution.archiveUrl = node.attribution.archiveUrl;
|
|
554
|
+
}
|
|
555
|
+
if (node.attribution.url) {
|
|
556
|
+
attribution.url = node.attribution.url;
|
|
557
|
+
}
|
|
558
|
+
if (node.attribution.date) {
|
|
559
|
+
attribution.date = node.attribution.date;
|
|
560
|
+
}
|
|
504
561
|
if (node.attribution.title) {
|
|
505
562
|
await this.beforeBlock();
|
|
506
563
|
const title = await this.chooseChildren(node.attribution.title);
|
|
@@ -521,10 +578,16 @@ class IdentityTransformer {
|
|
|
521
578
|
backgroundImage: node.header.backgroundImage,
|
|
522
579
|
imageUrl: node.header.imageUrl,
|
|
523
580
|
imageBlurhash: node.header.imageBlurhash,
|
|
524
|
-
url: node.header.url,
|
|
525
|
-
username: node.header.username,
|
|
526
|
-
usernameDomain: node.header.usernameDomain,
|
|
527
581
|
};
|
|
582
|
+
if (node.header.url) {
|
|
583
|
+
header.url = node.header.url;
|
|
584
|
+
}
|
|
585
|
+
if (node.header.username) {
|
|
586
|
+
header.username = node.header.username;
|
|
587
|
+
}
|
|
588
|
+
if (node.header.usernameDomain) {
|
|
589
|
+
header.usernameDomain = node.header.usernameDomain;
|
|
590
|
+
}
|
|
528
591
|
}
|
|
529
592
|
let media;
|
|
530
593
|
if (node.media) {
|
|
@@ -557,6 +620,48 @@ class IdentityTransformer {
|
|
|
557
620
|
original: node.original,
|
|
558
621
|
};
|
|
559
622
|
}
|
|
623
|
+
async date(node) {
|
|
624
|
+
await this.beforeInline();
|
|
625
|
+
await this.afterInline();
|
|
626
|
+
return {
|
|
627
|
+
type: "date",
|
|
628
|
+
isoDate: `${node.isoDate}`,
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
async time(node) {
|
|
632
|
+
await this.beforeInline();
|
|
633
|
+
await this.afterInline();
|
|
634
|
+
return {
|
|
635
|
+
type: "time",
|
|
636
|
+
isoTime: `${node.isoTime}`,
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
async datetime(node) {
|
|
640
|
+
await this.beforeInline();
|
|
641
|
+
await this.afterInline();
|
|
642
|
+
return {
|
|
643
|
+
type: "datetime",
|
|
644
|
+
iso8601: `${node.iso8601}`,
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
async subText(node) {
|
|
648
|
+
await this.beforeInline();
|
|
649
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
650
|
+
await this.afterInline();
|
|
651
|
+
return {
|
|
652
|
+
type: "sub",
|
|
653
|
+
content,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
async superText(node) {
|
|
657
|
+
await this.beforeInline();
|
|
658
|
+
const content = node.content && await this.chooseChildren(node.content);
|
|
659
|
+
await this.afterInline();
|
|
660
|
+
return {
|
|
661
|
+
type: "super",
|
|
662
|
+
content,
|
|
663
|
+
};
|
|
664
|
+
}
|
|
560
665
|
async choose(node) {
|
|
561
666
|
if (!node || !node.type) {
|
|
562
667
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(node)}`);
|
|
@@ -650,6 +755,16 @@ class IdentityTransformer {
|
|
|
650
755
|
return await this.video(node);
|
|
651
756
|
case "warning":
|
|
652
757
|
return await this.warning(node);
|
|
758
|
+
case "date":
|
|
759
|
+
return await this.date(node);
|
|
760
|
+
case "time":
|
|
761
|
+
return await this.time(node);
|
|
762
|
+
case "datetime":
|
|
763
|
+
return await this.datetime(node);
|
|
764
|
+
case "super":
|
|
765
|
+
return await this.superText(node);
|
|
766
|
+
case "sub":
|
|
767
|
+
return await this.subText(node);
|
|
653
768
|
}
|
|
654
769
|
}
|
|
655
770
|
catch (e) {
|
|
@@ -667,22 +782,44 @@ class IdentityTransformer {
|
|
|
667
782
|
await this.beforeBlock();
|
|
668
783
|
const definitions = node.definitions &&
|
|
669
784
|
(await this.chooseChildren(node.definitions)).filter((x) => x.type == "definition");
|
|
785
|
+
const hierarchy = node.hierarchy;
|
|
670
786
|
await this.afterBlock();
|
|
671
787
|
const result = {
|
|
672
788
|
type: "document",
|
|
673
789
|
title: node.title,
|
|
674
|
-
author: node.author,
|
|
675
790
|
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
791
|
url: node.url,
|
|
684
|
-
definitions,
|
|
685
792
|
};
|
|
793
|
+
if (node.image) {
|
|
794
|
+
result.image = node.image;
|
|
795
|
+
}
|
|
796
|
+
if (node.guid) {
|
|
797
|
+
result.guid = node.guid;
|
|
798
|
+
}
|
|
799
|
+
if (node["pub-date"]) {
|
|
800
|
+
result["pub-date"] = node["pub-date"];
|
|
801
|
+
}
|
|
802
|
+
if (node.description) {
|
|
803
|
+
result.description = node.description;
|
|
804
|
+
}
|
|
805
|
+
if (node.date) {
|
|
806
|
+
result.date = node.date;
|
|
807
|
+
}
|
|
808
|
+
if (hierarchy) {
|
|
809
|
+
result.hierarchy = hierarchy;
|
|
810
|
+
}
|
|
811
|
+
if (definitions) {
|
|
812
|
+
result.definitions = definitions;
|
|
813
|
+
}
|
|
814
|
+
if (node.noindex) {
|
|
815
|
+
result.noindex = node.noindex;
|
|
816
|
+
}
|
|
817
|
+
if (node.author) {
|
|
818
|
+
result.author = node.author;
|
|
819
|
+
}
|
|
820
|
+
if (node.hidden) {
|
|
821
|
+
result.hidden = node.hidden;
|
|
822
|
+
}
|
|
686
823
|
return result;
|
|
687
824
|
}
|
|
688
825
|
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
|
}
|