document-ir 0.3.0 → 0.4.1
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.
|
@@ -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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IdentityTransformer } from './IdentityTransformer.ts';
|
|
2
|
-
import { DocumentNode, Node, TextNode } from './types.ts';
|
|
2
|
+
import { CodeNode, DocumentNode, Node, TextNode } from './types.ts';
|
|
3
3
|
interface BlockInfo {
|
|
4
4
|
type: "_block";
|
|
5
5
|
content: WhiteSpaceContainer[];
|
|
@@ -20,6 +20,7 @@ export declare class WhitespaceStretchingTransformer extends IdentityTransformer
|
|
|
20
20
|
protected beforeInline(): Promise<void>;
|
|
21
21
|
protected afterInline(): Promise<void>;
|
|
22
22
|
protected reviewBlock(block: BlockInfo): void;
|
|
23
|
+
protected code(node: CodeNode): Promise<Node | null>;
|
|
23
24
|
protected text(node: TextNode): Promise<Node | null>;
|
|
24
25
|
transform(node: DocumentNode): Promise<DocumentNode>;
|
|
25
26
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { IdentityTransformer } from './IdentityTransformer.ts';
|
|
2
|
-
import { DocumentNode, Node, TextNode } from './types.ts';
|
|
2
|
+
import { CodeNode, DocumentNode, Node, TextNode } from './types.ts';
|
|
3
3
|
export declare class WhitespaceTransformer extends IdentityTransformer {
|
|
4
4
|
private stripWhitespace;
|
|
5
5
|
private lastText;
|
|
6
6
|
constructor();
|
|
7
7
|
protected text(node: TextNode): Promise<Node | null>;
|
|
8
8
|
private stripLastText;
|
|
9
|
+
protected code(node: CodeNode): Promise<Node | null>;
|
|
9
10
|
protected beforeBlock(): Promise<void>;
|
|
10
11
|
protected afterBlock(): Promise<void>;
|
|
11
12
|
transform(node: DocumentNode): Promise<DocumentNode>;
|
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,26 +898,33 @@ 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;
|
|
890
920
|
}
|
|
921
|
+
async code(e) {
|
|
922
|
+
const i = {
|
|
923
|
+
type: "code",
|
|
924
|
+
content: e.content
|
|
925
|
+
};
|
|
926
|
+
return e.diff != null && (i.diff = e.diff), e.lineNumbers != null && (i.lineNumbers = e.lineNumbers), e.id != null && (i.id = e.id), i;
|
|
927
|
+
}
|
|
891
928
|
async beforeBlock() {
|
|
892
929
|
this.stripLastText();
|
|
893
930
|
}
|
|
@@ -896,14 +933,14 @@ class T extends u {
|
|
|
896
933
|
}
|
|
897
934
|
async transform(e) {
|
|
898
935
|
const i = await super.transform(e);
|
|
899
|
-
return await new
|
|
936
|
+
return await new g().transform(i);
|
|
900
937
|
}
|
|
901
938
|
}
|
|
902
939
|
class v extends u {
|
|
903
940
|
constructor() {
|
|
904
941
|
super();
|
|
905
|
-
|
|
906
|
-
|
|
942
|
+
h(this, "root");
|
|
943
|
+
h(this, "cursor");
|
|
907
944
|
this.root = {
|
|
908
945
|
type: "_block",
|
|
909
946
|
content: [],
|
|
@@ -933,25 +970,32 @@ class v extends u {
|
|
|
933
970
|
this.cursor.parent && (this.cursor = this.cursor.parent);
|
|
934
971
|
}
|
|
935
972
|
reviewBlock(e) {
|
|
936
|
-
const i = [],
|
|
937
|
-
if (
|
|
973
|
+
const i = [], s = (r, n) => {
|
|
974
|
+
if (r.type == "text")
|
|
938
975
|
i.push({
|
|
939
|
-
node:
|
|
976
|
+
node: r,
|
|
940
977
|
level: n
|
|
941
978
|
});
|
|
942
|
-
else if (
|
|
943
|
-
this.reviewBlock(
|
|
979
|
+
else if (r.type == "_block")
|
|
980
|
+
this.reviewBlock(r), i.push({ node: null, level: n });
|
|
944
981
|
else
|
|
945
|
-
for (const a of
|
|
946
|
-
|
|
982
|
+
for (const a of r.content)
|
|
983
|
+
s(a, n + 1);
|
|
947
984
|
};
|
|
948
|
-
for (const
|
|
949
|
-
r
|
|
950
|
-
for (let
|
|
951
|
-
const n = i[
|
|
985
|
+
for (const r of e.content)
|
|
986
|
+
s(r, 0);
|
|
987
|
+
for (let r = 0; r < i.length; r++) {
|
|
988
|
+
const n = i[r], a = r + 1 < i.length ? i[r + 1] : { node: null, level: 0 };
|
|
952
989
|
!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
990
|
}
|
|
954
991
|
}
|
|
992
|
+
async code(e) {
|
|
993
|
+
const i = {
|
|
994
|
+
type: "code",
|
|
995
|
+
content: e.content
|
|
996
|
+
};
|
|
997
|
+
return e.diff != null && (i.diff = e.diff), e.lineNumbers != null && (i.lineNumbers = e.lineNumbers), e.id != null && (i.id = e.id), i;
|
|
998
|
+
}
|
|
955
999
|
async text(e) {
|
|
956
1000
|
const i = {
|
|
957
1001
|
type: "text",
|
|
@@ -977,6 +1021,8 @@ class w {
|
|
|
977
1021
|
for (const e of t)
|
|
978
1022
|
this.choose(e);
|
|
979
1023
|
}
|
|
1024
|
+
badge(t) {
|
|
1025
|
+
}
|
|
980
1026
|
block(t) {
|
|
981
1027
|
this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
|
|
982
1028
|
}
|
|
@@ -1027,6 +1073,11 @@ class w {
|
|
|
1027
1073
|
figureImage(t) {
|
|
1028
1074
|
this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
|
|
1029
1075
|
}
|
|
1076
|
+
footnote(t) {
|
|
1077
|
+
this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
|
|
1078
|
+
}
|
|
1079
|
+
footnoteDisplay(t) {
|
|
1080
|
+
}
|
|
1030
1081
|
formattedText(t) {
|
|
1031
1082
|
}
|
|
1032
1083
|
header(t) {
|
|
@@ -1133,6 +1184,8 @@ class w {
|
|
|
1133
1184
|
throw new Error(`Unexpected node, no type: ${JSON.stringify(t)}`);
|
|
1134
1185
|
try {
|
|
1135
1186
|
switch (t.type) {
|
|
1187
|
+
case "badge":
|
|
1188
|
+
return this.badge(t);
|
|
1136
1189
|
case "block":
|
|
1137
1190
|
return this.block(t);
|
|
1138
1191
|
case "block-quote":
|
|
@@ -1167,6 +1220,10 @@ class w {
|
|
|
1167
1220
|
return this.figureCaption(t);
|
|
1168
1221
|
case "figure-image":
|
|
1169
1222
|
return this.figureImage(t);
|
|
1223
|
+
case "footnote":
|
|
1224
|
+
return this.footnote(t);
|
|
1225
|
+
case "footnote-display":
|
|
1226
|
+
return this.footnoteDisplay(t);
|
|
1170
1227
|
case "formatted-text":
|
|
1171
1228
|
return this.formattedText(t);
|
|
1172
1229
|
case "header":
|
|
@@ -1251,10 +1308,10 @@ class w {
|
|
|
1251
1308
|
t.type == "document" ? this.document(t) : this.choose(t);
|
|
1252
1309
|
}
|
|
1253
1310
|
}
|
|
1254
|
-
class
|
|
1311
|
+
class m extends w {
|
|
1255
1312
|
constructor() {
|
|
1256
1313
|
super();
|
|
1257
|
-
|
|
1314
|
+
h(this, "textList");
|
|
1258
1315
|
this.textList = [];
|
|
1259
1316
|
}
|
|
1260
1317
|
text(e) {
|
|
@@ -1394,25 +1451,25 @@ class B extends k {
|
|
|
1394
1451
|
async definitionList(t) {
|
|
1395
1452
|
const e = [];
|
|
1396
1453
|
for (const i of t.content) {
|
|
1397
|
-
const
|
|
1398
|
-
if (
|
|
1399
|
-
for (const a of
|
|
1400
|
-
|
|
1401
|
-
|
|
1454
|
+
const s = [], r = await this.chooseChildren(i.title);
|
|
1455
|
+
if (r)
|
|
1456
|
+
for (const a of r)
|
|
1457
|
+
s.push(a);
|
|
1458
|
+
s.push({ type: "text", text: " " });
|
|
1402
1459
|
const n = await this.chooseChildren(i.abbreviation);
|
|
1403
1460
|
if (n)
|
|
1404
1461
|
for (const a of n)
|
|
1405
|
-
|
|
1462
|
+
s.push(a);
|
|
1406
1463
|
if (i.content.length > 0 && i.content[0].type != "paragraph") {
|
|
1407
|
-
|
|
1464
|
+
s.push({ type: "text", text: " " });
|
|
1408
1465
|
const a = await this.chooseChildren(i.content);
|
|
1409
1466
|
if (a)
|
|
1410
1467
|
for (const o of a)
|
|
1411
|
-
|
|
1468
|
+
s.push(o);
|
|
1412
1469
|
}
|
|
1413
1470
|
if (e.push({
|
|
1414
1471
|
type: "paragraph",
|
|
1415
|
-
content:
|
|
1472
|
+
content: s
|
|
1416
1473
|
}), i.content.length > 0 && i.content[0].type == "paragraph") {
|
|
1417
1474
|
const a = await this.chooseChildren(i.content);
|
|
1418
1475
|
if (a)
|
|
@@ -1451,20 +1508,20 @@ class B extends k {
|
|
|
1451
1508
|
}
|
|
1452
1509
|
if (t.content) {
|
|
1453
1510
|
const i = await this.chooseChildren(t.content.content);
|
|
1454
|
-
for (const
|
|
1455
|
-
e.push(
|
|
1511
|
+
for (const s of i)
|
|
1512
|
+
e.push(s);
|
|
1456
1513
|
}
|
|
1457
1514
|
if (t.media)
|
|
1458
1515
|
for (const i of t.media.content) {
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1516
|
+
const s = await this.choose(i);
|
|
1517
|
+
s && e.push(s);
|
|
1461
1518
|
}
|
|
1462
1519
|
if (t.attribution) {
|
|
1463
1520
|
const i = [];
|
|
1464
1521
|
if (t.attribution.title) {
|
|
1465
|
-
const
|
|
1466
|
-
for (const
|
|
1467
|
-
e.push(
|
|
1522
|
+
const s = await this.chooseChildren(t.attribution.title);
|
|
1523
|
+
for (const r of s)
|
|
1524
|
+
e.push(r);
|
|
1468
1525
|
}
|
|
1469
1526
|
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
1527
|
type: "paragraph",
|
|
@@ -1480,8 +1537,8 @@ class B extends k {
|
|
|
1480
1537
|
class C extends w {
|
|
1481
1538
|
constructor() {
|
|
1482
1539
|
super();
|
|
1483
|
-
|
|
1484
|
-
|
|
1540
|
+
h(this, "count");
|
|
1541
|
+
h(this, "texts");
|
|
1485
1542
|
this.count = 0, this.texts = [];
|
|
1486
1543
|
}
|
|
1487
1544
|
countText() {
|
|
@@ -1515,8 +1572,8 @@ function b(c) {
|
|
|
1515
1572
|
e.visit(i);
|
|
1516
1573
|
t.words = e.getCount(), t.totalWords = t.words;
|
|
1517
1574
|
for (const i of c.children) {
|
|
1518
|
-
const
|
|
1519
|
-
t.children.push(
|
|
1575
|
+
const s = b(i);
|
|
1576
|
+
t.children.push(s), t.totalWords += s.totalWords;
|
|
1520
1577
|
}
|
|
1521
1578
|
return t;
|
|
1522
1579
|
}
|
|
@@ -1525,37 +1582,37 @@ class N extends u {
|
|
|
1525
1582
|
super();
|
|
1526
1583
|
}
|
|
1527
1584
|
async transform(t) {
|
|
1528
|
-
const e = JSON.parse(JSON.stringify(t)), i = await new B().transform(e),
|
|
1585
|
+
const e = JSON.parse(JSON.stringify(t)), i = await new B().transform(e), s = [], r = {
|
|
1529
1586
|
header: t.title,
|
|
1530
1587
|
headerId: "title",
|
|
1531
1588
|
nodes: [],
|
|
1532
1589
|
children: [],
|
|
1533
1590
|
depth: 1
|
|
1534
1591
|
};
|
|
1535
|
-
|
|
1592
|
+
s.push(r);
|
|
1536
1593
|
let n = 1;
|
|
1537
1594
|
for (const o of i.content)
|
|
1538
1595
|
if (o.type == "header") {
|
|
1539
1596
|
if (o.level == 1)
|
|
1540
1597
|
continue;
|
|
1541
1598
|
if (o.level <= n)
|
|
1542
|
-
for (let p =
|
|
1543
|
-
|
|
1544
|
-
const
|
|
1545
|
-
|
|
1599
|
+
for (let p = s.length - 1; p > 0; p--)
|
|
1600
|
+
s[p].depth >= o.level && s.pop();
|
|
1601
|
+
const l = new m();
|
|
1602
|
+
l.visit(o);
|
|
1546
1603
|
const f = {
|
|
1547
|
-
header:
|
|
1604
|
+
header: l.getText(),
|
|
1548
1605
|
depth: o.level,
|
|
1549
1606
|
children: [],
|
|
1550
1607
|
nodes: []
|
|
1551
1608
|
};
|
|
1552
|
-
o.htmlId && (f.headerId = o.htmlId),
|
|
1609
|
+
o.htmlId && (f.headerId = o.htmlId), s[s.length - 1].children.push(f), s.push(f), n = o.level;
|
|
1553
1610
|
} else
|
|
1554
|
-
|
|
1611
|
+
s[s.length - 1].nodes.push(o);
|
|
1555
1612
|
const a = {
|
|
1556
1613
|
...t
|
|
1557
1614
|
};
|
|
1558
|
-
return a.hierarchy = b(
|
|
1615
|
+
return a.hierarchy = b(r), a;
|
|
1559
1616
|
}
|
|
1560
1617
|
}
|
|
1561
1618
|
export {
|
|
@@ -1564,7 +1621,7 @@ export {
|
|
|
1564
1621
|
u as IdentityTransformer,
|
|
1565
1622
|
w as NodeVisitor,
|
|
1566
1623
|
I as TextCollapseTransformer,
|
|
1567
|
-
|
|
1624
|
+
m as TextVisitor,
|
|
1568
1625
|
v as WhitespaceStretchingTransformer,
|
|
1569
1626
|
T as WhitespaceTransformer,
|
|
1570
1627
|
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;
|