node-sword-interface 0.245.0 → 0.249.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "0.245.0",
3
+ "version": "0.249.0",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -114,6 +114,14 @@ void get_book_list(ModuleHelper& module_helper)
114
114
  }
115
115
  }
116
116
 
117
+ void get_book_headers(TextProcessor& text_processor)
118
+ {
119
+ vector<Verse> headerList = text_processor.getBookHeaderList("NASB", "John");
120
+ for (int i = 0; i < headerList.size(); i++) {
121
+ cout << headerList[i].content << endl;
122
+ }
123
+ }
124
+
117
125
  void test_unlock_key(ModuleInstaller& module_installer, ModuleStore& module_store, TextProcessor& text_processor)
118
126
  {
119
127
  module_installer.uninstallModule("NA28");
@@ -206,11 +214,13 @@ int main(int argc, char** argv)
206
214
  //string translation = sword_facade.getSwordTranslation(string("/usr/share/sword/locales.d"), string("de"), string("locales"));
207
215
  //cout << translation << endl;
208
216
 
209
- vector<Verse> searchResults = moduleSearch.getModuleSearchResults("NASB", "faith", SearchType::multiWord, SearchScope::NT, true);
217
+ /*vector<Verse> searchResults = moduleSearch.getModuleSearchResults("NASB", "faith", SearchType::multiWord, SearchScope::NT, true);
210
218
  cout << "Got " << searchResults.size() << " results!" << endl;
211
219
  for (unsigned int i=0; i < searchResults.size(); i++) {
212
220
  cout << searchResults[i].reference << endl;
213
- }
221
+ }*/
222
+
223
+ get_book_headers(textProcessor);
214
224
 
215
225
  return 0;
216
226
  }
@@ -36,8 +36,6 @@
36
36
  using namespace std;
37
37
  using namespace sword;
38
38
 
39
- #define SEARCHTYPE_ENTRYATTR -3L
40
-
41
39
  TextProcessor::TextProcessor(ModuleStore& moduleStore, ModuleHelper& moduleHelper)
42
40
  : _moduleStore(moduleStore), _moduleHelper(moduleHelper)
43
41
  {
@@ -45,7 +43,7 @@ TextProcessor::TextProcessor(ModuleStore& moduleStore, ModuleHelper& moduleHelpe
45
43
  this->_rawMarkupEnabled = false;
46
44
  }
47
45
 
48
- string TextProcessor::getFilteredText(const string& text, int chapter, bool hasStrongs, bool hasDuplicateClosingEndDivs)
46
+ string TextProcessor::getFilteredText(const string& text, int chapter, int verseNr, bool hasStrongs, bool hasDuplicateClosingEndDivs)
49
47
  {
50
48
  //static regex schlachterMarkupFilter = regex("<H.*> ");
51
49
  static string chapterFilter = "<chapter";
@@ -72,6 +70,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, bool hasS
72
70
  static string quoteElementFilter = "<q ";
73
71
  static string titleStartElementFilter = "<title";
74
72
  static string titleEndElementFilter = "</title>";
73
+ static string segStartElementFilter = "<seg>";
74
+ static string segEndElementFilter = "</seg>";
75
75
  static string divTitleElementFilter = "<div class=\"title\"";
76
76
  static string secHeadClassFilter = "class=\"sechead\"";
77
77
  static string divMilestoneFilter = "<div type=\"x-milestone\"";
@@ -128,7 +128,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, bool hasS
128
128
 
129
129
  stringstream sectionTitleElement;
130
130
  sectionTitleElement << "<div class=\"sword-markup sword-section-title\" ";
131
- sectionTitleElement << "chapter=\"" << chapter << "\"";
131
+ sectionTitleElement << "chapter=\"" << chapter << "\" ";
132
+ sectionTitleElement << "verse=\"" << verseNr << "\"";
132
133
  this->findAndReplaceAll(filteredText, titleStartElementFilter, sectionTitleElement.str());
133
134
  this->findAndReplaceAll(filteredText, divTitleElementFilter, sectionTitleElement.str());
134
135
 
@@ -138,6 +139,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, bool hasS
138
139
  this->findAndReplaceAll(filteredText, secHeadClassFilter, secHead.str());
139
140
 
140
141
  this->findAndReplaceAll(filteredText, titleEndElementFilter, "</div>");
142
+ this->findAndReplaceAll(filteredText, segStartElementFilter, "");
143
+ this->findAndReplaceAll(filteredText, segEndElementFilter, "");
141
144
  this->findAndReplaceAll(filteredText, divMilestoneFilter, "<div class=\"sword-markup sword-x-milestone\"");
142
145
  this->findAndReplaceAll(filteredText, milestoneFilter, "<div class=\"sword-markup sword-milestone\"");
143
146
  this->findAndReplaceAll(filteredText, xBrFilter, "x-br\"/> ");
@@ -183,7 +186,7 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
183
186
  string chapterHeading = "";
184
187
  VerseKey currentVerseKey = module->getKey();
185
188
  int currentChapter = currentVerseKey.getChapter();
186
- int currentVerse = currentVerseKey.getVerse();
189
+ int currentVerseNr = currentVerseKey.getVerse();
187
190
 
188
191
  if (currentVerseKey.getVerse() == 1) { // X:1, set key to X:0
189
192
  // Include chapter/book/testament/module intros
@@ -203,10 +206,10 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
203
206
  if (this->_markupEnabled && !this->_rawMarkupEnabled) {
204
207
  // The chapter headings in the ISV are screwed up somehow for 1:1
205
208
  // Therefore we do not render chapter headings for the first verse of the book in this case.
206
- if (currentChapter == 1 && currentVerse == 1 && currentModuleName == "ISV") {
209
+ if (currentChapter == 1 && currentVerseNr == 1 && currentModuleName == "ISV") {
207
210
  chapterHeading = "";
208
211
  } else {
209
- chapterHeading = this->getFilteredText(chapterHeading, currentChapter);
212
+ chapterHeading = this->getFilteredText(chapterHeading, currentChapter, currentVerseNr);
210
213
  }
211
214
  }
212
215
 
@@ -221,12 +224,13 @@ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStron
221
224
  if (this->_markupEnabled && !forceNoMarkup) {
222
225
  VerseKey currentVerseKey = module->getKey();
223
226
  int currentChapter = currentVerseKey.getChapter();
227
+ int currentVerseNr = currentVerseKey.getVerse();
224
228
  verseText = string(module->getRawEntry());
225
229
  StringHelper::trim(verseText);
226
230
  filteredText = verseText;
227
231
 
228
232
  if (!this->_rawMarkupEnabled) {
229
- filteredText = this->getFilteredText(verseText, currentChapter, hasStrongs, hasDuplicateClosingEndDivs);
233
+ filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasDuplicateClosingEndDivs);
230
234
  }
231
235
  } else {
232
236
  verseText = string(module->stripText());
@@ -426,12 +430,13 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
426
430
  if (module == 0) {
427
431
  cerr << "getLocalModule returned zero pointer for " << moduleName << endl;
428
432
  } else {
429
- VerseKey verseKey(bookCode.c_str());
433
+ module->setKeyText(bookCode.c_str());
434
+ VerseKey *verseKey = (VerseKey *)module->getKey();
430
435
 
431
436
  // Include chapter/book/testament/module intros
432
- verseKey.setIntros(true);
433
- verseKey.setChapter(0);
434
- verseKey.setVerse(0);
437
+ verseKey->setIntros(true);
438
+ verseKey->setChapter(0);
439
+ verseKey->setVerse(0);
435
440
  module->setKey(verseKey);
436
441
 
437
442
  bookIntroText = string(module->getRawEntry());
@@ -475,7 +480,7 @@ vector<Verse> TextProcessor::getBookHeaderList(string moduleName, string bookCod
475
480
  ListKey scopeList = VerseKey().parseVerseList(bookCode.c_str(), "", true);
476
481
  SWKey* scope = &scopeList;
477
482
 
478
- ListKey resultKey = module->search("/Heading", SEARCHTYPE_ENTRYATTR, 0, scope);
483
+ ListKey resultKey = module->search("/Heading", SWModule::SEARCHTYPE_ENTRYATTR, 0, scope);
479
484
 
480
485
  static string titleStartElementFilter = "<title";
481
486
  static string titleEndElementFilter = "</title>";
@@ -484,6 +489,8 @@ vector<Verse> TextProcessor::getBookHeaderList(string moduleName, string bookCod
484
489
 
485
490
  for (resultKey = TOP; !resultKey.popError(); resultKey++) {
486
491
  module->setKey(resultKey);
492
+ module->renderText();
493
+
487
494
  VerseKey currentKey(resultKey.getShortText());
488
495
 
489
496
  // get both Preverse and Interverse Headings and just merge them into the same map
@@ -60,7 +60,7 @@ private:
60
60
  int verseCount=-1);
61
61
 
62
62
  std::string getCurrentChapterHeading(sword::SWModule* module);
63
- std::string getFilteredText(const std::string& text, int chapter, bool hasStrongs=false, bool hasDuplicateClosingEndDivs=false);
63
+ std::string getFilteredText(const std::string& text, int chapter, int verseNr, bool hasStrongs=false, bool hasDuplicateClosingEndDivs=false);
64
64
  std::string replaceSpacesInStrongs(const std::string& text);
65
65
  unsigned int findAndReplaceAll(std::string & data, std::string toSearch, std::string replaceStr);
66
66