node-sword-interface 1.0.1 → 1.0.3

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": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -187,7 +187,7 @@ int NodeSwordInterface::validateParams(const Napi::CallbackInfo& info, vector<Pa
187
187
  Napi::Env env = info.Env();
188
188
 
189
189
  if (info.Length() != paramSpec.size()) {
190
- string paramCountError = "Expected " + to_string(paramSpec.size()) + " parameters, but got " += to_string(info.Length()) + "!";
190
+ string paramCountError = "Expected " + to_string(paramSpec.size()) + " parameters, but got " + to_string(info.Length()) + "!";
191
191
  Napi::TypeError::New(env, paramCountError).ThrowAsJavaScriptException();
192
192
  return -1;
193
193
  } else {
@@ -210,9 +210,9 @@ bool ModuleHelper::isBrokenMarkupModule(std::string moduleName)
210
210
  moduleName) != this->_brokenMarkupModules.end();
211
211
  }
212
212
 
213
- bool ModuleHelper::isDuplicateClosingEndDivModule(std::string moduleName)
213
+ bool ModuleHelper::isInconsistentClosingEndDivModule(std::string moduleName)
214
214
  {
215
- return std::find(this->_duplicateClosingEndDivModules.begin(),
216
- this->_duplicateClosingEndDivModules.end(),
217
- moduleName) != this->_duplicateClosingEndDivModules.end();
215
+ return std::find(this->_inconsistentClosingEndDivModules.begin(),
216
+ this->_inconsistentClosingEndDivModules.end(),
217
+ moduleName) != this->_inconsistentClosingEndDivModules.end();
218
218
  }
@@ -34,8 +34,8 @@ public:
34
34
  // For modules in this list we will enforce the stripped version of the text and not use the markup
35
35
  this->_brokenMarkupModules = { "ASV" };
36
36
 
37
- // For modules in this list we will remove the duplicate closing end divs from the markup
38
- this->_duplicateClosingEndDivModules = { "NETtext" };
37
+ // For modules in this list we will balance the closing end divs in the markup
38
+ this->_inconsistentClosingEndDivModules = { "NETtext", "NASB" };
39
39
  }
40
40
 
41
41
  virtual ~ModuleHelper(){}
@@ -50,13 +50,13 @@ public:
50
50
  int getChapterVerseCount(std::string moduleName, std::string bookCode, int chapter);
51
51
  std::map<std::string, int> getAbsoluteVerseNumberMap(sword::SWModule* module, std::vector<std::string> bookList={});
52
52
  bool isBrokenMarkupModule(std::string moduleName);
53
- bool isDuplicateClosingEndDivModule(std::string moduleName);
53
+ bool isInconsistentClosingEndDivModule(std::string moduleName);
54
54
 
55
55
  private:
56
56
  bool moduleHasKeyValuePair(sword::SWModule* module, std::string key, std::string value);
57
57
  ModuleStore& _moduleStore;
58
58
  std::vector<std::string> _brokenMarkupModules;
59
- std::vector<std::string> _duplicateClosingEndDivModules;
59
+ std::vector<std::string> _inconsistentClosingEndDivModules;
60
60
  };
61
61
 
62
62
  #endif // _MODULE_HELPER
@@ -88,10 +88,9 @@ int ModuleInstaller::installModule(string repoName, string moduleName)
88
88
  this->resetAllMgrs();
89
89
 
90
90
  if (result != 0) {
91
- //cerr << "Error installing module: " << moduleName << " (write permissions?)" << endl;
91
+ // cerr << "Error installing module: " << moduleName << " (write permissions?)" << endl;
92
92
  return result;
93
93
  } else {
94
- //cout << "Installed module: " << moduleName << endl;
95
94
  return 0;
96
95
  }
97
96
  }
@@ -109,10 +108,9 @@ int ModuleInstaller::uninstallModule(string moduleName)
109
108
  this->_moduleStore.deleteModule(moduleName);
110
109
 
111
110
  if (error) {
112
- cerr << "Error uninstalling module: " << moduleName << " (write permissions?)" << endl;
111
+ // cerr << "Error uninstalling module: " << moduleName << " (write permissions?)" << endl;
113
112
  return -1;
114
113
  } else {
115
- cout << "Uninstalled module: " << moduleName << endl;
116
114
  return 0;
117
115
  }
118
116
  }
@@ -43,9 +43,8 @@ TextProcessor::TextProcessor(ModuleStore& moduleStore, ModuleHelper& moduleHelpe
43
43
  this->_rawMarkupEnabled = false;
44
44
  }
45
45
 
46
- string TextProcessor::getFilteredText(const string& text, int chapter, int verseNr, bool hasStrongs, bool hasDuplicateClosingEndDivs)
46
+ string TextProcessor::getFilteredText(const string& text, int chapter, int verseNr, bool hasStrongs, bool hasInconsistentClosingEndDivs)
47
47
  {
48
- //static regex schlachterMarkupFilter = regex("<H.*> ");
49
48
  static string chapterFilter = "<chapter";
50
49
  static regex pbElement = regex("<pb .*?/> ");
51
50
 
@@ -68,14 +67,13 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
68
67
  static string pbElementFilter = "<pb";
69
68
  static string quoteJesusElementFilter = "<q marker=\"\" who=\"Jesus\">";
70
69
  static string quoteElementFilter = "<q ";
70
+ static string quoteEndElementFilter = "</q>";
71
71
  static string titleStartElementFilter = "<title";
72
72
  static string titleEndElementFilter = "</title>";
73
- static string segStartElementFilter = "<seg>";
74
73
  static string segEndElementFilter = "</seg>";
75
74
  static string divTitleElementFilter = "<div class=\"title\"";
76
75
  static string secHeadClassFilter = "class=\"sechead\"";
77
76
  static string divMilestoneFilter = "<div type=\"x-milestone\"";
78
- static string milestoneFilter = "<milestone";
79
77
  static string xBrFilter = "x-br\"/>";
80
78
  static string divSIDFilter = "<div sID=";
81
79
  static string divEIDFilter = "<div eID=";
@@ -83,6 +81,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
83
81
  static string divineNameEndElement = "</divineName>";
84
82
  static string strongsWElement = "<w lemma=";
85
83
 
84
+ static regex milestoneFilter = regex("<milestone.*?/>");
85
+ static regex segStartElementFilter = regex("<seg.*?>");
86
86
  static regex divSectionElementFilter = regex("<div type=\"section\".*?>");
87
87
  static regex selfClosingElement = regex("(<)([wdiv]{1,3}) ([\\w:=\"\\- ]*?)(/>)");
88
88
 
@@ -105,7 +105,6 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
105
105
  filteredText.replace(0, noteTypeVariant.length(), "");
106
106
  }
107
107
 
108
- //filteredText = regex_replace(filteredText, schlachterMarkupFilter, "");
109
108
  this->findAndReplaceAll(filteredText, chapterFilter, "<chapter class=\"sword-markup sword-chapter\"");
110
109
  this->findAndReplaceAll(filteredText, lbBeginParagraph, "");
111
110
  this->findAndReplaceAll(filteredText, lbEndParagraph, "&nbsp;<div class=\"sword-markup sword-paragraph-end\"><br></div>");
@@ -124,6 +123,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
124
123
  this->findAndReplaceAll(filteredText, rtxtStartElementFilter2, "<div class=\"sword-markup sword-rtxt\" rend=");
125
124
  this->findAndReplaceAll(filteredText, rtxtEndElementFilter, "</div>");
126
125
  this->findAndReplaceAll(filteredText, pbElementFilter, "<pb class=\"sword-markup sword-pb\"");
126
+ filteredText = regex_replace(filteredText, milestoneFilter, "");
127
+ filteredText = regex_replace(filteredText, segStartElementFilter, "");
127
128
  filteredText = regex_replace(filteredText, divSectionElementFilter, "");
128
129
 
129
130
  stringstream sectionTitleElement;
@@ -147,15 +148,14 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
147
148
  }
148
149
 
149
150
  this->findAndReplaceAll(filteredText, titleEndElementFilter, "</div>");
150
- this->findAndReplaceAll(filteredText, segStartElementFilter, "");
151
151
  this->findAndReplaceAll(filteredText, segEndElementFilter, "");
152
152
  this->findAndReplaceAll(filteredText, divMilestoneFilter, "<div class=\"sword-markup sword-x-milestone\"");
153
- this->findAndReplaceAll(filteredText, milestoneFilter, "<div class=\"sword-markup sword-milestone\"");
154
153
  this->findAndReplaceAll(filteredText, xBrFilter, "x-br\"/> ");
155
154
  this->findAndReplaceAll(filteredText, divSIDFilter, "<div class=\"sword-markup sword-sid\" sID=");
156
155
  this->findAndReplaceAll(filteredText, divEIDFilter, "<div class=\"sword-markup sword-eid\" eID=");
157
- this->findAndReplaceAll(filteredText, quoteJesusElementFilter, "<div class=\"sword-markup sword-quote-jesus\"/>");
158
- this->findAndReplaceAll(filteredText, quoteElementFilter, "&quot;<div class=\"sword-markup sword-quote\" ");
156
+ this->findAndReplaceAll(filteredText, quoteJesusElementFilter, "<div class=\"sword-markup sword-quote-jesus\">");
157
+ this->findAndReplaceAll(filteredText, quoteElementFilter, "<div class=\"sword-markup sword-quote\" ");
158
+ this->findAndReplaceAll(filteredText, quoteEndElementFilter, "</div>");
159
159
  this->findAndReplaceAll(filteredText, divineNameStartElement, "");
160
160
  this->findAndReplaceAll(filteredText, divineNameEndElement, "");
161
161
  this->findAndReplaceAll(filteredText, strongsWElement, "<w class=");
@@ -169,15 +169,30 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
169
169
  this->findAndReplaceAll(filteredText, semiColonWithoutSpace, "; <");
170
170
  this->findAndReplaceAll(filteredText, colonWithoutSpace, ": <");
171
171
 
172
- if (hasDuplicateClosingEndDivs) {
172
+ if (hasInconsistentClosingEndDivs) {
173
173
  int numberOfOpeningDivs = StringHelper::numberOfSubstrings(filteredText, "<div");
174
174
  int numberOfClosingDivs = StringHelper::numberOfSubstrings(filteredText, "</div>");
175
175
 
176
- // Remove the last closing div if the number of closing divs is higher than the number of opening divs
176
+ // Remove the last closing div(s) if the number of closing divs is higher than the number of opening divs
177
177
  if (numberOfClosingDivs > numberOfOpeningDivs) {
178
178
  const string closingDiv = "</div>";
179
- size_t lastClosingDivOffset = filteredText.rfind(closingDiv);
180
- filteredText.replace(lastClosingDivOffset, closingDiv.length(), "");
179
+ unsigned int diff = numberOfClosingDivs - numberOfOpeningDivs;
180
+
181
+ for (unsigned int i = 0; i < diff; i++) {
182
+ size_t lastClosingDivOffset = filteredText.rfind(closingDiv);
183
+ filteredText.erase(lastClosingDivOffset, closingDiv.length());
184
+ }
185
+ }
186
+
187
+ // Add closing div(s) if the number of closing divs is smaller than the number of opening divs
188
+ if (numberOfClosingDivs < numberOfOpeningDivs) {
189
+ const string closingDiv = "</div>";
190
+ unsigned int diff = numberOfOpeningDivs - numberOfClosingDivs;
191
+
192
+ for (unsigned int i = 0; i < diff; i++) {
193
+ size_t lastClosingDivOffset = filteredText.rfind(closingDiv);
194
+ filteredText.insert(lastClosingDivOffset + closingDiv.length(), closingDiv);
195
+ }
181
196
  }
182
197
  }
183
198
 
@@ -224,7 +239,7 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
224
239
  return chapterHeading;
225
240
  }
226
241
 
227
- string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasDuplicateClosingEndDivs, bool forceNoMarkup)
242
+ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasInconsistentClosingEndDivs, bool forceNoMarkup)
228
243
  {
229
244
  string verseText;
230
245
  string filteredText;
@@ -238,7 +253,7 @@ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStron
238
253
  filteredText = verseText;
239
254
 
240
255
  if (!this->_rawMarkupEnabled) {
241
- filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasDuplicateClosingEndDivs);
256
+ filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasInconsistentClosingEndDivs);
242
257
  }
243
258
  } else {
244
259
  verseText = string(module->stripText());
@@ -300,7 +315,7 @@ vector<Verse> TextProcessor::getVersesFromReferences(string moduleName, vector<s
300
315
  vector<string> bookList = this->getBookListFromReferences(references);
301
316
  map<string, int> absoluteVerseNumbers = this->_moduleHelper.getAbsoluteVerseNumberMap(module, bookList);
302
317
  bool moduleMarkupIsBroken = this->_moduleHelper.isBrokenMarkupModule(moduleName);
303
- bool hasDuplicateClosingEndDivs = this->_moduleHelper.isDuplicateClosingEndDivModule(moduleName);
318
+ bool hasInconsistentClosingEndDivs = this->_moduleHelper.isInconsistentClosingEndDivModule(moduleName);
304
319
 
305
320
  for (unsigned int i = 0; i < references.size(); i++) {
306
321
  string currentReference = references[i];
@@ -310,7 +325,7 @@ vector<Verse> TextProcessor::getVersesFromReferences(string moduleName, vector<s
310
325
  bool entryExisting = module->hasEntry(module->getKey());
311
326
 
312
327
  if (entryExisting) {
313
- currentVerseText = this->getCurrentVerseText(module, false, hasDuplicateClosingEndDivs, moduleMarkupIsBroken);
328
+ currentVerseText = this->getCurrentVerseText(module, false, hasInconsistentClosingEndDivs, moduleMarkupIsBroken);
314
329
  }
315
330
 
316
331
  Verse currentVerse;
@@ -348,7 +363,7 @@ vector<Verse> TextProcessor::getText(string moduleName, string key, QueryLimit q
348
363
  int lastChapter = -1;
349
364
  bool currentBookExisting = true;
350
365
  bool moduleMarkupIsBroken = this->_moduleHelper.isBrokenMarkupModule(moduleName);
351
- bool hasDuplicateClosingEndDivs = this->_moduleHelper.isDuplicateClosingEndDivModule(moduleName);
366
+ bool hasInconsistentClosingEndDivs = this->_moduleHelper.isInconsistentClosingEndDivModule(moduleName);
352
367
 
353
368
  // This holds the text that we will return
354
369
  vector<Verse> text;
@@ -401,7 +416,7 @@ vector<Verse> TextProcessor::getText(string moduleName, string key, QueryLimit q
401
416
  // Current verse text
402
417
  verseText += this->getCurrentVerseText(module,
403
418
  hasStrongs,
404
- hasDuplicateClosingEndDivs,
419
+ hasInconsistentClosingEndDivs,
405
420
  // Note that if markup is broken this will enforce
406
421
  // the usage of the "stripped" / non-markup variant of the text
407
422
  moduleMarkupIsBroken);
@@ -43,7 +43,7 @@ public:
43
43
  std::vector<Verse> getChapterText(std::string moduleName, std::string bookCode, int chapter);
44
44
  std::vector<Verse> getVersesFromReferences(std::string moduleName, std::vector<std::string>& references);
45
45
  std::vector<std::string> getReferencesFromReferenceRange(std::string referenceRange);
46
- std::string getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasDuplicateClosingEndDivs=false, bool forceNoMarkup=false);
46
+ std::string getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasInconsistentClosingEndDivs=false, bool forceNoMarkup=false);
47
47
  std::string getBookIntroduction(std::string moduleName, std::string bookCode);
48
48
  std::vector<Verse> getBookHeaderList(std::string moduleName, std::string bookCode, bool withAbsoluteVerseNumbers=false);
49
49
 
@@ -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, int verseNr, bool hasStrongs=false, bool hasDuplicateClosingEndDivs=false);
63
+ std::string getFilteredText(const std::string& text, int chapter, int verseNr, bool hasStrongs=false, bool hasInconsistentClosingEndDivs=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