kni 4.0.2 → 5.0.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.
- package/LICENSE +21 -0
- package/README.md +9 -7
- package/console.js +33 -35
- package/describe.js +54 -89
- package/document.js +103 -72
- package/engine.js +436 -407
- package/entry.js +88 -0
- package/evaluate.js +221 -228
- package/excerpt.js +117 -115
- package/grammar.js +1025 -785
- package/html.js +174 -167
- package/inline-lexer.js +155 -125
- package/kni.js +286 -279
- package/link.js +50 -52
- package/outline-lexer.js +64 -37
- package/package.json +27 -34
- package/parser.js +32 -20
- package/path.js +34 -46
- package/readline.js +89 -79
- package/scanner.js +101 -78
- package/scope.js +32 -36
- package/story.js +174 -165
- package/test.js +6 -0
- package/translate-json.js +3 -5
- package/tsconfig.json +11 -0
- package/verify.js +121 -117
- package/wrapper.js +37 -41
- package/template.js +0 -69
package/excerpt.js
CHANGED
|
@@ -1,197 +1,199 @@
|
|
|
1
1
|
// An interface for building excerpts and writing them to a stream.
|
|
2
2
|
// The stream must have the interface of the line wrapper.
|
|
3
|
-
'use strict';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function Excerpt() {
|
|
4
|
+
export default class Excerpt {
|
|
5
|
+
constructor() {
|
|
8
6
|
this.children = [];
|
|
9
7
|
this.flag = false;
|
|
10
|
-
}
|
|
8
|
+
}
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
Child = Paragraph;
|
|
11
|
+
|
|
12
|
+
paragraph() {
|
|
13
|
+
this.flag = true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
break() {
|
|
17
|
+
if (this.children.length === 0) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const last = this.children[this.children.length - 1];
|
|
21
|
+
last.break();
|
|
22
|
+
}
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
Excerpt.prototype.startJoin = function startJoin(lift, delimiter, conjunction) {
|
|
24
|
+
startJoin(lift, delimiter, conjunction) {
|
|
18
25
|
if (this.children.length === 0) {
|
|
19
|
-
|
|
26
|
+
return;
|
|
20
27
|
}
|
|
21
|
-
|
|
28
|
+
const last = this.children[this.children.length - 1];
|
|
22
29
|
last.startJoin(lift, delimiter, conjunction);
|
|
23
|
-
}
|
|
30
|
+
}
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
Excerpt.prototype.delimit = function delimit(delimiter) {
|
|
32
|
+
delimit(delimiter) {
|
|
27
33
|
if (this.children.length === 0) {
|
|
28
|
-
|
|
34
|
+
return;
|
|
29
35
|
}
|
|
30
|
-
|
|
36
|
+
const last = this.children[this.children.length - 1];
|
|
31
37
|
last.delimit(delimiter);
|
|
32
|
-
}
|
|
38
|
+
}
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
Excerpt.prototype.stopJoin = function stopJoin() {
|
|
40
|
+
stopJoin() {
|
|
36
41
|
if (this.children.length === 0) {
|
|
37
|
-
|
|
42
|
+
return;
|
|
38
43
|
}
|
|
39
|
-
|
|
44
|
+
const last = this.children[this.children.length - 1];
|
|
40
45
|
last.stopJoin();
|
|
41
|
-
}
|
|
46
|
+
}
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
digest(lift, words, drop) {
|
|
44
49
|
if (typeof words === 'string') {
|
|
45
|
-
|
|
50
|
+
words = words.split(' ');
|
|
46
51
|
}
|
|
47
52
|
if (this.children.length === 0 || this.flag) {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
this.children.push(new this.Child());
|
|
54
|
+
this.flag = false;
|
|
50
55
|
}
|
|
51
|
-
|
|
56
|
+
const last = this.children[this.children.length - 1];
|
|
52
57
|
last.digest(lift, words, drop);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
write(wrapper) {
|
|
61
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
62
|
+
if (i > 0) {
|
|
63
|
+
wrapper.break();
|
|
64
|
+
}
|
|
65
|
+
this.children[i].write(wrapper);
|
|
61
66
|
}
|
|
62
|
-
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
class Paragraph {
|
|
71
|
+
constructor() {
|
|
65
72
|
this.children = [];
|
|
66
73
|
this.flag = false;
|
|
67
|
-
}
|
|
74
|
+
}
|
|
68
75
|
|
|
69
|
-
|
|
70
|
-
Paragraph.prototype.break = flag;
|
|
71
|
-
Paragraph.prototype.startJoin = Excerpt.prototype.startJoin;
|
|
72
|
-
Paragraph.prototype.delimit = Excerpt.prototype.delimit;
|
|
73
|
-
Paragraph.prototype.stopJoin = Excerpt.prototype.stopJoin;
|
|
74
|
-
Paragraph.prototype.digest = Excerpt.prototype.digest;
|
|
76
|
+
Child = Stanza;
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
break() {
|
|
79
|
+
this.flag = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
startJoin = Excerpt.prototype.startJoin;
|
|
83
|
+
delimit = Excerpt.prototype.delimit;
|
|
84
|
+
stopJoin = Excerpt.prototype.stopJoin;
|
|
85
|
+
digest = Excerpt.prototype.digest;
|
|
86
|
+
|
|
87
|
+
write(wrapper) {
|
|
88
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
89
|
+
this.children[i].write(wrapper);
|
|
79
90
|
}
|
|
80
|
-
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
81
93
|
|
|
82
|
-
|
|
94
|
+
class Stanza {
|
|
95
|
+
constructor() {
|
|
83
96
|
this.children = [];
|
|
84
97
|
this.lift = false;
|
|
85
98
|
this.empty = true;
|
|
86
99
|
this.cursor = new StanzaProxy(this);
|
|
87
|
-
}
|
|
100
|
+
}
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
Stanza.prototype.startJoin = function startJoin(lift, delimiter, conjunction) {
|
|
102
|
+
startJoin(lift, delimiter, conjunction) {
|
|
91
103
|
this.cursor = this.cursor.startJoin(lift, delimiter, conjunction);
|
|
92
|
-
}
|
|
104
|
+
}
|
|
93
105
|
|
|
94
|
-
|
|
95
|
-
Stanza.prototype.delimit = function delimit(delimiter) {
|
|
106
|
+
delimit(delimiter) {
|
|
96
107
|
this.cursor.delimit(delimiter);
|
|
97
|
-
}
|
|
108
|
+
}
|
|
98
109
|
|
|
99
|
-
|
|
100
|
-
Stanza.prototype.stopJoin = function stopJoin() {
|
|
110
|
+
stopJoin() {
|
|
101
111
|
this.cursor = this.cursor.stopJoin();
|
|
102
|
-
}
|
|
112
|
+
}
|
|
103
113
|
|
|
104
|
-
|
|
114
|
+
digest(lift, words, drop) {
|
|
105
115
|
this.cursor.digest(lift, words, drop);
|
|
106
|
-
}
|
|
116
|
+
}
|
|
107
117
|
|
|
108
|
-
|
|
109
|
-
for (
|
|
110
|
-
|
|
118
|
+
write(wrapper) {
|
|
119
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
120
|
+
wrapper.word(this.children[i]);
|
|
111
121
|
}
|
|
112
122
|
wrapper.break();
|
|
113
|
-
}
|
|
123
|
+
}
|
|
114
124
|
|
|
115
|
-
|
|
125
|
+
proxyDigest(lift, words, drop) {
|
|
116
126
|
lift = this.lift || lift;
|
|
117
|
-
|
|
127
|
+
let i = 0;
|
|
118
128
|
if (!lift && words.length && this.children.length) {
|
|
119
|
-
|
|
129
|
+
this.children[this.children.length - 1] += words[i++];
|
|
120
130
|
}
|
|
121
131
|
for (; i < words.length; i++) {
|
|
122
|
-
|
|
132
|
+
this.children.push(words[i]);
|
|
123
133
|
}
|
|
124
134
|
this.lift = drop;
|
|
125
135
|
this.empty = false;
|
|
126
|
-
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
127
138
|
|
|
128
|
-
|
|
139
|
+
class StanzaProxy {
|
|
140
|
+
constructor(parent) {
|
|
129
141
|
this.parent = parent;
|
|
130
|
-
}
|
|
142
|
+
}
|
|
131
143
|
|
|
132
|
-
|
|
133
|
-
StanzaProxy.prototype.startJoin = function startJoin(lift, delimiter, conjunction) {
|
|
144
|
+
startJoin(lift, delimiter, conjunction) {
|
|
134
145
|
return new Conjunction(this, lift, delimiter, conjunction);
|
|
135
|
-
}
|
|
146
|
+
}
|
|
136
147
|
|
|
137
|
-
|
|
138
|
-
StanzaProxy.prototype.delimit = function delimit(delimiter) {
|
|
148
|
+
delimit(delimiter) {
|
|
139
149
|
this.parent.digest('', [delimiter], ' ');
|
|
140
|
-
}
|
|
150
|
+
}
|
|
141
151
|
|
|
142
|
-
|
|
143
|
-
StanzaProxy.prototype.stopJoin = function stopJoin() {
|
|
152
|
+
stopJoin() {
|
|
144
153
|
throw new Error('cannot stop without starting conjunction');
|
|
145
|
-
}
|
|
154
|
+
}
|
|
146
155
|
|
|
147
|
-
|
|
156
|
+
digest(lift, words, drop) {
|
|
148
157
|
this.parent.proxyDigest(lift, words, drop);
|
|
149
|
-
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
150
160
|
|
|
151
|
-
|
|
152
|
-
|
|
161
|
+
class Conjunction {
|
|
162
|
+
constructor(parent, lift, delimiter, conjunction) {
|
|
153
163
|
this.children = [];
|
|
154
164
|
this.parent = parent;
|
|
155
165
|
this.lift = lift;
|
|
156
166
|
this.delimiter = delimiter;
|
|
157
167
|
this.conjunction = conjunction;
|
|
158
|
-
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
Child = Stanza;
|
|
171
|
+
|
|
172
|
+
delimit() {
|
|
173
|
+
this.flag = true;
|
|
174
|
+
}
|
|
159
175
|
|
|
160
|
-
|
|
161
|
-
Conjunction.prototype.delimit = flag;
|
|
162
|
-
Conjunction.prototype.digest = Excerpt.prototype.digest;
|
|
176
|
+
digest = Excerpt.prototype.digest;
|
|
163
177
|
|
|
164
|
-
|
|
178
|
+
startJoin = StanzaProxy.prototype.startJoin;
|
|
165
179
|
|
|
166
|
-
|
|
167
|
-
Conjunction.prototype.stopJoin = function stopJoin(drop) {
|
|
180
|
+
stopJoin(drop) {
|
|
168
181
|
if (this.children.length === 0) {
|
|
182
|
+
// noop
|
|
169
183
|
} else if (this.children.length === 1) {
|
|
170
|
-
|
|
184
|
+
this.parent.digest(this.lift, this.children[0].children, drop);
|
|
171
185
|
} else if (this.children.length === 2) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
this.parent.digest(this.lift, this.children[0].children, '');
|
|
187
|
+
this.parent.digest(' ', [this.conjunction], ' ');
|
|
188
|
+
this.parent.digest(' ', this.children[1].children, drop);
|
|
175
189
|
} else {
|
|
176
|
-
|
|
177
|
-
this.parent.digest('', this.children[i].children, '');
|
|
178
|
-
this.parent.digest('', [this.delimiter], ' ');
|
|
179
|
-
}
|
|
180
|
-
this.parent.digest('', [this.conjunction], ' ');
|
|
190
|
+
for (let i = 0; i < this.children.length - 1; i++) {
|
|
181
191
|
this.parent.digest('', this.children[i].children, '');
|
|
192
|
+
this.parent.digest('', [this.delimiter], ' ');
|
|
193
|
+
}
|
|
194
|
+
this.parent.digest('', [this.conjunction], ' ');
|
|
195
|
+
this.parent.digest('', this.children[this.children.length - 1].children, '');
|
|
182
196
|
}
|
|
183
197
|
return this.parent;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function flag() {
|
|
187
|
-
this.flag = true;
|
|
198
|
+
}
|
|
188
199
|
}
|
|
189
|
-
|
|
190
|
-
function breakChild() {
|
|
191
|
-
// istanbul ignore next
|
|
192
|
-
if (this.children.length === 0) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
var last = this.children[this.children.length - 1];
|
|
196
|
-
last.break();
|
|
197
|
-
};
|