node-sword-interface 1.0.2 → 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
|
@@ -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 "
|
|
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::
|
|
213
|
+
bool ModuleHelper::isInconsistentClosingEndDivModule(std::string moduleName)
|
|
214
214
|
{
|
|
215
|
-
return std::find(this->
|
|
216
|
-
this->
|
|
217
|
-
moduleName) != this->
|
|
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
|
|
38
|
-
this->
|
|
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
|
|
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>
|
|
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
|
|
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, " <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 (
|
|
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
|
-
|
|
182
|
-
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|