node-sword-interface 1.0.24 → 1.0.26

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 CHANGED
@@ -57,7 +57,7 @@ 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.&lt;VerseObject&gt;</code>](#VerseObject)
58
58
  * [.getReferencesFromReferenceRange(referenceRange)](#NodeSwordInterface+getReferencesFromReferenceRange) ⇒ <code>Array.&lt;String&gt;</code>
59
59
  * [.getBookList(moduleCode)](#NodeSwordInterface+getBookList) ⇒ <code>Array.&lt;String&gt;</code>
60
- * [.getBookHeaderList(moduleCode, bookCode, withAbsoluteVerseNumbers)](#NodeSwordInterface+getBookHeaderList) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
60
+ * [.getBookHeaderList(moduleCode, bookCode, startVerseNumber, verseCount)](#NodeSwordInterface+getBookHeaderList) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
61
61
  * [.getBookChapterCount(moduleCode, bookCode)](#NodeSwordInterface+getBookChapterCount)
62
62
  * [.getChapterVerseCount(moduleCode, bookCode, chapter)](#NodeSwordInterface+getChapterVerseCount)
63
63
  * [.getAllChapterVerseCounts(moduleCode, bookCode)](#NodeSwordInterface+getAllChapterVerseCounts) ⇒ <code>Number</code>
@@ -404,16 +404,17 @@ Returns the list of books available in the given module. By default the book cod
404
404
 
405
405
  <a name="NodeSwordInterface+getBookHeaderList"></a>
406
406
 
407
- ### nodeSwordInterface.getBookHeaderList(moduleCode, bookCode, withAbsoluteVerseNumbers) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
407
+ ### nodeSwordInterface.getBookHeaderList(moduleCode, bookCode, startVerseNumber, verseCount) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
408
408
  Returns the list of headers available in the given book. The headers are returned as an array of VerseObjects.
409
409
 
410
410
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
411
411
 
412
- | Param | Type | Default |
413
- | --- | --- | --- |
414
- | moduleCode | <code>String</code> | |
415
- | bookCode | <code>String</code> | |
416
- | withAbsoluteVerseNumbers | <code>Boolean</code> | <code>false</code> |
412
+ | Param | Type |
413
+ | --- | --- |
414
+ | moduleCode | <code>String</code> |
415
+ | bookCode | <code>String</code> |
416
+ | startVerseNumber | <code>Number</code> |
417
+ | verseCount | <code>Number</code> |
417
418
 
418
419
  <a name="NodeSwordInterface+getBookChapterCount"></a>
419
420
 
package/index.js CHANGED
@@ -416,12 +416,54 @@ class NodeSwordInterface {
416
416
  *
417
417
  * @param {String} moduleCode
418
418
  * @param {String} bookCode
419
- * @param {Boolean} withAbsoluteVerseNumbers
419
+ * @param {Number} startVerseNumber
420
+ * @param {Number} verseCount
420
421
  *
421
422
  * @return {VerseObject[]}
422
423
  */
423
- getBookHeaderList(moduleCode, bookCode, withAbsoluteVerseNumbers=false) {
424
- return this.nativeInterface.getBookHeaderList(moduleCode, bookCode, withAbsoluteVerseNumbers);
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -23,11 +23,12 @@
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
- "url": "https://github.com/ezra-project/node-sword-interface.git"
31
+ "url": "https://github.com/ezra-bible-app/node-sword-interface.git"
31
32
  },
32
33
  "devDependencies": {
33
34
  "jsdoc-to-markdown": "^8.0.3",
@@ -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);
@@ -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
 
@@ -200,7 +200,18 @@ vector<string> RepositoryInterface::getRepoNames()
200
200
  ++it) {
201
201
 
202
202
  string source = string(it->second->caption);
203
+
204
+ #if defined(__ANDROID__)
205
+ // Since August/September 2024 there have been issues observed with the access to the STEP Bible repository.
206
+ // We filter it out here, since it is currently dysfunctional.
207
+ if (source != "STEP Bible") {
208
+ #endif
209
+
203
210
  sourceNames.push_back(source);
211
+
212
+ #if defined(__ANDROID__)
213
+ }
214
+ #endif
204
215
  }
205
216
 
206
217
  return sourceNames;
@@ -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