document-ir 0.5.3 → 0.6.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,5 +1,5 @@
1
1
  import { ArrayCollapseTransformer } from './ArrayCollapseTransformer.ts';
2
- import { BubbleNode, CardNode, ColumnsNode, DefinitionListNode, FigureImageNode, HighTechAlertNode, ImageNode, Node, NoteNode, QuoteNode, RedactedNode, StickerNode, VideoNode } from './types.ts';
2
+ import { AdmonitionNode, BubbleNode, CardNode, ColumnsNode, DefinitionListNode, FigureImageNode, HighTechAlertNode, ImageNode, Node, NoteNode, QuoteNode, RedactedNode, StickerNode, VideoNode } from './types.ts';
3
3
  export declare class DocumentThinningTransformer extends ArrayCollapseTransformer {
4
4
  protected sticker(node: StickerNode): Promise<Node | null>;
5
5
  protected bubble(node: BubbleNode): Promise<Node | null>;
@@ -11,6 +11,7 @@ export declare class DocumentThinningTransformer extends ArrayCollapseTransforme
11
11
  protected video(node: VideoNode): Promise<Node | null>;
12
12
  protected definitionList(node: DefinitionListNode): Promise<Node | null>;
13
13
  protected redacted(_node: RedactedNode): Promise<Node | null>;
14
+ protected admonition(node: AdmonitionNode): Promise<Node | null>;
14
15
  protected note(node: NoteNode): Promise<Node | null>;
15
16
  protected card(node: CardNode): Promise<Node | null>;
16
17
  }
@@ -1,4 +1,4 @@
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';
1
+ import { AccordionGroupNode, AccordionTabNode, AdmonitionNode, 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>;
@@ -36,6 +36,7 @@ export declare class IdentityTransformer {
36
36
  protected image(node: ImageNode): Promise<Node | null>;
37
37
  protected italic(node: ItalicNode): Promise<Node | null>;
38
38
  protected link(node: LinkNode): Promise<Node | null>;
39
+ protected admonition(node: AdmonitionNode): Promise<Node | null>;
39
40
  protected array(node: ArrayNode): Promise<Node | null>;
40
41
  protected note(node: NoteNode): Promise<Node | null>;
41
42
  protected list(node: ListNode): Promise<Node | null>;
@@ -1,4 +1,4 @@
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';
1
+ import { AccordionGroupNode, AccordionTabNode, AdmonitionNode, ArrayNode, BadgeNode, BlockNode, BlockQuoteNode, BoldNode, BreakNode, BubbleNode, CardNode, CenterNode, CodeNode, CodeBlockNode, CodeGroupNode, CodeGroupTabNode, ColumnsNode, PillNode, StyleNode, 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;
@@ -13,6 +13,13 @@ export declare class NodeVisitor {
13
13
  protected bubble(node: BubbleNode): void;
14
14
  protected center(node: CenterNode): void;
15
15
  protected code(node: CodeNode): void;
16
+ protected codeBlock(node: CodeBlockNode): void;
17
+ protected accordionTab(node: AccordionTabNode): void;
18
+ protected accordionGroup(node: AccordionGroupNode): void;
19
+ protected codeGroupTab(node: CodeGroupTabNode): void;
20
+ protected codeGroup(node: CodeGroupNode): void;
21
+ protected pill(node: PillNode): void;
22
+ protected style(_node: StyleNode): void;
16
23
  protected columns(node: ColumnsNode): void;
17
24
  protected definition(node: DefinitionNode): void;
18
25
  protected definitionList(node: DefinitionListNode): void;
@@ -31,6 +38,7 @@ export declare class NodeVisitor {
31
38
  protected image(_node: ImageNode): void;
32
39
  protected italic(node: ItalicNode): void;
33
40
  protected link(node: LinkNode): void;
41
+ protected admonition(node: AdmonitionNode): void;
34
42
  protected array(node: ArrayNode): void;
35
43
  protected note(node: NoteNode): void;
36
44
  protected list(node: ListNode): void;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var d = Object.defineProperty;
2
- var g = (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) => g(c, typeof t != "symbol" ? t + "" : t, e);
2
+ var k = (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) => k(c, typeof t != "symbol" ? t + "" : t, e);
4
4
  class u {
5
5
  async beforeBlock() {
6
6
  }
@@ -338,6 +338,18 @@ class u {
338
338
  };
339
339
  return t.id != null && (i.id = t.id), t.title && (i.title = t.title), t.target && (i.target = t.target), t.userGeneratedContent && (i.userGeneratedContent = t.userGeneratedContent), t.noReferrer && (i.noReferrer = t.noReferrer), t.noFollow && (i.noFollow = t.noFollow), t.noOpener && (i.noOpener = t.noOpener), i;
340
340
  }
341
+ async admonition(t) {
342
+ await this.beforeBlock();
343
+ const e = await this.chooseChildren(t.content);
344
+ let i;
345
+ t.title && (i = await this.chooseChildren(t.title)), await this.afterBlock();
346
+ const s = {
347
+ type: "admonition",
348
+ admonitionType: t.admonitionType,
349
+ content: e
350
+ };
351
+ return i && (s.title = i), t.collapsable != null && (s.collapsable = t.collapsable), t.collapsed != null && (s.collapsed = t.collapsed), t.inline != null && (s.inline = t.inline), t.id != null && (s.id = t.id), s;
352
+ }
341
353
  async array(t) {
342
354
  const e = {
343
355
  type: "array",
@@ -767,6 +779,8 @@ class u {
767
779
  return await this.link(t);
768
780
  case "accordion-group":
769
781
  return await this.accordionGroup(t);
782
+ case "admonition":
783
+ return await this.admonition(t);
770
784
  case "array":
771
785
  return await this.array(t);
772
786
  case "note":
@@ -855,7 +869,7 @@ class u {
855
869
  return await this.document(t);
856
870
  }
857
871
  }
858
- class k extends u {
872
+ class g extends u {
859
873
  async chooseChildren(t) {
860
874
  const e = await super.chooseChildren(t), i = [];
861
875
  for (const s of e)
@@ -1023,7 +1037,7 @@ class N extends u {
1023
1037
  return this.reviewBlock(this.root), i;
1024
1038
  }
1025
1039
  }
1026
- class b {
1040
+ class w {
1027
1041
  beforeBlock() {
1028
1042
  }
1029
1043
  afterBlock() {
@@ -1059,6 +1073,28 @@ class b {
1059
1073
  code(t) {
1060
1074
  this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1061
1075
  }
1076
+ codeBlock(t) {
1077
+ this.code(t.content);
1078
+ }
1079
+ accordionTab(t) {
1080
+ this.beforeInline(), this.chooseChildren(t.header), this.afterInline(), this.beforeBlock(), this.chooseChildren(t.content), this.afterBlock();
1081
+ }
1082
+ accordionGroup(t) {
1083
+ for (const e of t.tabs)
1084
+ this.accordionTab(e);
1085
+ }
1086
+ codeGroupTab(t) {
1087
+ this.beforeInline(), this.chooseChildren(t.header), this.afterInline(), this.code(t.content);
1088
+ }
1089
+ codeGroup(t) {
1090
+ for (const e of t.tabs)
1091
+ this.codeGroupTab(e);
1092
+ }
1093
+ pill(t) {
1094
+ this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1095
+ }
1096
+ style(t) {
1097
+ }
1062
1098
  columns(t) {
1063
1099
  for (const e of t.columns)
1064
1100
  this.beforeBlock(), this.chooseChildren(e), this.afterBlock();
@@ -1111,6 +1147,9 @@ class b {
1111
1147
  link(t) {
1112
1148
  this.beforeInline(), this.chooseChildren(t.content), this.afterInline();
1113
1149
  }
1150
+ admonition(t) {
1151
+ this.beforeBlock(), t.title && this.chooseChildren(t.title), this.chooseChildren(t.content), this.afterBlock();
1152
+ }
1114
1153
  array(t) {
1115
1154
  this.chooseChildren(t.content);
1116
1155
  }
@@ -1217,6 +1256,18 @@ class b {
1217
1256
  return this.center(t);
1218
1257
  case "code":
1219
1258
  return this.code(t);
1259
+ case "code-block":
1260
+ return this.codeBlock(t);
1261
+ case "code-group":
1262
+ return this.codeGroup(t);
1263
+ case "accordion-group":
1264
+ return this.accordionGroup(t);
1265
+ case "admonition":
1266
+ return this.admonition(t);
1267
+ case "pill":
1268
+ return this.pill(t);
1269
+ case "style":
1270
+ return this.style(t);
1220
1271
  case "columns":
1221
1272
  return this.columns(t);
1222
1273
  case "definition":
@@ -1324,7 +1375,7 @@ class b {
1324
1375
  t.type == "document" ? this.document(t) : this.choose(t);
1325
1376
  }
1326
1377
  }
1327
- class B extends b {
1378
+ class B extends w {
1328
1379
  constructor() {
1329
1380
  super();
1330
1381
  h(this, "textList");
@@ -1359,7 +1410,7 @@ class B extends b {
1359
1410
  return this.textList.join("");
1360
1411
  }
1361
1412
  }
1362
- class C extends k {
1413
+ class C extends g {
1363
1414
  async sticker(t) {
1364
1415
  if (t.content.length == 0)
1365
1416
  return null;
@@ -1501,6 +1552,18 @@ class C extends k {
1501
1552
  async redacted(t) {
1502
1553
  return null;
1503
1554
  }
1555
+ async admonition(t) {
1556
+ if (t.content.length == 0)
1557
+ return null;
1558
+ const e = await this.chooseChildren(t.content);
1559
+ return e ? {
1560
+ type: "paragraph",
1561
+ content: [
1562
+ { type: "text", text: `${t.admonitionType.charAt(0).toUpperCase() + t.admonitionType.slice(1)}: ` },
1563
+ ...e
1564
+ ]
1565
+ } : null;
1566
+ }
1504
1567
  async note(t) {
1505
1568
  if (t.content.length == 0)
1506
1569
  return null;
@@ -1550,7 +1613,7 @@ class C extends k {
1550
1613
  };
1551
1614
  }
1552
1615
  }
1553
- class x extends b {
1616
+ class x extends w {
1554
1617
  constructor() {
1555
1618
  super();
1556
1619
  h(this, "count");
@@ -1621,8 +1684,8 @@ class _ extends u {
1621
1684
  depth: o.level,
1622
1685
  children: [],
1623
1686
  nodes: []
1624
- }, w = o.htmlId || o.id;
1625
- w && (f.headerId = w), s[s.length - 1].children.push(f), s.push(f), n = o.level;
1687
+ }, b = o.htmlId || o.id;
1688
+ b && (f.headerId = b), s[s.length - 1].children.push(f), s.push(f), n = o.level;
1626
1689
  } else
1627
1690
  s[s.length - 1].nodes.push(o);
1628
1691
  const a = {
@@ -1632,10 +1695,10 @@ class _ extends u {
1632
1695
  }
1633
1696
  }
1634
1697
  export {
1635
- k as ArrayCollapseTransformer,
1698
+ g as ArrayCollapseTransformer,
1636
1699
  C as DocumentThinningTransformer,
1637
1700
  u as IdentityTransformer,
1638
- b as NodeVisitor,
1701
+ w as NodeVisitor,
1639
1702
  T as TextCollapseTransformer,
1640
1703
  B as TextVisitor,
1641
1704
  N as WhitespaceStretchingTransformer,
package/dist/types.d.ts CHANGED
@@ -1,6 +1,16 @@
1
1
  export interface NodeIdentity {
2
2
  id?: string;
3
3
  }
4
+ export type AdmonitionType = "note" | "tip" | "info" | "warning" | "danger";
5
+ export interface AdmonitionNode extends NodeIdentity {
6
+ type: "admonition";
7
+ admonitionType: AdmonitionType;
8
+ content: Node[];
9
+ title?: Node[];
10
+ collapsable?: boolean;
11
+ collapsed?: boolean;
12
+ inline?: boolean;
13
+ }
4
14
  export interface ArrayNode extends NodeIdentity {
5
15
  type: "array";
6
16
  content: Node[];
@@ -397,7 +407,7 @@ export interface TableOfContentsNode extends NodeIdentity {
397
407
  content: Node[];
398
408
  children: TableOfContentsNode[];
399
409
  }
400
- 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;
410
+ export type Node = AccordionGroupNode | AdmonitionNode | 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;
401
411
  export interface DocumentMeta {
402
412
  hidden?: boolean;
403
413
  noindex?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-ir",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",