@helloao/tools 0.0.5 → 0.0.6
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 -21
- package/README.md +98 -98
- package/generation/api.d.ts +14 -2
- package/generation/api.js +17 -9
- package/generation/api.spec.js +81 -117
- package/generation/dataset.d.ts +1 -1
- package/generation/dataset.js +5 -5
- package/package.json +1 -2
- package/parser/iterators.spec.js +45 -45
- package/parser/usfm-parser.spec.js +171 -171
- package/parser/usx-parser.d.ts +2 -2
- package/parser/usx-parser.js +92 -31
- package/parser/usx-parser.spec.js +487 -487
- package/typings/types.d.ts +13 -13
package/parser/usx-parser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Chapter, ChapterContent, FootnoteReference, ParseTree, Verse, Text, HebrewSubtitle, InlineLineBreak } from
|
|
2
|
-
import { RewindableIterator } from
|
|
1
|
+
import { Chapter, ChapterContent, FootnoteReference, ParseTree, Verse, Text, HebrewSubtitle, InlineLineBreak } from './types';
|
|
2
|
+
import { RewindableIterator } from './iterators';
|
|
3
3
|
/**
|
|
4
4
|
* The version of the parser.
|
|
5
5
|
* Used to determine whether input files need to be re-parsed.
|
package/parser/usx-parser.js
CHANGED
|
@@ -32,7 +32,7 @@ class USXParser {
|
|
|
32
32
|
const usxElement = doc.documentElement;
|
|
33
33
|
let root = {
|
|
34
34
|
type: 'root',
|
|
35
|
-
content: []
|
|
35
|
+
content: [],
|
|
36
36
|
};
|
|
37
37
|
const bookElement = usxElement.querySelector('book[code]');
|
|
38
38
|
if (!bookElement) {
|
|
@@ -51,7 +51,10 @@ class USXParser {
|
|
|
51
51
|
// const title2 = usxElement.querySelector('para[style="mt2"]');
|
|
52
52
|
// const title3 = usxElement.querySelector('para[style="mt3"]');
|
|
53
53
|
if (titles.length > 0) {
|
|
54
|
-
root.title = [...titles]
|
|
54
|
+
root.title = [...titles]
|
|
55
|
+
.map((t) => t.textContent)
|
|
56
|
+
.filter((t) => t)
|
|
57
|
+
.join(' ');
|
|
55
58
|
}
|
|
56
59
|
for (let content of this.iterateRootContent(usxElement)) {
|
|
57
60
|
root.content.push(content);
|
|
@@ -85,10 +88,13 @@ class USXParser {
|
|
|
85
88
|
}
|
|
86
89
|
else if (child.nodeName === 'para') {
|
|
87
90
|
const style = child.getAttribute('style');
|
|
88
|
-
if (style === 's1' ||
|
|
91
|
+
if (style === 's1' ||
|
|
92
|
+
style === 's2' ||
|
|
93
|
+
style === 's3' ||
|
|
94
|
+
style === 's4') {
|
|
89
95
|
yield {
|
|
90
96
|
type: 'heading',
|
|
91
|
-
content: child.textContent ? [child.textContent] : []
|
|
97
|
+
content: child.textContent ? [child.textContent] : [],
|
|
92
98
|
};
|
|
93
99
|
}
|
|
94
100
|
}
|
|
@@ -108,10 +114,15 @@ class USXParser {
|
|
|
108
114
|
}
|
|
109
115
|
else if (element.nodeName === 'para') {
|
|
110
116
|
const style = element.getAttribute('style');
|
|
111
|
-
if (style === 's1' ||
|
|
117
|
+
if (style === 's1' ||
|
|
118
|
+
style === 's2' ||
|
|
119
|
+
style === 's3' ||
|
|
120
|
+
style === 's4') {
|
|
112
121
|
yield {
|
|
113
122
|
type: 'heading',
|
|
114
|
-
content: element.textContent
|
|
123
|
+
content: element.textContent
|
|
124
|
+
? [element.textContent]
|
|
125
|
+
: [],
|
|
115
126
|
};
|
|
116
127
|
}
|
|
117
128
|
else if (style === 'b') {
|
|
@@ -145,8 +156,18 @@ class USXParser {
|
|
|
145
156
|
let descriptive = null;
|
|
146
157
|
if (parent.nodeName === 'para') {
|
|
147
158
|
const style = parent.getAttribute('style');
|
|
148
|
-
if (style === 'q1' ||
|
|
149
|
-
|
|
159
|
+
if (style === 'q1' ||
|
|
160
|
+
style === 'q2' ||
|
|
161
|
+
style === 'q3' ||
|
|
162
|
+
style === 'q4') {
|
|
163
|
+
poem =
|
|
164
|
+
style === 'q1'
|
|
165
|
+
? 1
|
|
166
|
+
: style === 'q2'
|
|
167
|
+
? 2
|
|
168
|
+
: style === 'q3'
|
|
169
|
+
? 3
|
|
170
|
+
: 4;
|
|
150
171
|
}
|
|
151
172
|
else if (style === 'd') {
|
|
152
173
|
descriptive = true;
|
|
@@ -156,7 +177,7 @@ class USXParser {
|
|
|
156
177
|
if (poem !== null || descriptive !== null) {
|
|
157
178
|
if (typeof content === 'string') {
|
|
158
179
|
let text = {
|
|
159
|
-
text: content
|
|
180
|
+
text: content,
|
|
160
181
|
};
|
|
161
182
|
if (poem !== null) {
|
|
162
183
|
text.poem = poem;
|
|
@@ -168,7 +189,7 @@ class USXParser {
|
|
|
168
189
|
}
|
|
169
190
|
else {
|
|
170
191
|
let text = {
|
|
171
|
-
...content
|
|
192
|
+
...content,
|
|
172
193
|
};
|
|
173
194
|
if ('text' in text) {
|
|
174
195
|
if (poem !== null) {
|
|
@@ -191,7 +212,7 @@ class USXParser {
|
|
|
191
212
|
const verse = {
|
|
192
213
|
type: 'verse',
|
|
193
214
|
number: parseInt(element.getAttribute('number') || '0', 10),
|
|
194
|
-
content: []
|
|
215
|
+
content: [],
|
|
195
216
|
};
|
|
196
217
|
for (let content of this.iterateVerseContent(chapter, verse, nodes)) {
|
|
197
218
|
addOrJoin(verse.content, content);
|
|
@@ -202,7 +223,7 @@ class USXParser {
|
|
|
202
223
|
*parseHebrewSubtitle(para, chapter, nodes) {
|
|
203
224
|
const subtitle = {
|
|
204
225
|
type: 'hebrew_subtitle',
|
|
205
|
-
content: []
|
|
226
|
+
content: [],
|
|
206
227
|
};
|
|
207
228
|
for (let content of this.iterateHebrewSubtitleContent(para, chapter, nodes)) {
|
|
208
229
|
if (typeof content === 'object' && 'number' in content) {
|
|
@@ -241,12 +262,14 @@ class USXParser {
|
|
|
241
262
|
else if (node instanceof Element && node.nodeName === 'char') {
|
|
242
263
|
yield* this.iterateChar(nodes, node);
|
|
243
264
|
}
|
|
244
|
-
else if (node instanceof Element &&
|
|
265
|
+
else if (node instanceof Element &&
|
|
266
|
+
node.nodeName === 'para' &&
|
|
267
|
+
node.getAttribute('style') === 'b') {
|
|
245
268
|
for (let _ of (0, iterators_1.children)(nodes, node)) {
|
|
246
269
|
// iterate through all the children to prevent iterating over them multiple times
|
|
247
270
|
}
|
|
248
271
|
yield {
|
|
249
|
-
lineBreak: true
|
|
272
|
+
lineBreak: true,
|
|
250
273
|
};
|
|
251
274
|
}
|
|
252
275
|
else if (node.nodeType === NodeType.Text) {
|
|
@@ -259,7 +282,7 @@ class USXParser {
|
|
|
259
282
|
if (style === 'wj') {
|
|
260
283
|
yield {
|
|
261
284
|
text,
|
|
262
|
-
wordsOfJesus: true
|
|
285
|
+
wordsOfJesus: true,
|
|
263
286
|
};
|
|
264
287
|
}
|
|
265
288
|
else {
|
|
@@ -286,12 +309,12 @@ class USXParser {
|
|
|
286
309
|
text,
|
|
287
310
|
reference: {
|
|
288
311
|
chapter: chapter.number,
|
|
289
|
-
verse: verse?.number ?? 0
|
|
290
|
-
}
|
|
312
|
+
verse: verse?.number ?? 0,
|
|
313
|
+
},
|
|
291
314
|
};
|
|
292
315
|
chapter.footnotes.push(note);
|
|
293
316
|
yield {
|
|
294
|
-
noteId: note.noteId
|
|
317
|
+
noteId: note.noteId,
|
|
295
318
|
};
|
|
296
319
|
}
|
|
297
320
|
else {
|
|
@@ -312,7 +335,7 @@ class USXParser {
|
|
|
312
335
|
if (style === 'wj') {
|
|
313
336
|
yield {
|
|
314
337
|
text,
|
|
315
|
-
wordsOfJesus: true
|
|
338
|
+
wordsOfJesus: true,
|
|
316
339
|
};
|
|
317
340
|
}
|
|
318
341
|
else {
|
|
@@ -329,15 +352,31 @@ const ignoredParaStyles = new Set([
|
|
|
329
352
|
// <para> Identification [exclude all] - Running headings & table of contents
|
|
330
353
|
'ide', // See https://github.com/schierlm/BibleMultiConverter/issues/67
|
|
331
354
|
'rem', // Remarks (valid in schema though missed in docs)
|
|
332
|
-
'h',
|
|
333
|
-
'
|
|
334
|
-
'
|
|
355
|
+
'h',
|
|
356
|
+
'h1',
|
|
357
|
+
'h2',
|
|
358
|
+
'h3',
|
|
359
|
+
'h4',
|
|
360
|
+
'toc1',
|
|
361
|
+
'toc2',
|
|
362
|
+
'toc3',
|
|
363
|
+
'toca1',
|
|
364
|
+
'toca2',
|
|
365
|
+
'toca3',
|
|
335
366
|
/* <para> Introductions [exclude all] - Introductionary (non-biblical) content
|
|
336
367
|
Which might be helpful in a printed book, but intro material in apps is usually bad UX,
|
|
337
368
|
and users that really care can research a translations methodology themselves
|
|
338
369
|
*/
|
|
339
|
-
'imt',
|
|
340
|
-
'
|
|
370
|
+
'imt',
|
|
371
|
+
'imt1',
|
|
372
|
+
'imt2',
|
|
373
|
+
'imt3',
|
|
374
|
+
'imt4',
|
|
375
|
+
'is',
|
|
376
|
+
'is1',
|
|
377
|
+
'is2',
|
|
378
|
+
'is3',
|
|
379
|
+
'is4',
|
|
341
380
|
'ip',
|
|
342
381
|
'ipi',
|
|
343
382
|
'im',
|
|
@@ -345,19 +384,39 @@ const ignoredParaStyles = new Set([
|
|
|
345
384
|
'ipq',
|
|
346
385
|
'imq',
|
|
347
386
|
'ipr',
|
|
348
|
-
'iq',
|
|
387
|
+
'iq',
|
|
388
|
+
'iq1',
|
|
389
|
+
'iq2',
|
|
390
|
+
'iq3',
|
|
391
|
+
'iq4',
|
|
349
392
|
'ib',
|
|
350
|
-
'ili',
|
|
393
|
+
'ili',
|
|
394
|
+
'ili1',
|
|
395
|
+
'ili2',
|
|
396
|
+
'ili3',
|
|
397
|
+
'ili4',
|
|
351
398
|
'iot',
|
|
352
|
-
'io',
|
|
399
|
+
'io',
|
|
400
|
+
'io1',
|
|
401
|
+
'io2',
|
|
402
|
+
'io3',
|
|
403
|
+
'io4',
|
|
353
404
|
'iex',
|
|
354
405
|
'imte',
|
|
355
406
|
'ie',
|
|
356
407
|
/* <para> Headings [exclude some] - Exclude book & chapter headings but keep section headings
|
|
357
408
|
Not excluded: ms# | mr | s# | sr | d | sp | sd#
|
|
358
409
|
*/
|
|
359
|
-
'mt',
|
|
360
|
-
'
|
|
410
|
+
'mt',
|
|
411
|
+
'mt1',
|
|
412
|
+
'mt2',
|
|
413
|
+
'mt3',
|
|
414
|
+
'mt4',
|
|
415
|
+
'mte',
|
|
416
|
+
'mte1',
|
|
417
|
+
'mte2',
|
|
418
|
+
'mte3',
|
|
419
|
+
'mte4',
|
|
361
420
|
'cl',
|
|
362
421
|
'cd', // Non-biblical chapter summary, more than heading
|
|
363
422
|
'r', // Parallels to be provided by external data
|
|
@@ -368,7 +427,7 @@ function* iterateCharContent(char) {
|
|
|
368
427
|
if (style === 'wj') {
|
|
369
428
|
yield {
|
|
370
429
|
text,
|
|
371
|
-
wordsOfJesus: true
|
|
430
|
+
wordsOfJesus: true,
|
|
372
431
|
};
|
|
373
432
|
}
|
|
374
433
|
else {
|
|
@@ -409,7 +468,9 @@ function addOrJoin(array, value) {
|
|
|
409
468
|
if (typeof last === 'string' && typeof value === 'string') {
|
|
410
469
|
array[array.length - 1] = last + value;
|
|
411
470
|
}
|
|
412
|
-
else if (isVerseText(last) &&
|
|
471
|
+
else if (isVerseText(last) &&
|
|
472
|
+
isVerseText(value) &&
|
|
473
|
+
hasSameFormatting(last, value)) {
|
|
413
474
|
last.text += value.text;
|
|
414
475
|
}
|
|
415
476
|
else {
|