document-ir 0.2.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.
@@ -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 { 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>;
@@ -12,6 +13,11 @@ export declare class IdentityTransformer {
12
13
  protected bubble(node: BubbleNode): Promise<Node | null>;
13
14
  protected center(node: CenterNode): Promise<Node | null>;
14
15
  protected code(node: CodeNode): Promise<Node | null>;
16
+ protected codeBlock(node: CodeBlockNode): Promise<Node | null>;
17
+ protected accordionTab(node: AccordionTabNode): Promise<AccordionTabNode>;
18
+ protected accordionGroup(node: AccordionGroupNode): Promise<Node | null>;
19
+ protected codeGroupTab(node: CodeGroupTabNode): Promise<CodeGroupTabNode>;
20
+ protected codeGroup(node: CodeGroupNode): Promise<Node | null>;
15
21
  protected columns(node: ColumnsNode): Promise<Node | null>;
16
22
  protected definition(node: DefinitionNode): Promise<DefinitionNode | null>;
17
23
  protected definitionList(node: DefinitionListNode): Promise<Node | null>;
@@ -21,6 +27,8 @@ export declare class IdentityTransformer {
21
27
  protected figure(node: FigureNode): Promise<Node | null>;
22
28
  protected figureCaption(node: FigureCaptionNode): Promise<Node | null>;
23
29
  protected figureImage(node: FigureImageNode): Promise<Node | null>;
30
+ protected footnote(node: FootnoteNode): Promise<Node | null>;
31
+ protected footnoteDisplay(node: FootnoteDisplayNode): Promise<Node | null>;
24
32
  protected formattedText(node: FormattedTextNode): Promise<Node | null>;
25
33
  protected header(node: HeaderNode): Promise<Node | null>;
26
34
  protected highTechAlert(node: HighTechAlertNode): Promise<Node | null>;
@@ -32,10 +40,12 @@ export declare class IdentityTransformer {
32
40
  protected note(node: NoteNode): Promise<Node | null>;
33
41
  protected list(node: ListNode): Promise<Node | null>;
34
42
  protected paragraph(node: ParagraphNode): Promise<Node | null>;
43
+ protected pill(node: PillNode): Promise<Node | null>;
35
44
  protected quote(node: QuoteNode): Promise<Node | null>;
36
45
  protected redacted(node: RedactedNode): Promise<Node | null>;
37
46
  protected region(node: RegionNode): Promise<Node | null>;
38
47
  protected script(node: ScriptNode): Promise<Node | null>;
48
+ protected style(node: StyleNode): Promise<Node | null>;
39
49
  protected secret(node: SecretNode): Promise<Node | null>;
40
50
  protected smaller(node: SmallerNode): Promise<Node | null>;
41
51
  protected sticker(node: StickerNode): Promise<Node | null>;
@@ -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
- var b = Object.defineProperty;
2
- var y = (c, t, e) => t in c ? b(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
3
- var l = (c, t, e) => y(c, typeof t != "symbol" ? t + "" : t, e);
1
+ var d = Object.defineProperty;
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 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 r = await this.choose(i);
17
- r && e.push(r);
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);
@@ -84,12 +92,64 @@ class u {
84
92
  type: "code",
85
93
  content: e
86
94
  };
95
+ return t.diff != null && (i.diff = t.diff), t.lineNumbers != null && (i.lineNumbers = t.lineNumbers), t.id != null && (i.id = t.id), i;
96
+ }
97
+ async codeBlock(t) {
98
+ const i = {
99
+ type: "code-block",
100
+ content: await this.code(t.content),
101
+ fileName: t.fileName
102
+ };
103
+ return t.copyable != null && (i.copyable = t.copyable), t.collapsable != null && (i.collapsable = t.collapsable), t.collapsed != null && (i.collapsed = t.collapsed), t.id != null && (i.id = t.id), i;
104
+ }
105
+ async accordionTab(t) {
106
+ await this.beforeInline();
107
+ const e = await this.chooseChildren(t.header);
108
+ await this.afterInline(), await this.beforeBlock();
109
+ const i = await this.chooseChildren(t.content);
110
+ await this.afterBlock();
111
+ const s = {
112
+ type: "accordion-tab",
113
+ header: e,
114
+ content: i
115
+ };
116
+ return t.open != null && (s.open = t.open), t.id != null && (s.id = t.id), s;
117
+ }
118
+ async accordionGroup(t) {
119
+ const e = [];
120
+ for (const s of t.tabs)
121
+ e.push(await this.accordionTab(s));
122
+ const i = {
123
+ type: "accordion-group",
124
+ tabs: e
125
+ };
126
+ return t.id != null && (i.id = t.id), i;
127
+ }
128
+ async codeGroupTab(t) {
129
+ await this.beforeInline();
130
+ const e = await this.chooseChildren(t.header);
131
+ await this.afterInline();
132
+ const i = await this.code(t.content), s = {
133
+ type: "code-group-tab",
134
+ header: e,
135
+ content: i
136
+ };
137
+ return t.copyable != null && (s.copyable = t.copyable), t.id != null && (s.id = t.id), s;
138
+ }
139
+ async codeGroup(t) {
140
+ const e = [];
141
+ for (const s of t.tabs)
142
+ e.push(await this.codeGroupTab(s));
143
+ const i = {
144
+ type: "code-group",
145
+ tabs: e
146
+ };
87
147
  return t.id != null && (i.id = t.id), i;
88
148
  }
89
149
  async columns(t) {
90
150
  const e = [];
91
- for (const r of t.columns)
92
- await this.beforeBlock(), e.push(await this.chooseChildren(r)), await this.afterBlock();
151
+ for (const s of t.columns)
152
+ await this.beforeBlock(), e.push(await this.chooseChildren(s)), await this.afterBlock();
93
153
  const i = {
94
154
  type: "columns",
95
155
  columns: e,
@@ -103,23 +163,23 @@ class u {
103
163
  await this.afterBlock(), await this.beforeBlock();
104
164
  const i = await this.chooseChildren(t.title);
105
165
  await this.afterBlock(), await this.beforeBlock();
106
- const r = await this.chooseChildren(t.content);
166
+ const s = await this.chooseChildren(t.content);
107
167
  await this.afterBlock();
108
- const s = {
168
+ const r = {
109
169
  type: "definition",
110
170
  abbreviation: e,
111
171
  title: i,
112
- content: r,
172
+ content: s,
113
173
  key: t.key
114
174
  };
115
- return t.id != null && (s.id = t.id), s;
175
+ return t.id != null && (r.id = t.id), r;
116
176
  }
117
177
  async definitionList(t) {
118
178
  await this.beforeBlock();
119
179
  const e = [];
120
- for (const r of t.content) {
121
- const s = await this.definition(r);
122
- s && e.push(s);
180
+ for (const s of t.content) {
181
+ const r = await this.definition(s);
182
+ r && e.push(r);
123
183
  }
124
184
  await this.afterBlock();
125
185
  const i = {
@@ -193,6 +253,22 @@ class u {
193
253
  };
194
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;
195
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
+ }
196
272
  async formattedText(t) {
197
273
  await this.beforeBlock(), await this.afterBlock();
198
274
  const e = {
@@ -219,12 +295,12 @@ class u {
219
295
  await this.afterBlock(), await this.beforeBlock();
220
296
  const i = await this.chooseChildren(t.warning);
221
297
  await this.afterBlock();
222
- const r = {
298
+ const s = {
223
299
  type: "high-tech-alert",
224
300
  content: e,
225
301
  warning: i
226
302
  };
227
- return t.id != null && (r.id = t.id), r;
303
+ return t.id != null && (s.id = t.id), s;
228
304
  }
229
305
  async horizontalRule(t) {
230
306
  await this.beforeBlock(), await this.afterBlock();
@@ -282,15 +358,15 @@ class u {
282
358
  }
283
359
  async list(t) {
284
360
  const e = [];
285
- for (const r of t.content) {
361
+ for (const s of t.content) {
286
362
  await this.beforeBlock();
287
- const s = await this.chooseChildren(r.content);
288
- if (await this.afterBlock(), s && s.length > 0) {
289
- const a = {
363
+ const r = await this.chooseChildren(s.content);
364
+ if (await this.afterBlock(), r && r.length > 0) {
365
+ const n = {
290
366
  type: "list-item",
291
- content: s
367
+ content: r
292
368
  };
293
- r.id != null && (a.id = r.id), e.push(a);
369
+ s.id != null && (n.id = s.id), e.push(n);
294
370
  }
295
371
  }
296
372
  const i = {
@@ -310,6 +386,17 @@ class u {
310
386
  };
311
387
  return t.id != null && (i.id = t.id), i;
312
388
  }
389
+ async pill(t) {
390
+ await this.beforeInline();
391
+ const e = await this.chooseChildren(t.content);
392
+ await this.afterInline();
393
+ const i = {
394
+ type: "pill",
395
+ color: t.color,
396
+ content: e
397
+ };
398
+ return t.id != null && (i.id = t.id), i;
399
+ }
313
400
  async quote(t) {
314
401
  await this.beforeBlock();
315
402
  const e = await this.chooseChildren(t.content);
@@ -352,7 +439,13 @@ class u {
352
439
  "mime-type": t["mime-type"] || "text/javascript",
353
440
  source: t.source
354
441
  };
355
- return t.id != null && (e.id = t.id), e;
442
+ return t.url && (e.url = t.url), t.id != null && (e.id = t.id), e;
443
+ }
444
+ async style(t) {
445
+ const e = {
446
+ type: "style"
447
+ };
448
+ return t.source && (e.source = t.source), t.url && (e.url = t.url), t.id != null && (e.id = t.id), e;
356
449
  }
357
450
  async secret(t) {
358
451
  await this.beforeInline();
@@ -419,21 +512,21 @@ class u {
419
512
  }
420
513
  async table(t) {
421
514
  const e = [];
422
- for (const r of t.content) {
423
- const s = [];
424
- let a = 0;
425
- for (const n of r) {
515
+ for (const s of t.content) {
516
+ const r = [];
517
+ let n = 0;
518
+ for (const a of s) {
426
519
  await this.beforeBlock();
427
- const o = await this.chooseChildren(n.content);
428
- await this.afterBlock(), o && o.length == 0 && a++;
429
- const h = {
520
+ const o = await this.chooseChildren(a.content);
521
+ await this.afterBlock(), o && o.length == 0 && n++;
522
+ const l = {
430
523
  type: "table-cell",
431
- span: [n.span[0] || 1, n.span[1] || 1],
524
+ span: [a.span[0] || 1, a.span[1] || 1],
432
525
  content: o
433
526
  };
434
- n.id != null && (h.id = n.id), n.header && (h.header = n.header), s.push(h);
527
+ a.id != null && (l.id = a.id), a.header && (l.header = a.header), r.push(l);
435
528
  }
436
- s.length > 0 && a != s.length && e.push(s);
529
+ r.length > 0 && n != r.length && e.push(r);
437
530
  }
438
531
  const i = {
439
532
  type: "table",
@@ -483,10 +576,10 @@ class u {
483
576
  let e;
484
577
  if (t.content) {
485
578
  await this.beforeBlock();
486
- const n = await this.chooseChildren(t.content.content);
487
- n && n.length > 0 && (e = {
579
+ const a = await this.chooseChildren(t.content.content);
580
+ a && a.length > 0 && (e = {
488
581
  type: "card-content",
489
- content: n
582
+ content: a
490
583
  }, t.content.id != null && (e.id = t.content.id)), await this.afterBlock();
491
584
  }
492
585
  let i;
@@ -494,45 +587,45 @@ class u {
494
587
  type: "card-attribution"
495
588
  }, t.attribution.id != null && (i.id = t.attribution.id), t.attribution.archiveUrl && (i.archiveUrl = t.attribution.archiveUrl), t.attribution.url && (i.url = t.attribution.url), t.attribution.date && (i.date = t.attribution.date), t.attribution.title)) {
496
589
  await this.beforeBlock();
497
- const n = await this.chooseChildren(t.attribution.title);
498
- await this.afterBlock(), i.title = n;
590
+ const a = await this.chooseChildren(t.attribution.title);
591
+ await this.afterBlock(), i.title = a;
499
592
  }
500
- let r;
593
+ let s;
501
594
  if (t.header) {
502
595
  await this.beforeBlock();
503
- const n = await this.chooseChildren(t.header.title);
504
- await this.afterBlock(), r = {
596
+ const a = await this.chooseChildren(t.header.title);
597
+ await this.afterBlock(), s = {
505
598
  type: "card-header",
506
- title: n,
599
+ title: a,
507
600
  backgroundBlurhash: t.header.backgroundBlurhash,
508
601
  backgroundColor: t.header.backgroundColor,
509
602
  backgroundImage: t.header.backgroundImage,
510
603
  imageUrl: t.header.imageUrl,
511
604
  imageBlurhash: t.header.imageBlurhash
512
- }, t.header.id != null && (r.id = t.header.id), t.header.url && (r.url = t.header.url), t.header.username && (r.username = t.header.username), t.header.usernameDomain && (r.usernameDomain = t.header.usernameDomain);
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);
513
606
  }
514
- let s;
607
+ let r;
515
608
  if (t.media) {
516
- const n = [];
609
+ const a = [];
517
610
  for (const o of t.media.content) {
518
611
  await this.beforeBlock();
519
- const h = await this.choose(o);
520
- h && (h.type == "image" || h.type == "video" || h.type == "embed") && n.push(h), await this.afterBlock();
612
+ const l = await this.choose(o);
613
+ l && (l.type == "image" || l.type == "video" || l.type == "embed") && a.push(l), await this.afterBlock();
521
614
  }
522
- n.length > 0 && (s = {
615
+ a.length > 0 && (r = {
523
616
  type: "card-media",
524
- content: n
525
- }, t.media.id != null && (s.id = t.media.id));
617
+ content: a
618
+ }, t.media.id != null && (r.id = t.media.id));
526
619
  }
527
- const a = {
620
+ const n = {
528
621
  type: "card",
529
622
  content: e,
530
623
  attribution: i,
531
- header: r,
532
- media: s,
624
+ header: s,
625
+ media: r,
533
626
  original: t.original
534
627
  };
535
- return t.id != null && (a.id = t.id), a;
628
+ return t.id != null && (n.id = t.id), n;
536
629
  }
537
630
  async date(t) {
538
631
  await this.beforeInline();
@@ -591,16 +684,16 @@ class u {
591
684
  await this.beforeBlock();
592
685
  const e = await this.chooseChildren(t.content), i = t.date && await this.choose(t.date);
593
686
  await this.afterBlock(), await this.beforeBlock();
594
- const r = await this.chooseChildren(t.children);
687
+ const s = await this.chooseChildren(t.children);
595
688
  await this.afterBlock();
596
- const s = r.filter(
597
- (n) => n.type == "toc"
598
- ), a = {
689
+ const r = s.filter(
690
+ (a) => a.type == "toc"
691
+ ), n = {
599
692
  type: "toc",
600
693
  content: e,
601
- children: s
694
+ children: r
602
695
  };
603
- return t.id != null && (a.id = t.id), i && (i.type == "date" || i.type == "time" || i.type == "datetime") && (a.date = i), t.href && (a.href = t.href), t.hrefHtmlId && (a.hrefHtmlId = t.hrefHtmlId), a;
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;
604
697
  }
605
698
  async timeRange(t) {
606
699
  await this.beforeBlock();
@@ -617,6 +710,8 @@ class u {
617
710
  throw new Error(`Unexpected node, no type: ${JSON.stringify(t)}`);
618
711
  try {
619
712
  switch (t.type) {
713
+ case "badge":
714
+ return await this.badge(t);
620
715
  case "block":
621
716
  return await this.block(t);
622
717
  case "block-quote":
@@ -633,6 +728,10 @@ class u {
633
728
  return await this.center(t);
634
729
  case "code":
635
730
  return await this.code(t);
731
+ case "code-block":
732
+ return await this.codeBlock(t);
733
+ case "code-group":
734
+ return await this.codeGroup(t);
636
735
  case "columns":
637
736
  return await this.columns(t);
638
737
  case "definition":
@@ -651,6 +750,10 @@ class u {
651
750
  return await this.figureCaption(t);
652
751
  case "figure-image":
653
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);
654
757
  case "formatted-text":
655
758
  return await this.formattedText(t);
656
759
  case "header":
@@ -665,6 +768,8 @@ class u {
665
768
  return await this.italic(t);
666
769
  case "link":
667
770
  return await this.link(t);
771
+ case "accordion-group":
772
+ return await this.accordionGroup(t);
668
773
  case "array":
669
774
  return await this.array(t);
670
775
  case "note":
@@ -673,6 +778,8 @@ class u {
673
778
  return await this.list(t);
674
779
  case "paragraph":
675
780
  return await this.paragraph(t);
781
+ case "pill":
782
+ return await this.pill(t);
676
783
  case "quote":
677
784
  return await this.quote(t);
678
785
  case "redacted":
@@ -683,6 +790,8 @@ class u {
683
790
  return await this.script(t);
684
791
  case "secret":
685
792
  return await this.secret(t);
793
+ case "style":
794
+ return await this.style(t);
686
795
  case "smaller":
687
796
  return await this.smaller(t);
688
797
  case "sticker":
@@ -733,16 +842,16 @@ class u {
733
842
  const e = await this.chooseChildren(t.content);
734
843
  await this.afterBlock(), await this.beforeBlock();
735
844
  const i = t.definitions && (await this.chooseChildren(t.definitions)).filter(
736
- (a) => a.type == "definition"
737
- ), r = t.hierarchy;
845
+ (n) => n.type == "definition"
846
+ ), s = t.hierarchy;
738
847
  await this.afterBlock();
739
- const s = {
848
+ const r = {
740
849
  type: "document",
741
850
  title: t.title,
742
851
  content: e,
743
852
  url: t.url
744
853
  };
745
- return t.image && (s.image = t.image), t.guid && (s.guid = t.guid), t["pub-date"] && (s["pub-date"] = t["pub-date"]), t.description && (s.description = t.description), t.date && (s.date = t.date), r && (s.hierarchy = r), i && (s.definitions = i), t.noindex && (s.noindex = t.noindex), t.author && (s.author = t.author), t.hidden && (s.hidden = t.hidden), t.readingDifficultyMultiplier && (s.readingDifficultyMultiplier = t.readingDifficultyMultiplier), t.contentDigest && (s.contentDigest = t.contentDigest), s;
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;
746
855
  }
747
856
  async transform(t) {
748
857
  return await this.document(t);
@@ -751,37 +860,37 @@ class u {
751
860
  class k extends u {
752
861
  async chooseChildren(t) {
753
862
  const e = await super.chooseChildren(t), i = [];
754
- for (const r of e)
755
- if (r.type == "array")
756
- for (const s of r.content)
757
- i.push(s);
863
+ for (const s of e)
864
+ if (s.type == "array")
865
+ for (const r of s.content)
866
+ i.push(r);
758
867
  else
759
- i.push(r);
868
+ i.push(s);
760
869
  return i;
761
870
  }
762
871
  }
763
872
  class I extends u {
764
873
  async chooseChildren(t) {
765
874
  const e = await super.chooseChildren(t), i = [];
766
- let r = null, s;
767
- for (const a of e)
768
- if (a.type == "text")
769
- r != null ? r = `${r}${a.text}` : (r = a.text, s = a.id);
875
+ let s = null, r;
876
+ for (const n of e)
877
+ if (n.type == "text")
878
+ s != null ? s = `${s}${n.text}` : (s = n.text, r = n.id);
770
879
  else {
771
- if (r != null) {
772
- const n = { type: "text", text: r };
773
- s != null && (n.id = s), i.push(n), r = null, s = void 0;
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;
774
883
  }
775
- i.push(a);
884
+ i.push(n);
776
885
  }
777
- if (r != null) {
778
- const a = { type: "text", text: r };
779
- s != null && (a.id = s), i.push(a);
886
+ if (s != null) {
887
+ const n = { type: "text", text: s };
888
+ r != null && (n.id = r), i.push(n);
780
889
  }
781
890
  return i;
782
891
  }
783
892
  }
784
- class m extends u {
893
+ class g extends u {
785
894
  async text(t) {
786
895
  return t.text == "" ? null : t;
787
896
  }
@@ -789,22 +898,22 @@ class m extends u {
789
898
  class T extends u {
790
899
  constructor() {
791
900
  super();
792
- l(this, "stripWhitespace");
793
- l(this, "lastText");
901
+ h(this, "stripWhitespace");
902
+ h(this, "lastText");
794
903
  this.stripWhitespace = !0, this.lastText = null;
795
904
  }
796
905
  async text(e) {
797
906
  let i = "";
798
- for (const s of e.text)
799
- s == " " || s == `
800
- ` || s == " " || s == "\r" ? this.stripWhitespace || (i += " ", this.stripWhitespace = !0) : (i += s, this.stripWhitespace = !1);
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);
801
910
  if (i.length == 0)
802
911
  return null;
803
- const r = {
912
+ const s = {
804
913
  type: "text",
805
914
  text: i
806
915
  };
807
- return e.id != null && (r.id = e.id), this.lastText = r, r;
916
+ return e.id != null && (s.id = e.id), this.lastText = s, s;
808
917
  }
809
918
  stripLastText() {
810
919
  this.lastText && (this.lastText.text.endsWith(" ") && (this.lastText.text = this.lastText.text.slice(0, -1)), this.lastText = null), this.stripWhitespace = !0;
@@ -817,14 +926,14 @@ class T extends u {
817
926
  }
818
927
  async transform(e) {
819
928
  const i = await super.transform(e);
820
- return await new m().transform(i);
929
+ return await new g().transform(i);
821
930
  }
822
931
  }
823
932
  class v extends u {
824
933
  constructor() {
825
934
  super();
826
- l(this, "root");
827
- l(this, "cursor");
935
+ h(this, "root");
936
+ h(this, "cursor");
828
937
  this.root = {
829
938
  type: "_block",
830
939
  content: [],
@@ -854,23 +963,23 @@ class v extends u {
854
963
  this.cursor.parent && (this.cursor = this.cursor.parent);
855
964
  }
856
965
  reviewBlock(e) {
857
- const i = [], r = (s, a) => {
858
- if (s.type == "text")
966
+ const i = [], s = (r, n) => {
967
+ if (r.type == "text")
859
968
  i.push({
860
- node: s,
861
- level: a
969
+ node: r,
970
+ level: n
862
971
  });
863
- else if (s.type == "_block")
864
- this.reviewBlock(s), i.push({ node: null, level: a });
972
+ else if (r.type == "_block")
973
+ this.reviewBlock(r), i.push({ node: null, level: n });
865
974
  else
866
- for (const n of s.content)
867
- r(n, a + 1);
868
- };
869
- for (const s of e.content)
870
- r(s, 0);
871
- for (let s = 0; s < i.length; s++) {
872
- const a = i[s], n = s + 1 < i.length ? i[s + 1] : { node: null, level: 0 };
873
- !a.node || !n.node || a.level != n.level && (a.level < n.level ? n.node.text.startsWith(" ") && (n.node.text = n.node.text.slice(1), a.node.text += " ") : a.level > n.level && a.node.text.endsWith(" ") && (a.node.text = a.node.text.slice(0, -1), n.node.text = ` ${n.node.text}`));
975
+ for (const a of r.content)
976
+ s(a, n + 1);
977
+ };
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 };
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}`));
874
983
  }
875
984
  }
876
985
  async text(e) {
@@ -898,6 +1007,8 @@ class w {
898
1007
  for (const e of t)
899
1008
  this.choose(e);
900
1009
  }
1010
+ badge(t) {
1011
+ }
901
1012
  block(t) {
902
1013
  this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
903
1014
  }
@@ -948,6 +1059,11 @@ class w {
948
1059
  figureImage(t) {
949
1060
  this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
950
1061
  }
1062
+ footnote(t) {
1063
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1064
+ }
1065
+ footnoteDisplay(t) {
1066
+ }
951
1067
  formattedText(t) {
952
1068
  }
953
1069
  header(t) {
@@ -1054,6 +1170,8 @@ class w {
1054
1170
  throw new Error(`Unexpected node, no type: ${JSON.stringify(t)}`);
1055
1171
  try {
1056
1172
  switch (t.type) {
1173
+ case "badge":
1174
+ return this.badge(t);
1057
1175
  case "block":
1058
1176
  return this.block(t);
1059
1177
  case "block-quote":
@@ -1088,6 +1206,10 @@ class w {
1088
1206
  return this.figureCaption(t);
1089
1207
  case "figure-image":
1090
1208
  return this.figureImage(t);
1209
+ case "footnote":
1210
+ return this.footnote(t);
1211
+ case "footnote-display":
1212
+ return this.footnoteDisplay(t);
1091
1213
  case "formatted-text":
1092
1214
  return this.formattedText(t);
1093
1215
  case "header":
@@ -1172,10 +1294,10 @@ class w {
1172
1294
  t.type == "document" ? this.document(t) : this.choose(t);
1173
1295
  }
1174
1296
  }
1175
- class g extends w {
1297
+ class m extends w {
1176
1298
  constructor() {
1177
1299
  super();
1178
- l(this, "textList");
1300
+ h(this, "textList");
1179
1301
  this.textList = [];
1180
1302
  }
1181
1303
  text(e) {
@@ -1315,29 +1437,29 @@ class B extends k {
1315
1437
  async definitionList(t) {
1316
1438
  const e = [];
1317
1439
  for (const i of t.content) {
1318
- const r = [], s = await this.chooseChildren(i.title);
1319
- if (s)
1320
- for (const n of s)
1321
- r.push(n);
1322
- r.push({ type: "text", text: " " });
1323
- const a = await this.chooseChildren(i.abbreviation);
1324
- if (a)
1325
- for (const n of a)
1326
- r.push(n);
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: " " });
1445
+ const n = await this.chooseChildren(i.abbreviation);
1446
+ if (n)
1447
+ for (const a of n)
1448
+ s.push(a);
1327
1449
  if (i.content.length > 0 && i.content[0].type != "paragraph") {
1328
- r.push({ type: "text", text: " " });
1329
- const n = await this.chooseChildren(i.content);
1330
- if (n)
1331
- for (const o of n)
1332
- r.push(o);
1450
+ s.push({ type: "text", text: " " });
1451
+ const a = await this.chooseChildren(i.content);
1452
+ if (a)
1453
+ for (const o of a)
1454
+ s.push(o);
1333
1455
  }
1334
1456
  if (e.push({
1335
1457
  type: "paragraph",
1336
- content: r
1458
+ content: s
1337
1459
  }), i.content.length > 0 && i.content[0].type == "paragraph") {
1338
- const n = await this.chooseChildren(i.content);
1339
- if (n)
1340
- for (const o of n)
1460
+ const a = await this.chooseChildren(i.content);
1461
+ if (a)
1462
+ for (const o of a)
1341
1463
  e.push(o);
1342
1464
  }
1343
1465
  }
@@ -1372,20 +1494,20 @@ class B extends k {
1372
1494
  }
1373
1495
  if (t.content) {
1374
1496
  const i = await this.chooseChildren(t.content.content);
1375
- for (const r of i)
1376
- e.push(r);
1497
+ for (const s of i)
1498
+ e.push(s);
1377
1499
  }
1378
1500
  if (t.media)
1379
1501
  for (const i of t.media.content) {
1380
- const r = await this.choose(i);
1381
- r && e.push(r);
1502
+ const s = await this.choose(i);
1503
+ s && e.push(s);
1382
1504
  }
1383
1505
  if (t.attribution) {
1384
1506
  const i = [];
1385
1507
  if (t.attribution.title) {
1386
- const r = await this.chooseChildren(t.attribution.title);
1387
- for (const s of r)
1388
- e.push(s);
1508
+ const s = await this.chooseChildren(t.attribution.title);
1509
+ for (const r of s)
1510
+ e.push(r);
1389
1511
  }
1390
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({
1391
1513
  type: "paragraph",
@@ -1398,11 +1520,11 @@ class B extends k {
1398
1520
  };
1399
1521
  }
1400
1522
  }
1401
- class x extends w {
1523
+ class C extends w {
1402
1524
  constructor() {
1403
1525
  super();
1404
- l(this, "count");
1405
- l(this, "texts");
1526
+ h(this, "count");
1527
+ h(this, "texts");
1406
1528
  this.count = 0, this.texts = [];
1407
1529
  }
1408
1530
  countText() {
@@ -1424,59 +1546,59 @@ class x extends w {
1424
1546
  return this.countText(), this.count;
1425
1547
  }
1426
1548
  }
1427
- function d(c) {
1549
+ function b(c) {
1428
1550
  const t = {
1429
1551
  headerText: c.header,
1430
1552
  headerId: c.headerId,
1431
1553
  words: 0,
1432
1554
  totalWords: 0,
1433
1555
  children: []
1434
- }, e = new x();
1556
+ }, e = new C();
1435
1557
  for (const i of c.nodes)
1436
1558
  e.visit(i);
1437
1559
  t.words = e.getCount(), t.totalWords = t.words;
1438
1560
  for (const i of c.children) {
1439
- const r = d(i);
1440
- t.children.push(r), t.totalWords += r.totalWords;
1561
+ const s = b(i);
1562
+ t.children.push(s), t.totalWords += s.totalWords;
1441
1563
  }
1442
1564
  return t;
1443
1565
  }
1444
- class L extends u {
1566
+ class N extends u {
1445
1567
  constructor() {
1446
1568
  super();
1447
1569
  }
1448
1570
  async transform(t) {
1449
- const e = JSON.parse(JSON.stringify(t)), i = await new B().transform(e), r = [], s = {
1571
+ const e = JSON.parse(JSON.stringify(t)), i = await new B().transform(e), s = [], r = {
1450
1572
  header: t.title,
1451
1573
  headerId: "title",
1452
1574
  nodes: [],
1453
1575
  children: [],
1454
1576
  depth: 1
1455
1577
  };
1456
- r.push(s);
1457
- let a = 1;
1578
+ s.push(r);
1579
+ let n = 1;
1458
1580
  for (const o of i.content)
1459
1581
  if (o.type == "header") {
1460
1582
  if (o.level == 1)
1461
1583
  continue;
1462
- if (o.level <= a)
1463
- for (let p = r.length - 1; p > 0; p--)
1464
- r[p].depth >= o.level && r.pop();
1465
- const h = new g();
1466
- h.visit(o);
1584
+ if (o.level <= n)
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);
1467
1589
  const f = {
1468
- header: h.getText(),
1590
+ header: l.getText(),
1469
1591
  depth: o.level,
1470
1592
  children: [],
1471
1593
  nodes: []
1472
1594
  };
1473
- o.htmlId && (f.headerId = o.htmlId), r[r.length - 1].children.push(f), r.push(f), a = o.level;
1595
+ o.htmlId && (f.headerId = o.htmlId), s[s.length - 1].children.push(f), s.push(f), n = o.level;
1474
1596
  } else
1475
- r[r.length - 1].nodes.push(o);
1476
- const n = {
1597
+ s[s.length - 1].nodes.push(o);
1598
+ const a = {
1477
1599
  ...t
1478
1600
  };
1479
- return n.hierarchy = d(s), n;
1601
+ return a.hierarchy = b(r), a;
1480
1602
  }
1481
1603
  }
1482
1604
  export {
@@ -1485,9 +1607,9 @@ export {
1485
1607
  u as IdentityTransformer,
1486
1608
  w as NodeVisitor,
1487
1609
  I as TextCollapseTransformer,
1488
- g as TextVisitor,
1610
+ m as TextVisitor,
1489
1611
  v as WhitespaceStretchingTransformer,
1490
1612
  T as WhitespaceTransformer,
1491
- L as WordCounterTransformer,
1492
- x as WordCounterVisitor
1613
+ N as WordCounterTransformer,
1614
+ C as WordCounterVisitor
1493
1615
  };
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[];
@@ -32,6 +37,36 @@ export interface CenterNode extends NodeIdentity {
32
37
  export interface CodeNode extends NodeIdentity {
33
38
  type: "code";
34
39
  content: Node[];
40
+ diff?: boolean;
41
+ lineNumbers?: boolean;
42
+ }
43
+ export interface CodeBlockNode extends NodeIdentity {
44
+ type: "code-block";
45
+ content: CodeNode;
46
+ fileName: string;
47
+ copyable?: boolean;
48
+ collapsable?: boolean;
49
+ collapsed?: boolean;
50
+ }
51
+ export interface CodeGroupTabNode extends NodeIdentity {
52
+ type: "code-group-tab";
53
+ header: Node[];
54
+ content: CodeNode;
55
+ copyable?: boolean;
56
+ }
57
+ export interface CodeGroupNode extends NodeIdentity {
58
+ type: "code-group";
59
+ tabs: CodeGroupTabNode[];
60
+ }
61
+ export interface AccordionTabNode extends NodeIdentity {
62
+ type: "accordion-tab";
63
+ header: Node[];
64
+ content: Node[];
65
+ open?: boolean;
66
+ }
67
+ export interface AccordionGroupNode extends NodeIdentity {
68
+ type: "accordion-group";
69
+ tabs: AccordionTabNode[];
35
70
  }
36
71
  export interface ColumnsNode extends NodeIdentity {
37
72
  type: "columns";
@@ -96,6 +131,13 @@ export interface FigureImageNode extends NodeIdentity {
96
131
  alt: string;
97
132
  hero?: true;
98
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
+ }
99
141
  export interface FormattedTextNode extends NodeIdentity {
100
142
  type: "formatted-text";
101
143
  language?: string;
@@ -180,6 +222,18 @@ export interface ScriptNode extends NodeIdentity {
180
222
  type: "script";
181
223
  "mime-type": string;
182
224
  source: string;
225
+ url?: string;
226
+ }
227
+ export interface StyleNode extends NodeIdentity {
228
+ type: "style";
229
+ source?: string;
230
+ url?: string;
231
+ }
232
+ export type PillColor = "neutral" | "blue" | "green" | "red" | "yellow" | "purple" | "gray" | "teal" | "orange";
233
+ export interface PillNode extends NodeIdentity {
234
+ type: "pill";
235
+ color: PillColor;
236
+ content: Node[];
183
237
  }
184
238
  export interface SecretNode extends NodeIdentity {
185
239
  type: "secret";
@@ -337,10 +391,12 @@ export interface TableOfContentsNode extends NodeIdentity {
337
391
  content: Node[];
338
392
  children: TableOfContentsNode[];
339
393
  }
340
- 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 | 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;
341
395
  export interface DocumentMeta {
342
396
  hidden?: boolean;
343
397
  noindex?: boolean;
398
+ disableHeadingRequirement?: boolean;
399
+ disableToc?: boolean;
344
400
  title: string;
345
401
  author?: string;
346
402
  description?: string;
@@ -351,6 +407,7 @@ export interface DocumentMeta {
351
407
  url: string;
352
408
  contentDigest?: string;
353
409
  readingDifficultyMultiplier?: number;
410
+ keywords?: string[];
354
411
  }
355
412
  export interface DocumentHierarchy {
356
413
  headerText: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-ir",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",