node-sword-interface 0.246.0 → 0.250.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.246.0",
3
+ "version": "0.250.0",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -70,14 +70,25 @@ bool ModuleHelper::moduleHasKeyValuePair(sword::SWModule* module, std::string ke
70
70
 
71
71
  bool ModuleHelper::moduleHasBook(sword::SWModule* module, std::string bookCode)
72
72
  {
73
- bool hasBook;
73
+ bool hasBook = true;
74
74
  stringstream key;
75
75
  key << bookCode;
76
76
  key << " 1:1";
77
77
 
78
78
  module->setKey(key.str().c_str());
79
- hasBook = module->hasEntry(module->getKey());
80
-
79
+ string moduleKeyText = string(module->getKey()->getShortText());
80
+
81
+ /* In case of apocryphal books the hasEntry method below is not enough.
82
+ Once we have set the key we need to compare the actual module key with the key we wanted to set.
83
+ For apocryphal books we may get "Rev 1:1" as actual module key and this will mismatch with the set key
84
+ and then indicate that the book is not existing. */
85
+
86
+ if (moduleKeyText != key.str()) {
87
+ hasBook = false;
88
+ } else {
89
+ hasBook = module->hasEntry(module->getKey());
90
+ }
91
+
81
92
  return hasBook;
82
93
  }
83
94
 
@@ -43,7 +43,7 @@ TextProcessor::TextProcessor(ModuleStore& moduleStore, ModuleHelper& moduleHelpe
43
43
  this->_rawMarkupEnabled = false;
44
44
  }
45
45
 
46
- 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)
47
47
  {
48
48
  //static regex schlachterMarkupFilter = regex("<H.*> ");
49
49
  static string chapterFilter = "<chapter";
@@ -70,6 +70,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, bool hasS
70
70
  static string quoteElementFilter = "<q ";
71
71
  static string titleStartElementFilter = "<title";
72
72
  static string titleEndElementFilter = "</title>";
73
+ static string segStartElementFilter = "<seg>";
74
+ static string segEndElementFilter = "</seg>";
73
75
  static string divTitleElementFilter = "<div class=\"title\"";
74
76
  static string secHeadClassFilter = "class=\"sechead\"";
75
77
  static string divMilestoneFilter = "<div type=\"x-milestone\"";
@@ -126,7 +128,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, bool hasS
126
128
 
127
129
  stringstream sectionTitleElement;
128
130
  sectionTitleElement << "<div class=\"sword-markup sword-section-title\" ";
129
- sectionTitleElement << "chapter=\"" << chapter << "\"";
131
+ sectionTitleElement << "chapter=\"" << chapter << "\" ";
132
+ sectionTitleElement << "verse=\"" << verseNr << "\"";
130
133
  this->findAndReplaceAll(filteredText, titleStartElementFilter, sectionTitleElement.str());
131
134
  this->findAndReplaceAll(filteredText, divTitleElementFilter, sectionTitleElement.str());
132
135
 
@@ -136,6 +139,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, bool hasS
136
139
  this->findAndReplaceAll(filteredText, secHeadClassFilter, secHead.str());
137
140
 
138
141
  this->findAndReplaceAll(filteredText, titleEndElementFilter, "</div>");
142
+ this->findAndReplaceAll(filteredText, segStartElementFilter, "");
143
+ this->findAndReplaceAll(filteredText, segEndElementFilter, "");
139
144
  this->findAndReplaceAll(filteredText, divMilestoneFilter, "<div class=\"sword-markup sword-x-milestone\"");
140
145
  this->findAndReplaceAll(filteredText, milestoneFilter, "<div class=\"sword-markup sword-milestone\"");
141
146
  this->findAndReplaceAll(filteredText, xBrFilter, "x-br\"/> ");
@@ -181,7 +186,7 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
181
186
  string chapterHeading = "";
182
187
  VerseKey currentVerseKey = module->getKey();
183
188
  int currentChapter = currentVerseKey.getChapter();
184
- int currentVerse = currentVerseKey.getVerse();
189
+ int currentVerseNr = currentVerseKey.getVerse();
185
190
 
186
191
  if (currentVerseKey.getVerse() == 1) { // X:1, set key to X:0
187
192
  // Include chapter/book/testament/module intros
@@ -201,10 +206,10 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
201
206
  if (this->_markupEnabled && !this->_rawMarkupEnabled) {
202
207
  // The chapter headings in the ISV are screwed up somehow for 1:1
203
208
  // Therefore we do not render chapter headings for the first verse of the book in this case.
204
- if (currentChapter == 1 && currentVerse == 1 && currentModuleName == "ISV") {
209
+ if (currentChapter == 1 && currentVerseNr == 1 && currentModuleName == "ISV") {
205
210
  chapterHeading = "";
206
211
  } else {
207
- chapterHeading = this->getFilteredText(chapterHeading, currentChapter);
212
+ chapterHeading = this->getFilteredText(chapterHeading, currentChapter, currentVerseNr);
208
213
  }
209
214
  }
210
215
 
@@ -219,12 +224,13 @@ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStron
219
224
  if (this->_markupEnabled && !forceNoMarkup) {
220
225
  VerseKey currentVerseKey = module->getKey();
221
226
  int currentChapter = currentVerseKey.getChapter();
227
+ int currentVerseNr = currentVerseKey.getVerse();
222
228
  verseText = string(module->getRawEntry());
223
229
  StringHelper::trim(verseText);
224
230
  filteredText = verseText;
225
231
 
226
232
  if (!this->_rawMarkupEnabled) {
227
- filteredText = this->getFilteredText(verseText, currentChapter, hasStrongs, hasDuplicateClosingEndDivs);
233
+ filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasDuplicateClosingEndDivs);
228
234
  }
229
235
  } else {
230
236
  verseText = string(module->stripText());
@@ -424,12 +430,13 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
424
430
  if (module == 0) {
425
431
  cerr << "getLocalModule returned zero pointer for " << moduleName << endl;
426
432
  } else {
427
- VerseKey verseKey(bookCode.c_str());
433
+ module->setKeyText(bookCode.c_str());
434
+ VerseKey *verseKey = (VerseKey *)module->getKey();
428
435
 
429
436
  // Include chapter/book/testament/module intros
430
- verseKey.setIntros(true);
431
- verseKey.setChapter(0);
432
- verseKey.setVerse(0);
437
+ verseKey->setIntros(true);
438
+ verseKey->setChapter(0);
439
+ verseKey->setVerse(0);
433
440
  module->setKey(verseKey);
434
441
 
435
442
  bookIntroText = string(module->getRawEntry());
@@ -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