document-ir 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/IdentityTransformer.d.ts +4 -1
- package/dist/NodeVisitor.d.ts +4 -1
- package/dist/index.js +160 -117
- package/dist/types.d.ts +15 -1
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AccordionGroupNode, AccordionTabNode, ArrayNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, CodeBlockNode, CodeGroupNode, CodeGroupTabNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, PillNode, TimeRangeNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, StyleNode, SmallerNode, SocialNode, StandardNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TableOfContentsNode, TextNode, TimeNode, UnderlineNode, VideoNode, WarningNode } from './types.ts';
|
|
1
|
+
import { AccordionGroupNode, AccordionTabNode, ArrayNode, BadgeNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, CodeBlockNode, CodeGroupNode, CodeGroupTabNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FootnoteNode, FootnoteDisplayNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, PillNode, TimeRangeNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, StyleNode, SmallerNode, SocialNode, StandardNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TableOfContentsNode, TextNode, TimeNode, UnderlineNode, VideoNode, WarningNode } from './types.ts';
|
|
2
2
|
export declare class IdentityTransformer {
|
|
3
3
|
protected beforeBlock(): Promise<void>;
|
|
4
4
|
protected afterBlock(): Promise<void>;
|
|
5
5
|
protected beforeInline(): Promise<void>;
|
|
6
6
|
protected afterInline(): Promise<void>;
|
|
7
7
|
protected chooseChildren(nodes: Node[]): Promise<Node[]>;
|
|
8
|
+
protected badge(node: BadgeNode): Promise<Node | null>;
|
|
8
9
|
protected block(node: BlockNode): Promise<Node | null>;
|
|
9
10
|
protected blockQuote(node: BlockQuoteNode): Promise<Node | null>;
|
|
10
11
|
protected bold(node: BoldNode): Promise<Node | null>;
|
|
@@ -26,6 +27,8 @@ export declare class IdentityTransformer {
|
|
|
26
27
|
protected figure(node: FigureNode): Promise<Node | null>;
|
|
27
28
|
protected figureCaption(node: FigureCaptionNode): Promise<Node | null>;
|
|
28
29
|
protected figureImage(node: FigureImageNode): Promise<Node | null>;
|
|
30
|
+
protected footnote(node: FootnoteNode): Promise<Node | null>;
|
|
31
|
+
protected footnoteDisplay(node: FootnoteDisplayNode): Promise<Node | null>;
|
|
29
32
|
protected formattedText(node: FormattedTextNode): Promise<Node | null>;
|
|
30
33
|
protected header(node: HeaderNode): Promise<Node | null>;
|
|
31
34
|
protected highTechAlert(node: HighTechAlertNode): Promise<Node | null>;
|
package/dist/NodeVisitor.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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, TimeRangeNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StandardNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TableOfContentsNode, TextNode, TimeNode, UnderlineNode, VideoNode, WarningNode } from './types.ts';
|
|
1
|
+
import { ArrayNode, BadgeNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, ColumnsNode, DateNode, DateTimeNode, DefinitionListNode, DefinitionNode, DefinitionReferenceNode, DocumentNode, EmbedNode, EmojiNode, FigureCaptionNode, FigureImageNode, FigureNode, FootnoteNode, FootnoteDisplayNode, FormattedTextNode, HeaderNode, HighTechAlertNode, HorizontalRuleNode, ImageNode, ItalicNode, LinkNode, ListNode, Node, NoteNode, TimeRangeNode, ParagraphNode, QuoteNode, RedactedNode, RegionNode, ScriptNode, SecretNode, SmallerNode, SocialNode, StandardNode, StickerNode, StrikeThroughNode, SubTextNode, SuperTextNode, TableNode, TableOfContentsNode, TextNode, TimeNode, UnderlineNode, VideoNode, WarningNode } from './types.ts';
|
|
2
2
|
export declare class NodeVisitor {
|
|
3
3
|
protected beforeBlock(): void;
|
|
4
4
|
protected afterBlock(): void;
|
|
5
5
|
protected beforeInline(): void;
|
|
6
6
|
protected afterInline(): void;
|
|
7
7
|
protected chooseChildren(nodes: Node[]): void;
|
|
8
|
+
protected badge(_node: BadgeNode): void;
|
|
8
9
|
protected block(node: BlockNode): void;
|
|
9
10
|
protected blockQuote(node: BlockQuoteNode): void;
|
|
10
11
|
protected bold(node: BoldNode): void;
|
|
@@ -21,6 +22,8 @@ export declare class NodeVisitor {
|
|
|
21
22
|
protected figure(node: FigureNode): void;
|
|
22
23
|
protected figureCaption(node: FigureCaptionNode): void;
|
|
23
24
|
protected figureImage(node: FigureImageNode): void;
|
|
25
|
+
protected footnote(node: FootnoteNode): void;
|
|
26
|
+
protected footnoteDisplay(_node: FootnoteDisplayNode): void;
|
|
24
27
|
protected formattedText(_node: FormattedTextNode): void;
|
|
25
28
|
protected header(node: HeaderNode): void;
|
|
26
29
|
protected highTechAlert(node: HighTechAlertNode): void;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
2
|
var y = (c, t, e) => t in c ? d(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
|
|
3
|
-
var
|
|
3
|
+
var h = (c, t, e) => y(c, typeof t != "symbol" ? t + "" : t, e);
|
|
4
4
|
class u {
|
|
5
5
|
async beforeBlock() {
|
|
6
6
|
}
|
|
@@ -13,11 +13,19 @@ class u {
|
|
|
13
13
|
async chooseChildren(t) {
|
|
14
14
|
const e = [];
|
|
15
15
|
for (const i of t) {
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const s = await this.choose(i);
|
|
17
|
+
s && e.push(s);
|
|
18
18
|
}
|
|
19
19
|
return e;
|
|
20
20
|
}
|
|
21
|
+
async badge(t) {
|
|
22
|
+
const e = {
|
|
23
|
+
type: "badge",
|
|
24
|
+
url: t.url,
|
|
25
|
+
alt: t.alt
|
|
26
|
+
};
|
|
27
|
+
return t.id != null && (e.id = t.id), e;
|
|
28
|
+
}
|
|
21
29
|
async block(t) {
|
|
22
30
|
await this.beforeBlock();
|
|
23
31
|
const e = await this.chooseChildren(t.content);
|
|
@@ -100,17 +108,17 @@ class u {
|
|
|
100
108
|
await this.afterInline(), await this.beforeBlock();
|
|
101
109
|
const i = await this.chooseChildren(t.content);
|
|
102
110
|
await this.afterBlock();
|
|
103
|
-
const
|
|
111
|
+
const s = {
|
|
104
112
|
type: "accordion-tab",
|
|
105
113
|
header: e,
|
|
106
114
|
content: i
|
|
107
115
|
};
|
|
108
|
-
return t.open != null && (
|
|
116
|
+
return t.open != null && (s.open = t.open), t.id != null && (s.id = t.id), s;
|
|
109
117
|
}
|
|
110
118
|
async accordionGroup(t) {
|
|
111
119
|
const e = [];
|
|
112
|
-
for (const
|
|
113
|
-
e.push(await this.accordionTab(
|
|
120
|
+
for (const s of t.tabs)
|
|
121
|
+
e.push(await this.accordionTab(s));
|
|
114
122
|
const i = {
|
|
115
123
|
type: "accordion-group",
|
|
116
124
|
tabs: e
|
|
@@ -121,17 +129,17 @@ class u {
|
|
|
121
129
|
await this.beforeInline();
|
|
122
130
|
const e = await this.chooseChildren(t.header);
|
|
123
131
|
await this.afterInline();
|
|
124
|
-
const i = await this.code(t.content),
|
|
132
|
+
const i = await this.code(t.content), s = {
|
|
125
133
|
type: "code-group-tab",
|
|
126
134
|
header: e,
|
|
127
135
|
content: i
|
|
128
136
|
};
|
|
129
|
-
return t.copyable != null && (
|
|
137
|
+
return t.copyable != null && (s.copyable = t.copyable), t.id != null && (s.id = t.id), s;
|
|
130
138
|
}
|
|
131
139
|
async codeGroup(t) {
|
|
132
140
|
const e = [];
|
|
133
|
-
for (const
|
|
134
|
-
e.push(await this.codeGroupTab(
|
|
141
|
+
for (const s of t.tabs)
|
|
142
|
+
e.push(await this.codeGroupTab(s));
|
|
135
143
|
const i = {
|
|
136
144
|
type: "code-group",
|
|
137
145
|
tabs: e
|
|
@@ -140,8 +148,8 @@ class u {
|
|
|
140
148
|
}
|
|
141
149
|
async columns(t) {
|
|
142
150
|
const e = [];
|
|
143
|
-
for (const
|
|
144
|
-
await this.beforeBlock(), e.push(await this.chooseChildren(
|
|
151
|
+
for (const s of t.columns)
|
|
152
|
+
await this.beforeBlock(), e.push(await this.chooseChildren(s)), await this.afterBlock();
|
|
145
153
|
const i = {
|
|
146
154
|
type: "columns",
|
|
147
155
|
columns: e,
|
|
@@ -155,23 +163,23 @@ class u {
|
|
|
155
163
|
await this.afterBlock(), await this.beforeBlock();
|
|
156
164
|
const i = await this.chooseChildren(t.title);
|
|
157
165
|
await this.afterBlock(), await this.beforeBlock();
|
|
158
|
-
const
|
|
166
|
+
const s = await this.chooseChildren(t.content);
|
|
159
167
|
await this.afterBlock();
|
|
160
|
-
const
|
|
168
|
+
const r = {
|
|
161
169
|
type: "definition",
|
|
162
170
|
abbreviation: e,
|
|
163
171
|
title: i,
|
|
164
|
-
content:
|
|
172
|
+
content: s,
|
|
165
173
|
key: t.key
|
|
166
174
|
};
|
|
167
|
-
return t.id != null && (
|
|
175
|
+
return t.id != null && (r.id = t.id), r;
|
|
168
176
|
}
|
|
169
177
|
async definitionList(t) {
|
|
170
178
|
await this.beforeBlock();
|
|
171
179
|
const e = [];
|
|
172
|
-
for (const
|
|
173
|
-
const
|
|
174
|
-
|
|
180
|
+
for (const s of t.content) {
|
|
181
|
+
const r = await this.definition(s);
|
|
182
|
+
r && e.push(r);
|
|
175
183
|
}
|
|
176
184
|
await this.afterBlock();
|
|
177
185
|
const i = {
|
|
@@ -245,6 +253,22 @@ class u {
|
|
|
245
253
|
};
|
|
246
254
|
return t.id != null && (i.id = t.id), t.blurhash && (i.blurhash = t.blurhash), t.height && (i.height = t.height), t.width && (i.width = t.width), t.hero && (i.hero = t.hero), t.image && (i.image = t.image), i;
|
|
247
255
|
}
|
|
256
|
+
async footnote(t) {
|
|
257
|
+
await this.beforeInline();
|
|
258
|
+
const e = await this.chooseChildren(t.content);
|
|
259
|
+
await this.afterInline();
|
|
260
|
+
const i = {
|
|
261
|
+
type: "footnote",
|
|
262
|
+
content: e
|
|
263
|
+
};
|
|
264
|
+
return t.id != null && (i.id = t.id), i;
|
|
265
|
+
}
|
|
266
|
+
async footnoteDisplay(t) {
|
|
267
|
+
const e = {
|
|
268
|
+
type: "footnote-display"
|
|
269
|
+
};
|
|
270
|
+
return t.id != null && (e.id = t.id), e;
|
|
271
|
+
}
|
|
248
272
|
async formattedText(t) {
|
|
249
273
|
await this.beforeBlock(), await this.afterBlock();
|
|
250
274
|
const e = {
|
|
@@ -271,12 +295,12 @@ class u {
|
|
|
271
295
|
await this.afterBlock(), await this.beforeBlock();
|
|
272
296
|
const i = await this.chooseChildren(t.warning);
|
|
273
297
|
await this.afterBlock();
|
|
274
|
-
const
|
|
298
|
+
const s = {
|
|
275
299
|
type: "high-tech-alert",
|
|
276
300
|
content: e,
|
|
277
301
|
warning: i
|
|
278
302
|
};
|
|
279
|
-
return t.id != null && (
|
|
303
|
+
return t.id != null && (s.id = t.id), s;
|
|
280
304
|
}
|
|
281
305
|
async horizontalRule(t) {
|
|
282
306
|
await this.beforeBlock(), await this.afterBlock();
|
|
@@ -334,15 +358,15 @@ class u {
|
|
|
334
358
|
}
|
|
335
359
|
async list(t) {
|
|
336
360
|
const e = [];
|
|
337
|
-
for (const
|
|
361
|
+
for (const s of t.content) {
|
|
338
362
|
await this.beforeBlock();
|
|
339
|
-
const
|
|
340
|
-
if (await this.afterBlock(),
|
|
363
|
+
const r = await this.chooseChildren(s.content);
|
|
364
|
+
if (await this.afterBlock(), r && r.length > 0) {
|
|
341
365
|
const n = {
|
|
342
366
|
type: "list-item",
|
|
343
|
-
content:
|
|
367
|
+
content: r
|
|
344
368
|
};
|
|
345
|
-
|
|
369
|
+
s.id != null && (n.id = s.id), e.push(n);
|
|
346
370
|
}
|
|
347
371
|
}
|
|
348
372
|
const i = {
|
|
@@ -488,21 +512,21 @@ class u {
|
|
|
488
512
|
}
|
|
489
513
|
async table(t) {
|
|
490
514
|
const e = [];
|
|
491
|
-
for (const
|
|
492
|
-
const
|
|
515
|
+
for (const s of t.content) {
|
|
516
|
+
const r = [];
|
|
493
517
|
let n = 0;
|
|
494
|
-
for (const a of
|
|
518
|
+
for (const a of s) {
|
|
495
519
|
await this.beforeBlock();
|
|
496
520
|
const o = await this.chooseChildren(a.content);
|
|
497
521
|
await this.afterBlock(), o && o.length == 0 && n++;
|
|
498
|
-
const
|
|
522
|
+
const l = {
|
|
499
523
|
type: "table-cell",
|
|
500
524
|
span: [a.span[0] || 1, a.span[1] || 1],
|
|
501
525
|
content: o
|
|
502
526
|
};
|
|
503
|
-
a.id != null && (
|
|
527
|
+
a.id != null && (l.id = a.id), a.header && (l.header = a.header), r.push(l);
|
|
504
528
|
}
|
|
505
|
-
|
|
529
|
+
r.length > 0 && n != r.length && e.push(r);
|
|
506
530
|
}
|
|
507
531
|
const i = {
|
|
508
532
|
type: "table",
|
|
@@ -566,11 +590,11 @@ class u {
|
|
|
566
590
|
const a = await this.chooseChildren(t.attribution.title);
|
|
567
591
|
await this.afterBlock(), i.title = a;
|
|
568
592
|
}
|
|
569
|
-
let
|
|
593
|
+
let s;
|
|
570
594
|
if (t.header) {
|
|
571
595
|
await this.beforeBlock();
|
|
572
596
|
const a = await this.chooseChildren(t.header.title);
|
|
573
|
-
await this.afterBlock(),
|
|
597
|
+
await this.afterBlock(), s = {
|
|
574
598
|
type: "card-header",
|
|
575
599
|
title: a,
|
|
576
600
|
backgroundBlurhash: t.header.backgroundBlurhash,
|
|
@@ -578,27 +602,27 @@ class u {
|
|
|
578
602
|
backgroundImage: t.header.backgroundImage,
|
|
579
603
|
imageUrl: t.header.imageUrl,
|
|
580
604
|
imageBlurhash: t.header.imageBlurhash
|
|
581
|
-
}, t.header.id != null && (
|
|
605
|
+
}, t.header.id != null && (s.id = t.header.id), t.header.url && (s.url = t.header.url), t.header.username && (s.username = t.header.username), t.header.usernameDomain && (s.usernameDomain = t.header.usernameDomain);
|
|
582
606
|
}
|
|
583
|
-
let
|
|
607
|
+
let r;
|
|
584
608
|
if (t.media) {
|
|
585
609
|
const a = [];
|
|
586
610
|
for (const o of t.media.content) {
|
|
587
611
|
await this.beforeBlock();
|
|
588
|
-
const
|
|
589
|
-
|
|
612
|
+
const l = await this.choose(o);
|
|
613
|
+
l && (l.type == "image" || l.type == "video" || l.type == "embed") && a.push(l), await this.afterBlock();
|
|
590
614
|
}
|
|
591
|
-
a.length > 0 && (
|
|
615
|
+
a.length > 0 && (r = {
|
|
592
616
|
type: "card-media",
|
|
593
617
|
content: a
|
|
594
|
-
}, t.media.id != null && (
|
|
618
|
+
}, t.media.id != null && (r.id = t.media.id));
|
|
595
619
|
}
|
|
596
620
|
const n = {
|
|
597
621
|
type: "card",
|
|
598
622
|
content: e,
|
|
599
623
|
attribution: i,
|
|
600
|
-
header:
|
|
601
|
-
media:
|
|
624
|
+
header: s,
|
|
625
|
+
media: r,
|
|
602
626
|
original: t.original
|
|
603
627
|
};
|
|
604
628
|
return t.id != null && (n.id = t.id), n;
|
|
@@ -660,14 +684,14 @@ class u {
|
|
|
660
684
|
await this.beforeBlock();
|
|
661
685
|
const e = await this.chooseChildren(t.content), i = t.date && await this.choose(t.date);
|
|
662
686
|
await this.afterBlock(), await this.beforeBlock();
|
|
663
|
-
const
|
|
687
|
+
const s = await this.chooseChildren(t.children);
|
|
664
688
|
await this.afterBlock();
|
|
665
|
-
const
|
|
689
|
+
const r = s.filter(
|
|
666
690
|
(a) => a.type == "toc"
|
|
667
691
|
), n = {
|
|
668
692
|
type: "toc",
|
|
669
693
|
content: e,
|
|
670
|
-
children:
|
|
694
|
+
children: r
|
|
671
695
|
};
|
|
672
696
|
return t.id != null && (n.id = t.id), i && (i.type == "date" || i.type == "time" || i.type == "datetime") && (n.date = i), t.href && (n.href = t.href), t.hrefHtmlId && (n.hrefHtmlId = t.hrefHtmlId), n;
|
|
673
697
|
}
|
|
@@ -686,6 +710,8 @@ class u {
|
|
|
686
710
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(t)}`);
|
|
687
711
|
try {
|
|
688
712
|
switch (t.type) {
|
|
713
|
+
case "badge":
|
|
714
|
+
return await this.badge(t);
|
|
689
715
|
case "block":
|
|
690
716
|
return await this.block(t);
|
|
691
717
|
case "block-quote":
|
|
@@ -724,6 +750,10 @@ class u {
|
|
|
724
750
|
return await this.figureCaption(t);
|
|
725
751
|
case "figure-image":
|
|
726
752
|
return await this.figureImage(t);
|
|
753
|
+
case "footnote":
|
|
754
|
+
return await this.footnote(t);
|
|
755
|
+
case "footnote-display":
|
|
756
|
+
return await this.footnoteDisplay(t);
|
|
727
757
|
case "formatted-text":
|
|
728
758
|
return await this.formattedText(t);
|
|
729
759
|
case "header":
|
|
@@ -813,15 +843,15 @@ class u {
|
|
|
813
843
|
await this.afterBlock(), await this.beforeBlock();
|
|
814
844
|
const i = t.definitions && (await this.chooseChildren(t.definitions)).filter(
|
|
815
845
|
(n) => n.type == "definition"
|
|
816
|
-
),
|
|
846
|
+
), s = t.hierarchy;
|
|
817
847
|
await this.afterBlock();
|
|
818
|
-
const
|
|
848
|
+
const r = {
|
|
819
849
|
type: "document",
|
|
820
850
|
title: t.title,
|
|
821
851
|
content: e,
|
|
822
852
|
url: t.url
|
|
823
853
|
};
|
|
824
|
-
return t.image && (
|
|
854
|
+
return t.image && (r.image = t.image), t.guid && (r.guid = t.guid), t["pub-date"] && (r["pub-date"] = t["pub-date"]), t.description && (r.description = t.description), t.date && (r.date = t.date), s && (r.hierarchy = s), i && (r.definitions = i), t.noindex && (r.noindex = t.noindex), t.author && (r.author = t.author), t.hidden && (r.hidden = t.hidden), t.readingDifficultyMultiplier && (r.readingDifficultyMultiplier = t.readingDifficultyMultiplier), t.contentDigest && (r.contentDigest = t.contentDigest), t.keywords && (r.keywords = t.keywords), t.disableHeadingRequirement != null && (r.disableHeadingRequirement = t.disableHeadingRequirement), t.disableToc != null && (r.disableToc = t.disableToc), r;
|
|
825
855
|
}
|
|
826
856
|
async transform(t) {
|
|
827
857
|
return await this.document(t);
|
|
@@ -830,37 +860,37 @@ class u {
|
|
|
830
860
|
class k extends u {
|
|
831
861
|
async chooseChildren(t) {
|
|
832
862
|
const e = await super.chooseChildren(t), i = [];
|
|
833
|
-
for (const
|
|
834
|
-
if (
|
|
835
|
-
for (const
|
|
836
|
-
i.push(
|
|
863
|
+
for (const s of e)
|
|
864
|
+
if (s.type == "array")
|
|
865
|
+
for (const r of s.content)
|
|
866
|
+
i.push(r);
|
|
837
867
|
else
|
|
838
|
-
i.push(
|
|
868
|
+
i.push(s);
|
|
839
869
|
return i;
|
|
840
870
|
}
|
|
841
871
|
}
|
|
842
872
|
class I extends u {
|
|
843
873
|
async chooseChildren(t) {
|
|
844
874
|
const e = await super.chooseChildren(t), i = [];
|
|
845
|
-
let
|
|
875
|
+
let s = null, r;
|
|
846
876
|
for (const n of e)
|
|
847
877
|
if (n.type == "text")
|
|
848
|
-
|
|
878
|
+
s != null ? s = `${s}${n.text}` : (s = n.text, r = n.id);
|
|
849
879
|
else {
|
|
850
|
-
if (
|
|
851
|
-
const a = { type: "text", text:
|
|
852
|
-
|
|
880
|
+
if (s != null) {
|
|
881
|
+
const a = { type: "text", text: s };
|
|
882
|
+
r != null && (a.id = r), i.push(a), s = null, r = void 0;
|
|
853
883
|
}
|
|
854
884
|
i.push(n);
|
|
855
885
|
}
|
|
856
|
-
if (
|
|
857
|
-
const n = { type: "text", text:
|
|
858
|
-
|
|
886
|
+
if (s != null) {
|
|
887
|
+
const n = { type: "text", text: s };
|
|
888
|
+
r != null && (n.id = r), i.push(n);
|
|
859
889
|
}
|
|
860
890
|
return i;
|
|
861
891
|
}
|
|
862
892
|
}
|
|
863
|
-
class
|
|
893
|
+
class g extends u {
|
|
864
894
|
async text(t) {
|
|
865
895
|
return t.text == "" ? null : t;
|
|
866
896
|
}
|
|
@@ -868,22 +898,22 @@ class m extends u {
|
|
|
868
898
|
class T extends u {
|
|
869
899
|
constructor() {
|
|
870
900
|
super();
|
|
871
|
-
|
|
872
|
-
|
|
901
|
+
h(this, "stripWhitespace");
|
|
902
|
+
h(this, "lastText");
|
|
873
903
|
this.stripWhitespace = !0, this.lastText = null;
|
|
874
904
|
}
|
|
875
905
|
async text(e) {
|
|
876
906
|
let i = "";
|
|
877
|
-
for (const
|
|
878
|
-
|
|
879
|
-
` ||
|
|
907
|
+
for (const r of e.text)
|
|
908
|
+
r == " " || r == `
|
|
909
|
+
` || r == " " || r == "\r" ? this.stripWhitespace || (i += " ", this.stripWhitespace = !0) : (i += r, this.stripWhitespace = !1);
|
|
880
910
|
if (i.length == 0)
|
|
881
911
|
return null;
|
|
882
|
-
const
|
|
912
|
+
const s = {
|
|
883
913
|
type: "text",
|
|
884
914
|
text: i
|
|
885
915
|
};
|
|
886
|
-
return e.id != null && (
|
|
916
|
+
return e.id != null && (s.id = e.id), this.lastText = s, s;
|
|
887
917
|
}
|
|
888
918
|
stripLastText() {
|
|
889
919
|
this.lastText && (this.lastText.text.endsWith(" ") && (this.lastText.text = this.lastText.text.slice(0, -1)), this.lastText = null), this.stripWhitespace = !0;
|
|
@@ -896,14 +926,14 @@ class T extends u {
|
|
|
896
926
|
}
|
|
897
927
|
async transform(e) {
|
|
898
928
|
const i = await super.transform(e);
|
|
899
|
-
return await new
|
|
929
|
+
return await new g().transform(i);
|
|
900
930
|
}
|
|
901
931
|
}
|
|
902
932
|
class v extends u {
|
|
903
933
|
constructor() {
|
|
904
934
|
super();
|
|
905
|
-
|
|
906
|
-
|
|
935
|
+
h(this, "root");
|
|
936
|
+
h(this, "cursor");
|
|
907
937
|
this.root = {
|
|
908
938
|
type: "_block",
|
|
909
939
|
content: [],
|
|
@@ -933,22 +963,22 @@ class v extends u {
|
|
|
933
963
|
this.cursor.parent && (this.cursor = this.cursor.parent);
|
|
934
964
|
}
|
|
935
965
|
reviewBlock(e) {
|
|
936
|
-
const i = [],
|
|
937
|
-
if (
|
|
966
|
+
const i = [], s = (r, n) => {
|
|
967
|
+
if (r.type == "text")
|
|
938
968
|
i.push({
|
|
939
|
-
node:
|
|
969
|
+
node: r,
|
|
940
970
|
level: n
|
|
941
971
|
});
|
|
942
|
-
else if (
|
|
943
|
-
this.reviewBlock(
|
|
972
|
+
else if (r.type == "_block")
|
|
973
|
+
this.reviewBlock(r), i.push({ node: null, level: n });
|
|
944
974
|
else
|
|
945
|
-
for (const a of
|
|
946
|
-
|
|
975
|
+
for (const a of r.content)
|
|
976
|
+
s(a, n + 1);
|
|
947
977
|
};
|
|
948
|
-
for (const
|
|
949
|
-
r
|
|
950
|
-
for (let
|
|
951
|
-
const n = i[
|
|
978
|
+
for (const r of e.content)
|
|
979
|
+
s(r, 0);
|
|
980
|
+
for (let r = 0; r < i.length; r++) {
|
|
981
|
+
const n = i[r], a = r + 1 < i.length ? i[r + 1] : { node: null, level: 0 };
|
|
952
982
|
!n.node || !a.node || n.level != a.level && (n.level < a.level ? a.node.text.startsWith(" ") && (a.node.text = a.node.text.slice(1), n.node.text += " ") : n.level > a.level && n.node.text.endsWith(" ") && (n.node.text = n.node.text.slice(0, -1), a.node.text = ` ${a.node.text}`));
|
|
953
983
|
}
|
|
954
984
|
}
|
|
@@ -977,6 +1007,8 @@ class w {
|
|
|
977
1007
|
for (const e of t)
|
|
978
1008
|
this.choose(e);
|
|
979
1009
|
}
|
|
1010
|
+
badge(t) {
|
|
1011
|
+
}
|
|
980
1012
|
block(t) {
|
|
981
1013
|
this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
|
|
982
1014
|
}
|
|
@@ -1027,6 +1059,11 @@ class w {
|
|
|
1027
1059
|
figureImage(t) {
|
|
1028
1060
|
this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
|
|
1029
1061
|
}
|
|
1062
|
+
footnote(t) {
|
|
1063
|
+
this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
|
|
1064
|
+
}
|
|
1065
|
+
footnoteDisplay(t) {
|
|
1066
|
+
}
|
|
1030
1067
|
formattedText(t) {
|
|
1031
1068
|
}
|
|
1032
1069
|
header(t) {
|
|
@@ -1133,6 +1170,8 @@ class w {
|
|
|
1133
1170
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(t)}`);
|
|
1134
1171
|
try {
|
|
1135
1172
|
switch (t.type) {
|
|
1173
|
+
case "badge":
|
|
1174
|
+
return this.badge(t);
|
|
1136
1175
|
case "block":
|
|
1137
1176
|
return this.block(t);
|
|
1138
1177
|
case "block-quote":
|
|
@@ -1167,6 +1206,10 @@ class w {
|
|
|
1167
1206
|
return this.figureCaption(t);
|
|
1168
1207
|
case "figure-image":
|
|
1169
1208
|
return this.figureImage(t);
|
|
1209
|
+
case "footnote":
|
|
1210
|
+
return this.footnote(t);
|
|
1211
|
+
case "footnote-display":
|
|
1212
|
+
return this.footnoteDisplay(t);
|
|
1170
1213
|
case "formatted-text":
|
|
1171
1214
|
return this.formattedText(t);
|
|
1172
1215
|
case "header":
|
|
@@ -1251,10 +1294,10 @@ class w {
|
|
|
1251
1294
|
t.type == "document" ? this.document(t) : this.choose(t);
|
|
1252
1295
|
}
|
|
1253
1296
|
}
|
|
1254
|
-
class
|
|
1297
|
+
class m extends w {
|
|
1255
1298
|
constructor() {
|
|
1256
1299
|
super();
|
|
1257
|
-
|
|
1300
|
+
h(this, "textList");
|
|
1258
1301
|
this.textList = [];
|
|
1259
1302
|
}
|
|
1260
1303
|
text(e) {
|
|
@@ -1394,25 +1437,25 @@ class B extends k {
|
|
|
1394
1437
|
async definitionList(t) {
|
|
1395
1438
|
const e = [];
|
|
1396
1439
|
for (const i of t.content) {
|
|
1397
|
-
const
|
|
1398
|
-
if (
|
|
1399
|
-
for (const a of
|
|
1400
|
-
|
|
1401
|
-
|
|
1440
|
+
const s = [], r = await this.chooseChildren(i.title);
|
|
1441
|
+
if (r)
|
|
1442
|
+
for (const a of r)
|
|
1443
|
+
s.push(a);
|
|
1444
|
+
s.push({ type: "text", text: " " });
|
|
1402
1445
|
const n = await this.chooseChildren(i.abbreviation);
|
|
1403
1446
|
if (n)
|
|
1404
1447
|
for (const a of n)
|
|
1405
|
-
|
|
1448
|
+
s.push(a);
|
|
1406
1449
|
if (i.content.length > 0 && i.content[0].type != "paragraph") {
|
|
1407
|
-
|
|
1450
|
+
s.push({ type: "text", text: " " });
|
|
1408
1451
|
const a = await this.chooseChildren(i.content);
|
|
1409
1452
|
if (a)
|
|
1410
1453
|
for (const o of a)
|
|
1411
|
-
|
|
1454
|
+
s.push(o);
|
|
1412
1455
|
}
|
|
1413
1456
|
if (e.push({
|
|
1414
1457
|
type: "paragraph",
|
|
1415
|
-
content:
|
|
1458
|
+
content: s
|
|
1416
1459
|
}), i.content.length > 0 && i.content[0].type == "paragraph") {
|
|
1417
1460
|
const a = await this.chooseChildren(i.content);
|
|
1418
1461
|
if (a)
|
|
@@ -1451,20 +1494,20 @@ class B extends k {
|
|
|
1451
1494
|
}
|
|
1452
1495
|
if (t.content) {
|
|
1453
1496
|
const i = await this.chooseChildren(t.content.content);
|
|
1454
|
-
for (const
|
|
1455
|
-
e.push(
|
|
1497
|
+
for (const s of i)
|
|
1498
|
+
e.push(s);
|
|
1456
1499
|
}
|
|
1457
1500
|
if (t.media)
|
|
1458
1501
|
for (const i of t.media.content) {
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1502
|
+
const s = await this.choose(i);
|
|
1503
|
+
s && e.push(s);
|
|
1461
1504
|
}
|
|
1462
1505
|
if (t.attribution) {
|
|
1463
1506
|
const i = [];
|
|
1464
1507
|
if (t.attribution.title) {
|
|
1465
|
-
const
|
|
1466
|
-
for (const
|
|
1467
|
-
e.push(
|
|
1508
|
+
const s = await this.chooseChildren(t.attribution.title);
|
|
1509
|
+
for (const r of s)
|
|
1510
|
+
e.push(r);
|
|
1468
1511
|
}
|
|
1469
1512
|
t.attribution.date && (e.length > 0 && e.push({ type: "text", text: " " }), e.push({ type: "text", text: `${t.attribution.date}` })), i.length > 0 && e.push({
|
|
1470
1513
|
type: "paragraph",
|
|
@@ -1480,8 +1523,8 @@ class B extends k {
|
|
|
1480
1523
|
class C extends w {
|
|
1481
1524
|
constructor() {
|
|
1482
1525
|
super();
|
|
1483
|
-
|
|
1484
|
-
|
|
1526
|
+
h(this, "count");
|
|
1527
|
+
h(this, "texts");
|
|
1485
1528
|
this.count = 0, this.texts = [];
|
|
1486
1529
|
}
|
|
1487
1530
|
countText() {
|
|
@@ -1515,8 +1558,8 @@ function b(c) {
|
|
|
1515
1558
|
e.visit(i);
|
|
1516
1559
|
t.words = e.getCount(), t.totalWords = t.words;
|
|
1517
1560
|
for (const i of c.children) {
|
|
1518
|
-
const
|
|
1519
|
-
t.children.push(
|
|
1561
|
+
const s = b(i);
|
|
1562
|
+
t.children.push(s), t.totalWords += s.totalWords;
|
|
1520
1563
|
}
|
|
1521
1564
|
return t;
|
|
1522
1565
|
}
|
|
@@ -1525,37 +1568,37 @@ class N extends u {
|
|
|
1525
1568
|
super();
|
|
1526
1569
|
}
|
|
1527
1570
|
async transform(t) {
|
|
1528
|
-
const e = JSON.parse(JSON.stringify(t)), i = await new B().transform(e),
|
|
1571
|
+
const e = JSON.parse(JSON.stringify(t)), i = await new B().transform(e), s = [], r = {
|
|
1529
1572
|
header: t.title,
|
|
1530
1573
|
headerId: "title",
|
|
1531
1574
|
nodes: [],
|
|
1532
1575
|
children: [],
|
|
1533
1576
|
depth: 1
|
|
1534
1577
|
};
|
|
1535
|
-
|
|
1578
|
+
s.push(r);
|
|
1536
1579
|
let n = 1;
|
|
1537
1580
|
for (const o of i.content)
|
|
1538
1581
|
if (o.type == "header") {
|
|
1539
1582
|
if (o.level == 1)
|
|
1540
1583
|
continue;
|
|
1541
1584
|
if (o.level <= n)
|
|
1542
|
-
for (let p =
|
|
1543
|
-
|
|
1544
|
-
const
|
|
1545
|
-
|
|
1585
|
+
for (let p = s.length - 1; p > 0; p--)
|
|
1586
|
+
s[p].depth >= o.level && s.pop();
|
|
1587
|
+
const l = new m();
|
|
1588
|
+
l.visit(o);
|
|
1546
1589
|
const f = {
|
|
1547
|
-
header:
|
|
1590
|
+
header: l.getText(),
|
|
1548
1591
|
depth: o.level,
|
|
1549
1592
|
children: [],
|
|
1550
1593
|
nodes: []
|
|
1551
1594
|
};
|
|
1552
|
-
o.htmlId && (f.headerId = o.htmlId),
|
|
1595
|
+
o.htmlId && (f.headerId = o.htmlId), s[s.length - 1].children.push(f), s.push(f), n = o.level;
|
|
1553
1596
|
} else
|
|
1554
|
-
|
|
1597
|
+
s[s.length - 1].nodes.push(o);
|
|
1555
1598
|
const a = {
|
|
1556
1599
|
...t
|
|
1557
1600
|
};
|
|
1558
|
-
return a.hierarchy = b(
|
|
1601
|
+
return a.hierarchy = b(r), a;
|
|
1559
1602
|
}
|
|
1560
1603
|
}
|
|
1561
1604
|
export {
|
|
@@ -1564,7 +1607,7 @@ export {
|
|
|
1564
1607
|
u as IdentityTransformer,
|
|
1565
1608
|
w as NodeVisitor,
|
|
1566
1609
|
I as TextCollapseTransformer,
|
|
1567
|
-
|
|
1610
|
+
m as TextVisitor,
|
|
1568
1611
|
v as WhitespaceStretchingTransformer,
|
|
1569
1612
|
T as WhitespaceTransformer,
|
|
1570
1613
|
N as WordCounterTransformer,
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface ArrayNode extends NodeIdentity {
|
|
|
5
5
|
type: "array";
|
|
6
6
|
content: Node[];
|
|
7
7
|
}
|
|
8
|
+
export interface BadgeNode extends NodeIdentity {
|
|
9
|
+
type: "badge";
|
|
10
|
+
url: string;
|
|
11
|
+
alt: string;
|
|
12
|
+
}
|
|
8
13
|
export interface BlockNode extends NodeIdentity {
|
|
9
14
|
type: "block";
|
|
10
15
|
content: Node[];
|
|
@@ -126,6 +131,13 @@ export interface FigureImageNode extends NodeIdentity {
|
|
|
126
131
|
alt: string;
|
|
127
132
|
hero?: true;
|
|
128
133
|
}
|
|
134
|
+
export interface FootnoteNode extends NodeIdentity {
|
|
135
|
+
type: "footnote";
|
|
136
|
+
content: Node[];
|
|
137
|
+
}
|
|
138
|
+
export interface FootnoteDisplayNode extends NodeIdentity {
|
|
139
|
+
type: "footnote-display";
|
|
140
|
+
}
|
|
129
141
|
export interface FormattedTextNode extends NodeIdentity {
|
|
130
142
|
type: "formatted-text";
|
|
131
143
|
language?: string;
|
|
@@ -379,10 +391,12 @@ export interface TableOfContentsNode extends NodeIdentity {
|
|
|
379
391
|
content: Node[];
|
|
380
392
|
children: TableOfContentsNode[];
|
|
381
393
|
}
|
|
382
|
-
export type Node = AccordionGroupNode | ArrayNode | BlockNode | BlockQuoteNode | BoldNode | BreakNode | BubbleNode | CardNode | CenterNode | CodeNode | CodeBlockNode | CodeGroupNode | ColumnsNode | DefinitionNode | DefinitionListNode | DefinitionReferenceNode | EmbedNode | EmojiNode | FigureNode | FigureCaptionNode | FigureImageNode | FormattedTextNode | HeaderNode | HighTechAlertNode | HorizontalRuleNode | ImageNode | ItalicNode | LinkNode | ListNode | NoteNode | ParagraphNode | PillNode | QuoteNode | RedactedNode | RegionNode | ScriptNode | SecretNode | StyleNode | SmallerNode | StickerNode | StrikeThroughNode | TextNode | TableNode | SocialNode | UnderlineNode | VideoNode | DateNode | TimeNode | DateTimeNode | SuperTextNode | SubTextNode | TableOfContentsNode | TimeRangeNode | StandardNode | WarningNode;
|
|
394
|
+
export type Node = AccordionGroupNode | ArrayNode | BadgeNode | BlockNode | BlockQuoteNode | BoldNode | BreakNode | BubbleNode | CardNode | CenterNode | CodeNode | CodeBlockNode | CodeGroupNode | ColumnsNode | DefinitionNode | DefinitionListNode | DefinitionReferenceNode | EmbedNode | EmojiNode | FigureNode | FigureCaptionNode | FigureImageNode | FootnoteNode | FootnoteDisplayNode | FormattedTextNode | HeaderNode | HighTechAlertNode | HorizontalRuleNode | ImageNode | ItalicNode | LinkNode | ListNode | NoteNode | ParagraphNode | PillNode | QuoteNode | RedactedNode | RegionNode | ScriptNode | SecretNode | StyleNode | SmallerNode | StickerNode | StrikeThroughNode | TextNode | TableNode | SocialNode | UnderlineNode | VideoNode | DateNode | TimeNode | DateTimeNode | SuperTextNode | SubTextNode | TableOfContentsNode | TimeRangeNode | StandardNode | WarningNode;
|
|
383
395
|
export interface DocumentMeta {
|
|
384
396
|
hidden?: boolean;
|
|
385
397
|
noindex?: boolean;
|
|
398
|
+
disableHeadingRequirement?: boolean;
|
|
399
|
+
disableToc?: boolean;
|
|
386
400
|
title: string;
|
|
387
401
|
author?: string;
|
|
388
402
|
description?: string;
|