text-doc-ir 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/main.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare class FixedWidthTextVisitor extends NodeVisitor {
6
6
  private breakLazy;
7
7
  private spaceLazy;
8
8
  private breakCount;
9
+ private eatSpaces;
9
10
  private state;
10
11
  constructor(width: number);
11
12
  private setState;
package/esm/main.js CHANGED
@@ -39,6 +39,12 @@ export class FixedWidthTextVisitor extends NodeVisitor {
39
39
  writable: true,
40
40
  value: void 0
41
41
  });
42
+ Object.defineProperty(this, "eatSpaces", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
42
48
  Object.defineProperty(this, "state", {
43
49
  enumerable: true,
44
50
  configurable: true,
@@ -51,6 +57,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
51
57
  this.breakLazy = false;
52
58
  this.spaceLazy = false;
53
59
  this.breakCount = 0;
60
+ this.eatSpaces = true;
54
61
  this.state = {
55
62
  images: new Map(),
56
63
  imagesReverse: new Map(),
@@ -71,6 +78,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
71
78
  this.pushBlockContentBegin();
72
79
  for (const line of node.text.split("\n")) {
73
80
  this.pushLine();
81
+ this.eatSpaces = false;
74
82
  this.pushText(line);
75
83
  }
76
84
  this.pushBlockContentEnd();
@@ -731,7 +739,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
731
739
  }
732
740
  let sliceStart = 0;
733
741
  do {
734
- if (line == "" || line.endsWith(" ")) {
742
+ if ((line == "" && this.eatSpaces) || line.endsWith(" ")) {
735
743
  // skip white space
736
744
  while (true) {
737
745
  const nextChar = text.slice(sliceStart, sliceStart + 1);
@@ -746,6 +754,7 @@ export class FixedWidthTextVisitor extends NodeVisitor {
746
754
  }
747
755
  }
748
756
  }
757
+ this.eatSpaces = true;
749
758
  let sliceEnd = sliceStart + this.width - line.length;
750
759
  let slice = text.slice(sliceStart, sliceEnd);
751
760
  const nextChar = text.slice(sliceEnd, sliceEnd + 1);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/main.js",
3
3
  "main": "./script/main.js",
4
4
  "name": "text-doc-ir",
5
- "version": "0.0.2",
5
+ "version": "0.0.3",
6
6
  "description": "Transforms a document intermediate representation into plain text with formatting",
7
7
  "license": "MIT",
8
8
  "repository": {
package/script/main.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare class FixedWidthTextVisitor extends NodeVisitor {
6
6
  private breakLazy;
7
7
  private spaceLazy;
8
8
  private breakCount;
9
+ private eatSpaces;
9
10
  private state;
10
11
  constructor(width: number);
11
12
  private setState;
package/script/main.js CHANGED
@@ -42,6 +42,12 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
42
42
  writable: true,
43
43
  value: void 0
44
44
  });
45
+ Object.defineProperty(this, "eatSpaces", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
45
51
  Object.defineProperty(this, "state", {
46
52
  enumerable: true,
47
53
  configurable: true,
@@ -54,6 +60,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
54
60
  this.breakLazy = false;
55
61
  this.spaceLazy = false;
56
62
  this.breakCount = 0;
63
+ this.eatSpaces = true;
57
64
  this.state = {
58
65
  images: new Map(),
59
66
  imagesReverse: new Map(),
@@ -74,6 +81,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
74
81
  this.pushBlockContentBegin();
75
82
  for (const line of node.text.split("\n")) {
76
83
  this.pushLine();
84
+ this.eatSpaces = false;
77
85
  this.pushText(line);
78
86
  }
79
87
  this.pushBlockContentEnd();
@@ -734,7 +742,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
734
742
  }
735
743
  let sliceStart = 0;
736
744
  do {
737
- if (line == "" || line.endsWith(" ")) {
745
+ if ((line == "" && this.eatSpaces) || line.endsWith(" ")) {
738
746
  // skip white space
739
747
  while (true) {
740
748
  const nextChar = text.slice(sliceStart, sliceStart + 1);
@@ -749,6 +757,7 @@ class FixedWidthTextVisitor extends deps_js_1.NodeVisitor {
749
757
  }
750
758
  }
751
759
  }
760
+ this.eatSpaces = true;
752
761
  let sliceEnd = sliceStart + this.width - line.length;
753
762
  let slice = text.slice(sliceStart, sliceEnd);
754
763
  const nextChar = text.slice(sliceEnd, sliceEnd + 1);