node-sword-interface 1.0.23 → 1.0.25
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/API.md +36 -7
- package/index.js +64 -3
- package/package.json +4 -3
- package/src/napi_module/node_sword_interface.cpp +0 -21
- package/src/napi_module/node_sword_interface.hpp +0 -1
- package/src/node_sword_cli.cpp +0 -10
- package/src/sword_backend/text_processor.cpp +0 -69
- package/src/sword_backend/text_processor.hpp +0 -1
package/API.md
CHANGED
|
@@ -57,9 +57,11 @@ This is the main class of node-sword-interface and it provides a set of static f
|
|
|
57
57
|
* [.getVersesFromReferences(moduleCode, references)](#NodeSwordInterface+getVersesFromReferences) ⇒ [<code>Array.<VerseObject></code>](#VerseObject)
|
|
58
58
|
* [.getReferencesFromReferenceRange(referenceRange)](#NodeSwordInterface+getReferencesFromReferenceRange) ⇒ <code>Array.<String></code>
|
|
59
59
|
* [.getBookList(moduleCode)](#NodeSwordInterface+getBookList) ⇒ <code>Array.<String></code>
|
|
60
|
-
* [.getBookHeaderList(moduleCode, bookCode,
|
|
60
|
+
* [.getBookHeaderList(moduleCode, bookCode, startVerseNumber, verseCount)](#NodeSwordInterface+getBookHeaderList) ⇒ [<code>Array.<VerseObject></code>](#VerseObject)
|
|
61
61
|
* [.getBookChapterCount(moduleCode, bookCode)](#NodeSwordInterface+getBookChapterCount)
|
|
62
62
|
* [.getChapterVerseCount(moduleCode, bookCode, chapter)](#NodeSwordInterface+getChapterVerseCount)
|
|
63
|
+
* [.getAllChapterVerseCounts(moduleCode, bookCode)](#NodeSwordInterface+getAllChapterVerseCounts) ⇒ <code>Number</code>
|
|
64
|
+
* [.getBookVerseCount(moduleCode, bookCode)](#NodeSwordInterface+getBookVerseCount) ⇒ <code>Number</code>
|
|
63
65
|
* [.getBibleText(moduleCode)](#NodeSwordInterface+getBibleText) ⇒ [<code>Array.<VerseObject></code>](#VerseObject)
|
|
64
66
|
* [.getBookIntroduction(moduleCode, bookCode)](#NodeSwordInterface+getBookIntroduction) ⇒ <code>String</code>
|
|
65
67
|
* [.moduleHasBook(moduleCode, bookCode)](#NodeSwordInterface+moduleHasBook) ⇒ <code>Boolean</code>
|
|
@@ -402,16 +404,17 @@ Returns the list of books available in the given module. By default the book cod
|
|
|
402
404
|
|
|
403
405
|
<a name="NodeSwordInterface+getBookHeaderList"></a>
|
|
404
406
|
|
|
405
|
-
### nodeSwordInterface.getBookHeaderList(moduleCode, bookCode,
|
|
407
|
+
### nodeSwordInterface.getBookHeaderList(moduleCode, bookCode, startVerseNumber, verseCount) ⇒ [<code>Array.<VerseObject></code>](#VerseObject)
|
|
406
408
|
Returns the list of headers available in the given book. The headers are returned as an array of VerseObjects.
|
|
407
409
|
|
|
408
410
|
**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
|
|
409
411
|
|
|
410
|
-
| Param | Type |
|
|
411
|
-
| --- | --- |
|
|
412
|
-
| moduleCode | <code>String</code> |
|
|
413
|
-
| bookCode | <code>String</code> |
|
|
414
|
-
|
|
|
412
|
+
| Param | Type |
|
|
413
|
+
| --- | --- |
|
|
414
|
+
| moduleCode | <code>String</code> |
|
|
415
|
+
| bookCode | <code>String</code> |
|
|
416
|
+
| startVerseNumber | <code>Number</code> |
|
|
417
|
+
| verseCount | <code>Number</code> |
|
|
415
418
|
|
|
416
419
|
<a name="NodeSwordInterface+getBookChapterCount"></a>
|
|
417
420
|
|
|
@@ -438,6 +441,32 @@ Returns the number of verses in the given chapter.
|
|
|
438
441
|
| bookCode | <code>String</code> | The book code of the SWORD module. |
|
|
439
442
|
| chapter | <code>Number</code> | The chapter of the book. |
|
|
440
443
|
|
|
444
|
+
<a name="NodeSwordInterface+getAllChapterVerseCounts"></a>
|
|
445
|
+
|
|
446
|
+
### nodeSwordInterface.getAllChapterVerseCounts(moduleCode, bookCode) ⇒ <code>Number</code>
|
|
447
|
+
Returns an array with the chapter verse counts of all chapters of a given book.
|
|
448
|
+
|
|
449
|
+
**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
|
|
450
|
+
**Returns**: <code>Number</code> - chapterVerseCounts
|
|
451
|
+
|
|
452
|
+
| Param | Type |
|
|
453
|
+
| --- | --- |
|
|
454
|
+
| moduleCode | <code>String</code> |
|
|
455
|
+
| bookCode | <code>String</code> |
|
|
456
|
+
|
|
457
|
+
<a name="NodeSwordInterface+getBookVerseCount"></a>
|
|
458
|
+
|
|
459
|
+
### nodeSwordInterface.getBookVerseCount(moduleCode, bookCode) ⇒ <code>Number</code>
|
|
460
|
+
Returns the number verses in the given book.
|
|
461
|
+
|
|
462
|
+
**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
|
|
463
|
+
**Returns**: <code>Number</code> - The verse count of the book.
|
|
464
|
+
|
|
465
|
+
| Param | Type | Description |
|
|
466
|
+
| --- | --- | --- |
|
|
467
|
+
| moduleCode | <code>String</code> | The module code of the SWORD module. |
|
|
468
|
+
| bookCode | <code>String</code> | The book code of the SWORD module. |
|
|
469
|
+
|
|
441
470
|
<a name="NodeSwordInterface+getBibleText"></a>
|
|
442
471
|
|
|
443
472
|
### nodeSwordInterface.getBibleText(moduleCode) ⇒ [<code>Array.<VerseObject></code>](#VerseObject)
|
package/index.js
CHANGED
|
@@ -416,12 +416,54 @@ class NodeSwordInterface {
|
|
|
416
416
|
*
|
|
417
417
|
* @param {String} moduleCode
|
|
418
418
|
* @param {String} bookCode
|
|
419
|
-
* @param {
|
|
419
|
+
* @param {Number} startVerseNumber
|
|
420
|
+
* @param {Number} verseCount
|
|
420
421
|
*
|
|
421
422
|
* @return {VerseObject[]}
|
|
422
423
|
*/
|
|
423
|
-
getBookHeaderList(moduleCode, bookCode,
|
|
424
|
-
|
|
424
|
+
getBookHeaderList(moduleCode, bookCode, startVerseNumber=-1, verseCount=-1) {
|
|
425
|
+
const bookTextJson = this.nativeInterface.getBookText(moduleCode, bookCode, startVerseNumber, verseCount);
|
|
426
|
+
|
|
427
|
+
let bookTextHtml = "<div>";
|
|
428
|
+
bookTextJson.forEach((verse) => { bookTextHtml += verse.content; });
|
|
429
|
+
bookTextHtml += "</div>";
|
|
430
|
+
|
|
431
|
+
const HTMLParser = require('node-html-parser');
|
|
432
|
+
const root = HTMLParser.parse(bookTextHtml);
|
|
433
|
+
const rawSectionHeaders = root.querySelectorAll('.sword-section-title');
|
|
434
|
+
let sectionHeaders = [];
|
|
435
|
+
|
|
436
|
+
rawSectionHeaders.forEach((header) => {
|
|
437
|
+
let newSectionHeader = {};
|
|
438
|
+
|
|
439
|
+
newSectionHeader['moduleCode'] = moduleCode;
|
|
440
|
+
newSectionHeader['bibleBookShortTitle'] = bookCode;
|
|
441
|
+
newSectionHeader['type'] = header._attrs.type;
|
|
442
|
+
newSectionHeader['subType'] = header._attrs.subtype;
|
|
443
|
+
newSectionHeader['chapter'] = header._attrs.chapter;
|
|
444
|
+
newSectionHeader['verseNr'] = header._attrs.verse;
|
|
445
|
+
|
|
446
|
+
let content = "";
|
|
447
|
+
|
|
448
|
+
// You may expect that a header only has one child node (the text). But there are modules like the NET Bible
|
|
449
|
+
// where the header actually contains several child nodes and some of them are Strongs elements.
|
|
450
|
+
// Therefore, we have to go through individually and also differentiate between text nodes and other types of nodes.
|
|
451
|
+
for (let i = 0; i < header.childNodes.length; i++) {
|
|
452
|
+
let currentNode = header.childNodes[i];
|
|
453
|
+
|
|
454
|
+
if (currentNode.nodeType == HTMLParser.NodeType.TEXT_NODE) {
|
|
455
|
+
content += currentNode._rawText;
|
|
456
|
+
} else {
|
|
457
|
+
content += currentNode.firstChild._rawText;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
newSectionHeader['content'] = content;
|
|
462
|
+
|
|
463
|
+
sectionHeaders.push(newSectionHeader);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
return sectionHeaders;
|
|
425
467
|
}
|
|
426
468
|
|
|
427
469
|
/**
|
|
@@ -445,6 +487,25 @@ class NodeSwordInterface {
|
|
|
445
487
|
return this.nativeInterface.getChapterVerseCount(moduleCode, bookCode, chapter);
|
|
446
488
|
}
|
|
447
489
|
|
|
490
|
+
/**
|
|
491
|
+
* Returns an array with the chapter verse counts of all chapters of a given book.
|
|
492
|
+
*
|
|
493
|
+
* @param {String} moduleCode
|
|
494
|
+
* @param {String} bookCode
|
|
495
|
+
* @returns {Number} chapterVerseCounts
|
|
496
|
+
*/
|
|
497
|
+
getAllChapterVerseCounts(moduleCode, bookCode) {
|
|
498
|
+
let chapterVerseCounts = [];
|
|
499
|
+
|
|
500
|
+
let bookChapterCount = this.nativeInterface.getBookChapterCount(moduleCode, bookCode);
|
|
501
|
+
for (let i = 0; i < bookChapterCount; i++) {
|
|
502
|
+
let currentChapterVerseCount = this.nativeInterface.getChapterVerseCount(moduleCode, bookCode, i);
|
|
503
|
+
chapterVerseCounts.push(currentChapterVerseCount);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return chapterVerseCounts;
|
|
507
|
+
}
|
|
508
|
+
|
|
448
509
|
/**
|
|
449
510
|
* Returns the number verses in the given book.
|
|
450
511
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-sword-interface",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "Javascript (N-API) interface to SWORD library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"C++",
|
|
@@ -23,14 +23,15 @@
|
|
|
23
23
|
"license": "GPL-2.0+",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"glob": "^8.0.3",
|
|
26
|
-
"node-addon-api": "^7.1.0"
|
|
26
|
+
"node-addon-api": "^7.1.0",
|
|
27
|
+
"node-html-parser": "^6.1.13"
|
|
27
28
|
},
|
|
28
29
|
"repository": {
|
|
29
30
|
"type": "git",
|
|
30
31
|
"url": "https://github.com/ezra-project/node-sword-interface.git"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"jsdoc-to-markdown": "^8.0.
|
|
34
|
+
"jsdoc-to-markdown": "^8.0.3",
|
|
34
35
|
"node-gyp": "^9.1.0"
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -98,7 +98,6 @@ Napi::Object NodeSwordInterface::Init(Napi::Env env, Napi::Object exports)
|
|
|
98
98
|
InstanceMethod("getReferencesFromReferenceRange", &NodeSwordInterface::getReferencesFromReferenceRange),
|
|
99
99
|
InstanceMethod("getBookList", &NodeSwordInterface::getBookList),
|
|
100
100
|
InstanceMethod("getBookChapterCount", &NodeSwordInterface::getBookChapterCount),
|
|
101
|
-
InstanceMethod("getBookHeaderList", &NodeSwordInterface::getBookHeaderList),
|
|
102
101
|
InstanceMethod("getChapterVerseCount", &NodeSwordInterface::getChapterVerseCount),
|
|
103
102
|
InstanceMethod("getBookIntroduction", &NodeSwordInterface::getBookIntroduction),
|
|
104
103
|
InstanceMethod("moduleHasBook", &NodeSwordInterface::moduleHasBook),
|
|
@@ -668,26 +667,6 @@ Napi::Value NodeSwordInterface::getBookChapterCount(const Napi::CallbackInfo& in
|
|
|
668
667
|
return bookChapterCount;
|
|
669
668
|
}
|
|
670
669
|
|
|
671
|
-
Napi::Value NodeSwordInterface::getBookHeaderList(const Napi::CallbackInfo& info)
|
|
672
|
-
{
|
|
673
|
-
lockApi();
|
|
674
|
-
Napi::Env env = info.Env();
|
|
675
|
-
INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string, ParamType::boolean);
|
|
676
|
-
Napi::String moduleName = info[0].As<Napi::String>();
|
|
677
|
-
Napi::String bookCode = info[1].As<Napi::String>();
|
|
678
|
-
Napi::Boolean withAbsoluteVerseNumbers = info[2].As<Napi::Boolean>();
|
|
679
|
-
|
|
680
|
-
#ifdef _WIN32
|
|
681
|
-
Napi::Array headerList = Napi::Array::New(env, 0);
|
|
682
|
-
#else
|
|
683
|
-
vector<Verse> rawHeaderList = this->_textProcessor->getBookHeaderList(moduleName, bookCode, withAbsoluteVerseNumbers);
|
|
684
|
-
Napi::Array headerList = this->_napiSwordHelper->getNapiVerseObjectsFromRawList(env, string(moduleName), rawHeaderList);
|
|
685
|
-
#endif
|
|
686
|
-
|
|
687
|
-
unlockApi();
|
|
688
|
-
return headerList;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
670
|
Napi::Value NodeSwordInterface::getChapterVerseCount(const Napi::CallbackInfo& info)
|
|
692
671
|
{
|
|
693
672
|
lockApi();
|
|
@@ -79,7 +79,6 @@ private:
|
|
|
79
79
|
Napi::Value getReferencesFromReferenceRange(const Napi::CallbackInfo& info);
|
|
80
80
|
Napi::Value getBookList(const Napi::CallbackInfo& info);
|
|
81
81
|
Napi::Value getBookChapterCount(const Napi::CallbackInfo& info);
|
|
82
|
-
Napi::Value getBookHeaderList(const Napi::CallbackInfo& info);
|
|
83
82
|
Napi::Value getChapterVerseCount(const Napi::CallbackInfo& info);
|
|
84
83
|
Napi::Value getBookIntroduction(const Napi::CallbackInfo& info);
|
|
85
84
|
Napi::Value moduleHasBook(const Napi::CallbackInfo& info);
|
package/src/node_sword_cli.cpp
CHANGED
|
@@ -126,14 +126,6 @@ void get_book_list(ModuleHelper& module_helper)
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
void get_book_headers(TextProcessor& text_processor)
|
|
130
|
-
{
|
|
131
|
-
vector<Verse> headerList = text_processor.getBookHeaderList("NASB", "John");
|
|
132
|
-
for (int i = 0; i < headerList.size(); i++) {
|
|
133
|
-
cout << headerList[i].content << endl;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
129
|
void test_unlock_key(ModuleInstaller& module_installer, ModuleStore& module_store, TextProcessor& text_processor)
|
|
138
130
|
{
|
|
139
131
|
module_installer.uninstallModule("NA28");
|
|
@@ -236,8 +228,6 @@ int main(int argc, char** argv)
|
|
|
236
228
|
|
|
237
229
|
//get_updated_repo_modules(repoInterface);
|
|
238
230
|
|
|
239
|
-
/*get_book_headers(textProcessor);*/
|
|
240
|
-
|
|
241
231
|
return 0;
|
|
242
232
|
}
|
|
243
233
|
|
|
@@ -519,75 +519,6 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
|
|
|
519
519
|
return filteredText;
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
-
vector<Verse> TextProcessor::getBookHeaderList(string moduleName, string bookCode, bool withAbsoluteVerseNumbers)
|
|
523
|
-
{
|
|
524
|
-
vector<Verse> headerList;
|
|
525
|
-
SWModule* module = this->_moduleStore.getLocalModule(moduleName);
|
|
526
|
-
|
|
527
|
-
if (module == 0) {
|
|
528
|
-
cerr << "getBookHeaderList: getLocalModule returned zero pointer for " << moduleName << endl;
|
|
529
|
-
} else {
|
|
530
|
-
map<string, int> absoluteVerseNumbers;
|
|
531
|
-
|
|
532
|
-
if (withAbsoluteVerseNumbers) {
|
|
533
|
-
absoluteVerseNumbers = this->_moduleHelper.getAbsoluteVerseNumberMap(module, { bookCode });
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
ListKey scopeList = VerseKey().parseVerseList(bookCode.c_str(), "", true);
|
|
537
|
-
SWKey* scope = &scopeList;
|
|
538
|
-
|
|
539
|
-
ListKey resultKey = module->search("/Heading", SWModule::SEARCHTYPE_ENTRYATTR, 0, scope);
|
|
540
|
-
|
|
541
|
-
static string titleStartElementFilter = "<title";
|
|
542
|
-
static string titleEndElementFilter = "</title>";
|
|
543
|
-
static string divTitleElementFilter = "<div class=\"title\"";
|
|
544
|
-
static string secHeadClassFilter = "class=\"sechead\"";
|
|
545
|
-
|
|
546
|
-
for (resultKey = TOP; !resultKey.popError(); resultKey++) {
|
|
547
|
-
module->setKey(resultKey);
|
|
548
|
-
module->renderText();
|
|
549
|
-
|
|
550
|
-
VerseKey currentKey(resultKey.getShortText());
|
|
551
|
-
|
|
552
|
-
// get both Preverse and Interverse Headings and just merge them into the same map
|
|
553
|
-
AttributeValue headings = module->getEntryAttributes()["Heading"]["Preverse"];
|
|
554
|
-
AttributeValue interverseHeadings = module->getEntryAttributes()["Heading"]["Interverse"];
|
|
555
|
-
headings.insert(interverseHeadings.begin(), interverseHeadings.end());
|
|
556
|
-
|
|
557
|
-
stringstream currentHeaderTextStream;
|
|
558
|
-
|
|
559
|
-
Verse currentHeader;
|
|
560
|
-
currentHeader.reference = module->getKey()->getShortText();
|
|
561
|
-
currentHeader.absoluteVerseNumber = -1;
|
|
562
|
-
if (withAbsoluteVerseNumbers) {
|
|
563
|
-
currentHeader.absoluteVerseNumber = absoluteVerseNumbers[currentHeader.reference];
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
for (AttributeValue::const_iterator it = headings.begin(); it != headings.end(); ++it) {
|
|
567
|
-
currentHeaderTextStream << it->second << endl;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
string currentHeaderText = currentHeaderTextStream.str();
|
|
571
|
-
stringstream sectionTitleElement;
|
|
572
|
-
sectionTitleElement << "<div class=\"sword-markup sword-section-title\" ";
|
|
573
|
-
sectionTitleElement << "chapter=\"" << currentKey.getChapter() << "\"";
|
|
574
|
-
this->findAndReplaceAll(currentHeaderText, titleStartElementFilter, sectionTitleElement.str());
|
|
575
|
-
this->findAndReplaceAll(currentHeaderText, divTitleElementFilter, sectionTitleElement.str());
|
|
576
|
-
|
|
577
|
-
stringstream secHead;
|
|
578
|
-
secHead << "class=\"sword-markup sword-section-title\" ";
|
|
579
|
-
secHead << "chapter=\"" << currentKey.getChapter() << "\"";
|
|
580
|
-
this->findAndReplaceAll(currentHeaderText, secHeadClassFilter, secHead.str());
|
|
581
|
-
this->findAndReplaceAll(currentHeaderText, titleEndElementFilter, "</div>");
|
|
582
|
-
|
|
583
|
-
currentHeader.content = currentHeaderText;
|
|
584
|
-
headerList.push_back(currentHeader);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
return headerList;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
522
|
string TextProcessor::replaceSpacesInStrongs(const string& text)
|
|
592
523
|
{
|
|
593
524
|
string input = text;
|
|
@@ -46,7 +46,6 @@ public:
|
|
|
46
46
|
std::vector<std::string> getReferencesFromReferenceRange(std::string referenceRange);
|
|
47
47
|
std::string getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasInconsistentClosingEndDivs=false, bool forceNoMarkup=false);
|
|
48
48
|
std::string getBookIntroduction(std::string moduleName, std::string bookCode);
|
|
49
|
-
std::vector<Verse> getBookHeaderList(std::string moduleName, std::string bookCode, bool withAbsoluteVerseNumbers=false);
|
|
50
49
|
|
|
51
50
|
StrongsEntry* getStrongsEntry(std::string key);
|
|
52
51
|
|