document-ir 0.4.0 → 0.4.2

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 { 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
- 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);
1
+ var y = Object.defineProperty;
2
+ var d = (c, t, e) => t in c ? y(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
3
+ var h = (c, t, e) => d(c, typeof t != "symbol" ? t + "" : t, e);
4
4
  class u {
5
5
  async beforeBlock() {
6
6
  }
@@ -92,7 +92,7 @@ class u {
92
92
  type: "code",
93
93
  content: e
94
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;
95
+ return t.language != null && (i.language = t.language), t.diff != null && (i.diff = t.diff), t.lineNumbers != null && (i.lineNumbers = t.lineNumbers), t.id != null && (i.id = t.id), i;
96
96
  }
97
97
  async codeBlock(t) {
98
98
  const i = {
@@ -273,10 +273,9 @@ class u {
273
273
  await this.beforeBlock(), await this.afterBlock();
274
274
  const e = {
275
275
  type: "formatted-text",
276
- text: t.text || "",
277
- language: t.language
276
+ text: t.text || ""
278
277
  };
279
- return t.id != null && (e.id = t.id), e;
278
+ return t.language != null && (e.language = t.language), t.id != null && (e.id = t.id), e;
280
279
  }
281
280
  async header(t) {
282
281
  await this.beforeBlock();
@@ -405,10 +404,9 @@ class u {
405
404
  type: "quote",
406
405
  icon: t.icon,
407
406
  name: t.name,
408
- content: e,
409
- url: t.url
407
+ content: e
410
408
  };
411
- return t.id != null && (i.id = t.id), t.orientation && (i.orientation = t.orientation), i;
409
+ return t.id != null && (i.id = t.id), t.url && (i.url = t.url), t.orientation && (i.orientation = t.orientation), i;
412
410
  }
413
411
  async redacted(t) {
414
412
  t.style == "block" ? await this.beforeBlock() : await this.beforeInline();
@@ -622,10 +620,9 @@ class u {
622
620
  content: e,
623
621
  attribution: i,
624
622
  header: s,
625
- media: r,
626
- original: t.original
623
+ media: r
627
624
  };
628
- return t.id != null && (n.id = t.id), n;
625
+ return t.original && (n.original = t.original), t.id != null && (n.id = t.id), n;
629
626
  }
630
627
  async date(t) {
631
628
  await this.beforeInline();
@@ -857,7 +854,7 @@ class u {
857
854
  return await this.document(t);
858
855
  }
859
856
  }
860
- class k extends u {
857
+ class g extends u {
861
858
  async chooseChildren(t) {
862
859
  const e = await super.chooseChildren(t), i = [];
863
860
  for (const s of e)
@@ -890,7 +887,7 @@ class I extends u {
890
887
  return i;
891
888
  }
892
889
  }
893
- class g extends u {
890
+ class k extends u {
894
891
  async text(t) {
895
892
  return t.text == "" ? null : t;
896
893
  }
@@ -918,6 +915,13 @@ class T extends u {
918
915
  stripLastText() {
919
916
  this.lastText && (this.lastText.text.endsWith(" ") && (this.lastText.text = this.lastText.text.slice(0, -1)), this.lastText = null), this.stripWhitespace = !0;
920
917
  }
918
+ async code(e) {
919
+ const i = {
920
+ type: "code",
921
+ content: e.content
922
+ };
923
+ return e.language != null && (i.language = e.language), e.diff != null && (i.diff = e.diff), e.lineNumbers != null && (i.lineNumbers = e.lineNumbers), e.id != null && (i.id = e.id), i;
924
+ }
921
925
  async beforeBlock() {
922
926
  this.stripLastText();
923
927
  }
@@ -926,7 +930,7 @@ class T extends u {
926
930
  }
927
931
  async transform(e) {
928
932
  const i = await super.transform(e);
929
- return await new g().transform(i);
933
+ return await new k().transform(i);
930
934
  }
931
935
  }
932
936
  class v extends u {
@@ -982,6 +986,13 @@ class v extends u {
982
986
  !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}`));
983
987
  }
984
988
  }
989
+ async code(e) {
990
+ const i = {
991
+ type: "code",
992
+ content: e.content
993
+ };
994
+ return e.language != null && (i.language = e.language), e.diff != null && (i.diff = e.diff), e.lineNumbers != null && (i.lineNumbers = e.lineNumbers), e.id != null && (i.id = e.id), i;
995
+ }
985
996
  async text(e) {
986
997
  const i = {
987
998
  type: "text",
@@ -1329,7 +1340,7 @@ class m extends w {
1329
1340
  return this.textList.join("");
1330
1341
  }
1331
1342
  }
1332
- class B extends k {
1343
+ class B extends g {
1333
1344
  async sticker(t) {
1334
1345
  if (t.content.length == 0)
1335
1346
  return null;
@@ -1602,7 +1613,7 @@ class N extends u {
1602
1613
  }
1603
1614
  }
1604
1615
  export {
1605
- k as ArrayCollapseTransformer,
1616
+ g as ArrayCollapseTransformer,
1606
1617
  B as DocumentThinningTransformer,
1607
1618
  u as IdentityTransformer,
1608
1619
  w as NodeVisitor,
package/dist/types.d.ts CHANGED
@@ -37,6 +37,7 @@ export interface CenterNode extends NodeIdentity {
37
37
  export interface CodeNode extends NodeIdentity {
38
38
  type: "code";
39
39
  content: Node[];
40
+ language?: string;
40
41
  diff?: boolean;
41
42
  lineNumbers?: boolean;
42
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-ir",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",