node-sword-interface 1.0.98 → 1.0.100

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.98",
3
+ "version": "1.0.100",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -105,11 +105,11 @@ void get_module_text(TextProcessor& text_processor)
105
105
  {
106
106
  cout << "Text:" << endl;
107
107
  text_processor.enableMarkup();
108
- vector<Verse> verses = text_processor.getBookText("NASB", "Ps");
108
+ vector<Verse> verses = text_processor.getBookText("NET", "Luke");
109
109
  cout << "Got " << verses.size() << " verses!" << endl;
110
- /*for (int i = 0; i < verses.size(); i++) {
110
+ for (int i = 0; i < 10; i++) {
111
111
  cout << verses[i].reference << "|" << verses[i].content << endl;
112
- }*/
112
+ }
113
113
  }
114
114
 
115
115
  void get_reference_text(ModuleStore& module_store, TextProcessor& text_processor)
@@ -220,17 +220,17 @@ int main(int argc, char** argv)
220
220
 
221
221
  show_modules(repoInterface);
222
222
 
223
- /*int error = moduleInstaller.installModule("UKJV");
223
+ /*int error = moduleInstaller.installModule("CrossWire", "UKJV");
224
224
 
225
225
  if (error) {
226
226
  cout << "Error installing module (write permissions?)\n";
227
- }
227
+ }*/
228
228
 
229
- error = moduleInstaller.uninstallModule("UKJV");
229
+ int error = moduleInstaller.uninstallModule("YLT");
230
230
 
231
231
  if (error) {
232
232
  cout << "Error uninstalling module (write permissions?)\n";
233
- }*/
233
+ }
234
234
 
235
235
  /*get_local_module(moduleStore);
236
236
 
@@ -241,7 +241,7 @@ int main(int argc, char** argv)
241
241
 
242
242
  //get_strongs_entry(textProcessor);
243
243
 
244
- //get_module_text(textProcessor);
244
+ get_module_text(textProcessor);
245
245
 
246
246
  //get_reference_text(moduleStore, textProcessor);
247
247
 
@@ -30,6 +30,7 @@
30
30
 
31
31
  // Own includes
32
32
  #include "text_processor.hpp"
33
+ #include "module_store.hpp"
33
34
  #include "module_helper.hpp"
34
35
  #include "string_helper.hpp"
35
36
  #include "strongs_entry.hpp"
@@ -45,7 +46,32 @@ TextProcessor::TextProcessor(ModuleStore& moduleStore, ModuleHelper& moduleHelpe
45
46
  this->_rawMarkupEnabled = false;
46
47
  }
47
48
 
48
- string TextProcessor::getFilteredText(const string& text, int chapter, int verseNr, bool hasStrongs, bool hasInconsistentClosingEndDivs)
49
+ string TextProcessor::getFileUrl(const string& nativePath)
50
+ {
51
+ if (nativePath.empty()) {
52
+ return "";
53
+ }
54
+
55
+ string path = nativePath;
56
+
57
+ // Strip trailing slash or backslash
58
+ if (!path.empty() && (path.back() == '/' || path.back() == '\\')) {
59
+ path.pop_back();
60
+ }
61
+
62
+ // Convert backslashes to forward slashes for URL compatibility
63
+ static regex backslash("\\\\");
64
+ path = regex_replace(path, backslash, "/");
65
+
66
+ // Build file:// URL (Windows needs extra slash for drive letter)
67
+ #if _WIN32
68
+ return "file:///" + path;
69
+ #else
70
+ return "file://" + path;
71
+ #endif
72
+ }
73
+
74
+ string TextProcessor::getFilteredText(const string& text, int chapter, int verseNr, bool hasStrongs, bool hasInconsistentClosingEndDivs, const string& moduleFileUrl)
49
75
  {
50
76
  static string chapterFilter = "<chapter";
51
77
  static regex pbElement = regex("<pb .*?/> ");
@@ -218,10 +244,17 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
218
244
  filteredText = this->replaceSpacesInStrongs(filteredText);
219
245
  }
220
246
 
247
+ // Prefix img src attributes starting with "/" with the module file URL
248
+ if (!moduleFileUrl.empty()) {
249
+ static string imgSrcSlash = "src=\"/";
250
+ string imgSrcReplacement = "src=\"" + moduleFileUrl + "/";
251
+ this->findAndReplaceAll(filteredText, imgSrcSlash, imgSrcReplacement);
252
+ }
253
+
221
254
  return filteredText;
222
255
  }
223
256
 
224
- string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
257
+ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module, const string& moduleFileUrl)
225
258
  {
226
259
  string currentModuleName = string(module->getName());
227
260
  string chapterHeading = "";
@@ -254,7 +287,7 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
254
287
  // Therefore we do not render chapter headings for the first verse of the chapter in this case.
255
288
  chapterHeading = "";
256
289
  } else {
257
- chapterHeading = this->getFilteredText(chapterHeading, currentChapter, currentVerseNr);
290
+ chapterHeading = this->getFilteredText(chapterHeading, currentChapter, currentVerseNr, false, false, moduleFileUrl);
258
291
  }
259
292
  }
260
293
 
@@ -262,6 +295,12 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
262
295
  }
263
296
 
264
297
  string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasInconsistentClosingEndDivs, bool forceNoMarkup)
298
+ {
299
+ string moduleFileUrl = this->getFileUrl(this->_moduleStore.getModuleDataPath(module));
300
+ return this->getCurrentVerseText(module, hasStrongs, hasInconsistentClosingEndDivs, forceNoMarkup, moduleFileUrl);
301
+ }
302
+
303
+ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasInconsistentClosingEndDivs, bool forceNoMarkup, const string& moduleFileUrl)
265
304
  {
266
305
  string verseText;
267
306
  string filteredText;
@@ -275,7 +314,7 @@ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStron
275
314
  filteredText = verseText;
276
315
 
277
316
  if (!this->_rawMarkupEnabled) {
278
- filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasInconsistentClosingEndDivs);
317
+ filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasInconsistentClosingEndDivs, moduleFileUrl);
279
318
  }
280
319
  } else {
281
320
  verseText = string(module->stripText());
@@ -358,6 +397,9 @@ vector<Verse> TextProcessor::getVersesFromReferences(string moduleName, vector<s
358
397
  bool moduleMarkupIsBroken = this->_moduleHelper.isBrokenMarkupModule(moduleName);
359
398
  bool hasInconsistentClosingEndDivs = this->_moduleHelper.isInconsistentClosingEndDivModule(moduleName);
360
399
 
400
+ // Compute file URL once for the entire module
401
+ string moduleFileUrl = this->getFileUrl(this->_moduleStore.getModuleDataPath(module));
402
+
361
403
  for (unsigned int i = 0; i < references.size(); i++) {
362
404
  string currentReference = references[i];
363
405
  string currentVerseText = "";
@@ -366,7 +408,7 @@ vector<Verse> TextProcessor::getVersesFromReferences(string moduleName, vector<s
366
408
  bool entryExisting = module->hasEntry(module->getKey());
367
409
 
368
410
  if (entryExisting) {
369
- currentVerseText = this->getCurrentVerseText(module, false, hasInconsistentClosingEndDivs, moduleMarkupIsBroken);
411
+ currentVerseText = this->getCurrentVerseText(module, false, hasInconsistentClosingEndDivs, moduleMarkupIsBroken, moduleFileUrl);
370
412
  }
371
413
 
372
414
  Verse currentVerse;
@@ -414,6 +456,9 @@ vector<Verse> TextProcessor::getText(string moduleName, string key, QueryLimit q
414
456
  } else {
415
457
  bool hasStrongs = this->_moduleHelper.moduleHasGlobalOption(module, "Strongs");
416
458
 
459
+ // Compute file URL once for the entire module
460
+ string moduleFileUrl = this->getFileUrl(this->_moduleStore.getModuleDataPath(module));
461
+
417
462
  module->setKey(key.c_str());
418
463
 
419
464
  if (startVerseNumber >= 1) {
@@ -450,7 +495,7 @@ vector<Verse> TextProcessor::getText(string moduleName, string key, QueryLimit q
450
495
  // and if the module markup is not broken
451
496
  // and if the requested verse count is more than one or the default (-1 / all verses).
452
497
  if (firstVerseInChapter && !moduleMarkupIsBroken && (verseCount > 1 || verseCount == -1)) {
453
- string chapterHeading = this->getCurrentChapterHeading(module);
498
+ string chapterHeading = this->getCurrentChapterHeading(module, moduleFileUrl);
454
499
  verseText += chapterHeading;
455
500
  }
456
501
 
@@ -460,7 +505,8 @@ vector<Verse> TextProcessor::getText(string moduleName, string key, QueryLimit q
460
505
  hasInconsistentClosingEndDivs,
461
506
  // Note that if markup is broken this will enforce
462
507
  // the usage of the "stripped" / non-markup variant of the text
463
- moduleMarkupIsBroken);
508
+ moduleMarkupIsBroken,
509
+ moduleFileUrl);
464
510
 
465
511
  // If the current verse does not have any content and if it is the first verse in this book
466
512
  // we assume that the book is not existing.
@@ -522,6 +568,14 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
522
568
  filteredText = regex_replace(filteredText, headStartElementFilter, "<div class=\"sword-markup sword-head\"");
523
569
  filteredText = regex_replace(filteredText, headEndElementFilter, "</div>");
524
570
  filteredText = regex_replace(filteredText, chapterDivFilter, "");
571
+
572
+ // Prefix img src attributes starting with "/" with the module file URL
573
+ string moduleFileUrl = this->getFileUrl(this->_moduleStore.getModuleDataPath(module));
574
+ if (!moduleFileUrl.empty()) {
575
+ static string imgSrcSlash = "src=\"/";
576
+ string imgSrcReplacement = "src=\"" + moduleFileUrl + "/";
577
+ this->findAndReplaceAll(filteredText, imgSrcSlash, imgSrcReplacement);
578
+ }
525
579
  }
526
580
 
527
581
  return filteredText;
@@ -63,8 +63,10 @@ private:
63
63
  int startVerseNr=-1,
64
64
  int verseCount=-1);
65
65
 
66
- std::string getCurrentChapterHeading(sword::SWModule* module);
67
- std::string getFilteredText(const std::string& text, int chapter, int verseNr, bool hasStrongs=false, bool hasInconsistentClosingEndDivs=false);
66
+ std::string getCurrentChapterHeading(sword::SWModule* module, const std::string& moduleFileUrl);
67
+ std::string getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasInconsistentClosingEndDivs, bool forceNoMarkup, const std::string& moduleFileUrl);
68
+ std::string getFilteredText(const std::string& text, int chapter, int verseNr, bool hasStrongs, bool hasInconsistentClosingEndDivs, const std::string& moduleFileUrl);
69
+ std::string getFileUrl(const std::string& nativePath);
68
70
  std::string replaceSpacesInStrongs(const std::string& text);
69
71
  unsigned int findAndReplaceAll(std::string & data, std::string toSearch, std::string replaceStr);
70
72