node-sword-interface 1.0.2 → 1.0.4

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/binding.gyp CHANGED
@@ -112,8 +112,7 @@
112
112
  ],
113
113
  "libraries": [
114
114
  '<(module_root_dir)/sword_build/libsword.a',
115
- '<!@(pkg-config --libs libcurl)',
116
- '<!@(PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig" pkg-config --libs icu-uc icu-io icu-i18n)'
115
+ '<!@(pkg-config --libs libcurl)'
117
116
  ],
118
117
  "dependencies": [
119
118
  "<!(node -p \"require('node-addon-api').gyp\")",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -28,7 +28,7 @@
28
28
  "url": "https://github.com/ezra-project/node-sword-interface.git"
29
29
  },
30
30
  "devDependencies": {
31
- "jsdoc-to-markdown": "^7.1.0",
31
+ "jsdoc-to-markdown": "^8.0.0",
32
32
  "node-gyp": "^8.0.0"
33
33
  }
34
34
  }
@@ -34,18 +34,11 @@ git clone https://github.com/bibletime/crosswire-sword-mirror sword
34
34
  git -C sword checkout 1460f9
35
35
  patch --batch --forward -d sword -p 0 < patch/sword_globconf.patch
36
36
 
37
-
38
37
  # PATCHES
39
38
  case "$(uname -s)" in
40
- # Linux)
41
- # # We only apply the Sword ICU patch on Linux
42
- # patch --batch --forward -d sword -p 0 < patch/sword_icu.patch
43
- # ;;
44
39
  Darwin)
45
40
  # We only apply the following patch on macOS
46
41
  export MACOSX_DEPLOYMENT_TARGET=10.10
47
- export CMAKE_PREFIX_PATH=/usr/local/opt/icu4c
48
- # patch --batch --forward -d sword -p 0 < patch/sword_mac.patch
49
42
  ;;
50
43
  esac
51
44
 
@@ -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
@@ -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
 
@@ -71,12 +70,10 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
71
70
  static string quoteEndElementFilter = "</q>";
72
71
  static string titleStartElementFilter = "<title";
73
72
  static string titleEndElementFilter = "</title>";
74
- static string segStartElementFilter = "<seg>";
75
73
  static string segEndElementFilter = "</seg>";
76
74
  static string divTitleElementFilter = "<div class=\"title\"";
77
75
  static string secHeadClassFilter = "class=\"sechead\"";
78
76
  static string divMilestoneFilter = "<div type=\"x-milestone\"";
79
- static string milestoneFilter = "<milestone";
80
77
  static string xBrFilter = "x-br\"/>";
81
78
  static string divSIDFilter = "<div sID=";
82
79
  static string divEIDFilter = "<div eID=";
@@ -84,6 +81,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
84
81
  static string divineNameEndElement = "</divineName>";
85
82
  static string strongsWElement = "<w lemma=";
86
83
 
84
+ static regex milestoneFilter = regex("<milestone.*?/>");
85
+ static regex segStartElementFilter = regex("<seg.*?>");
87
86
  static regex divSectionElementFilter = regex("<div type=\"section\".*?>");
88
87
  static regex selfClosingElement = regex("(<)([wdiv]{1,3}) ([\\w:=\"\\- ]*?)(/>)");
89
88
 
@@ -106,7 +105,6 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
106
105
  filteredText.replace(0, noteTypeVariant.length(), "");
107
106
  }
108
107
 
109
- //filteredText = regex_replace(filteredText, schlachterMarkupFilter, "");
110
108
  this->findAndReplaceAll(filteredText, chapterFilter, "<chapter class=\"sword-markup sword-chapter\"");
111
109
  this->findAndReplaceAll(filteredText, lbBeginParagraph, "");
112
110
  this->findAndReplaceAll(filteredText, lbEndParagraph, "&nbsp;<div class=\"sword-markup sword-paragraph-end\"><br></div>");
@@ -125,6 +123,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
125
123
  this->findAndReplaceAll(filteredText, rtxtStartElementFilter2, "<div class=\"sword-markup sword-rtxt\" rend=");
126
124
  this->findAndReplaceAll(filteredText, rtxtEndElementFilter, "</div>");
127
125
  this->findAndReplaceAll(filteredText, pbElementFilter, "<pb class=\"sword-markup sword-pb\"");
126
+ filteredText = regex_replace(filteredText, milestoneFilter, "");
127
+ filteredText = regex_replace(filteredText, segStartElementFilter, "");
128
128
  filteredText = regex_replace(filteredText, divSectionElementFilter, "");
129
129
 
130
130
  stringstream sectionTitleElement;
@@ -148,10 +148,8 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
148
148
  }
149
149
 
150
150
  this->findAndReplaceAll(filteredText, titleEndElementFilter, "</div>");
151
- this->findAndReplaceAll(filteredText, segStartElementFilter, "");
152
151
  this->findAndReplaceAll(filteredText, segEndElementFilter, "");
153
152
  this->findAndReplaceAll(filteredText, divMilestoneFilter, "<div class=\"sword-markup sword-x-milestone\"");
154
- this->findAndReplaceAll(filteredText, milestoneFilter, "<div class=\"sword-markup sword-milestone\"");
155
153
  this->findAndReplaceAll(filteredText, xBrFilter, "x-br\"/> ");
156
154
  this->findAndReplaceAll(filteredText, divSIDFilter, "<div class=\"sword-markup sword-sid\" sID=");
157
155
  this->findAndReplaceAll(filteredText, divEIDFilter, "<div class=\"sword-markup sword-eid\" eID=");
@@ -171,15 +169,30 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
171
169
  this->findAndReplaceAll(filteredText, semiColonWithoutSpace, "; <");
172
170
  this->findAndReplaceAll(filteredText, colonWithoutSpace, ": <");
173
171
 
174
- if (hasDuplicateClosingEndDivs) {
172
+ if (hasInconsistentClosingEndDivs) {
175
173
  int numberOfOpeningDivs = StringHelper::numberOfSubstrings(filteredText, "<div");
176
174
  int numberOfClosingDivs = StringHelper::numberOfSubstrings(filteredText, "</div>");
177
175
 
178
- // 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
179
177
  if (numberOfClosingDivs > numberOfOpeningDivs) {
180
178
  const string closingDiv = "</div>";
181
- size_t lastClosingDivOffset = filteredText.rfind(closingDiv);
182
- 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
+ }
183
196
  }
184
197
  }
185
198
 
@@ -226,7 +239,7 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
226
239
  return chapterHeading;
227
240
  }
228
241
 
229
- 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)
230
243
  {
231
244
  string verseText;
232
245
  string filteredText;
@@ -240,7 +253,7 @@ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStron
240
253
  filteredText = verseText;
241
254
 
242
255
  if (!this->_rawMarkupEnabled) {
243
- filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasDuplicateClosingEndDivs);
256
+ filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasInconsistentClosingEndDivs);
244
257
  }
245
258
  } else {
246
259
  verseText = string(module->stripText());
@@ -302,7 +315,7 @@ vector<Verse> TextProcessor::getVersesFromReferences(string moduleName, vector<s
302
315
  vector<string> bookList = this->getBookListFromReferences(references);
303
316
  map<string, int> absoluteVerseNumbers = this->_moduleHelper.getAbsoluteVerseNumberMap(module, bookList);
304
317
  bool moduleMarkupIsBroken = this->_moduleHelper.isBrokenMarkupModule(moduleName);
305
- bool hasDuplicateClosingEndDivs = this->_moduleHelper.isDuplicateClosingEndDivModule(moduleName);
318
+ bool hasInconsistentClosingEndDivs = this->_moduleHelper.isInconsistentClosingEndDivModule(moduleName);
306
319
 
307
320
  for (unsigned int i = 0; i < references.size(); i++) {
308
321
  string currentReference = references[i];
@@ -312,7 +325,7 @@ vector<Verse> TextProcessor::getVersesFromReferences(string moduleName, vector<s
312
325
  bool entryExisting = module->hasEntry(module->getKey());
313
326
 
314
327
  if (entryExisting) {
315
- currentVerseText = this->getCurrentVerseText(module, false, hasDuplicateClosingEndDivs, moduleMarkupIsBroken);
328
+ currentVerseText = this->getCurrentVerseText(module, false, hasInconsistentClosingEndDivs, moduleMarkupIsBroken);
316
329
  }
317
330
 
318
331
  Verse currentVerse;
@@ -350,7 +363,7 @@ vector<Verse> TextProcessor::getText(string moduleName, string key, QueryLimit q
350
363
  int lastChapter = -1;
351
364
  bool currentBookExisting = true;
352
365
  bool moduleMarkupIsBroken = this->_moduleHelper.isBrokenMarkupModule(moduleName);
353
- bool hasDuplicateClosingEndDivs = this->_moduleHelper.isDuplicateClosingEndDivModule(moduleName);
366
+ bool hasInconsistentClosingEndDivs = this->_moduleHelper.isInconsistentClosingEndDivModule(moduleName);
354
367
 
355
368
  // This holds the text that we will return
356
369
  vector<Verse> text;
@@ -403,7 +416,7 @@ vector<Verse> TextProcessor::getText(string moduleName, string key, QueryLimit q
403
416
  // Current verse text
404
417
  verseText += this->getCurrentVerseText(module,
405
418
  hasStrongs,
406
- hasDuplicateClosingEndDivs,
419
+ hasInconsistentClosingEndDivs,
407
420
  // Note that if markup is broken this will enforce
408
421
  // the usage of the "stripped" / non-markup variant of the text
409
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
 
@@ -1,55 +0,0 @@
1
- Index: include/utf8transliterator.h
2
- ===================================================================
3
- --- include/utf8transliterator.h (Revision 3673)
4
- +++ include/utf8transliterator.h (Arbeitskopie)
5
- @@ -45,6 +45,9 @@
6
- #include <defs.h>
7
- #include <map>
8
-
9
- +using icu::UnicodeString;
10
- +using icu::Transliterator;
11
- +
12
- SWORD_NAMESPACE_START
13
-
14
- class SWModule;
15
- Index: src/modules/filters/scsuutf8.cpp
16
- ===================================================================
17
- --- src/modules/filters/scsuutf8.cpp (Revision 3673)
18
- +++ src/modules/filters/scsuutf8.cpp (Arbeitskopie)
19
- @@ -35,8 +35,8 @@
20
- #include <unicode/unistr.h>
21
- #endif
22
-
23
- +using icu::UnicodeString;
24
-
25
- -
26
- SWORD_NAMESPACE_START
27
-
28
-
29
- Index: src/modules/filters/utf8nfc.cpp
30
- ===================================================================
31
- --- src/modules/filters/utf8nfc.cpp (Revision 3673)
32
- +++ src/modules/filters/utf8nfc.cpp (Arbeitskopie)
33
- @@ -30,6 +30,9 @@
34
- #include <utf8nfc.h>
35
- #include <swbuf.h>
36
-
37
- +using icu::UnicodeString;
38
- +using icu::Normalizer;
39
- +
40
- SWORD_NAMESPACE_START
41
-
42
- UTF8NFC::UTF8NFC() {
43
- Index: src/modules/filters/utf8scsu.cpp
44
- ===================================================================
45
- --- src/modules/filters/utf8scsu.cpp (Revision 3673)
46
- +++ src/modules/filters/utf8scsu.cpp (Arbeitskopie)
47
- @@ -25,6 +25,8 @@
48
- #include <utf8scsu.h>
49
- #include <swbuf.h>
50
-
51
- +using icu::UnicodeString;
52
- +
53
- SWORD_NAMESPACE_START
54
-
55
-
@@ -1,62 +0,0 @@
1
- Index include/utf8transliterator.h
2
- ===================================================================
3
- --- include/utf8transliterator.h
4
- +++ include/utf8transliterator.h
5
- @@ -42,6 +42,9 @@ SE_JAMO, SE_HAN, SE_KANJI
6
-
7
- #include <unicode/translit.h>
8
-
9
- +using icu_64::UnicodeString;
10
- +using icu_64::Transliterator;
11
- +
12
- #include <defs.h>
13
- #include <map>
14
-
15
- Index src/modules/filters/scsuutf8.cpp
16
- ===================================================================
17
- --- src/modules/filters/scsuutf8.cpp
18
- +++ src/modules/filters/scsuutf8.cpp
19
- @@ -29,13 +29,14 @@
20
- * in http://www.unicode.org/unicode/reports/tr6.html
21
- */
22
-
23
- -#include <scsuutf8.h>
24
- -#include <swbuf.h>
25
- #ifdef _ICU_
26
- #include <unicode/unistr.h>
27
- #endif
28
-
29
- +using icu_64::UnicodeString;
30
-
31
- +#include <scsuutf8.h>
32
- +#include <swbuf.h>
33
-
34
- SWORD_NAMESPACE_START
35
-
36
- Index src/modules/filters/utf8nfc.cpp
37
- ===================================================================
38
- --- src/modules/filters/utf8nfc.cpp
39
- +++ src/modules/filters/utf8nfc.cpp
40
- @@ -27,6 +27,9 @@
41
- #include <unicode/normlzr.h>
42
- #include <unicode/unorm.h>
43
-
44
- +using icu_64::UnicodeString;
45
- +using icu_64::Normalizer;
46
- +
47
- #include <utf8nfc.h>
48
- #include <swbuf.h>
49
-
50
- Index src/modules/filters/utf8scsu.cpp
51
- ===================================================================
52
- --- src/modules/filters/utf8scsu.cpp
53
- +++ src/modules/filters/utf8scsu.cpp
54
- @@ -25,6 +25,8 @@
55
- #include <utf8scsu.h>
56
- #include <swbuf.h>
57
-
58
- +using icu_64::UnicodeString;
59
- +
60
- SWORD_NAMESPACE_START
61
-
62
-