node-sword-interface 1.0.101 → 1.0.103

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.101",
3
+ "version": "1.0.103",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -130,7 +130,7 @@ void get_book_intro(TextProcessor& text_processor)
130
130
  {
131
131
  cout << "Text:" << endl;
132
132
  text_processor.enableMarkup();
133
- string bookIntro = text_processor.getBookIntroduction("GerNeUe", "John");
133
+ string bookIntro = text_processor.getBookIntroduction("NET", "Luke");
134
134
  cout << bookIntro << endl;
135
135
  }
136
136
 
@@ -226,11 +226,11 @@ int main(int argc, char** argv)
226
226
  cout << "Error installing module (write permissions?)\n";
227
227
  }*/
228
228
 
229
- int error = moduleInstaller.uninstallModule("YLT");
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,11 +241,11 @@ 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
 
248
- //get_book_intro(textProcessor);
248
+ get_book_intro(textProcessor);
249
249
 
250
250
  //get_book_list(moduleHelper);
251
251
 
@@ -265,8 +265,30 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module, const st
265
265
  if (currentVerseKey.getVerse() == 1) { // X:1, set key to X:0
266
266
  // Include chapter/book/testament/module intros
267
267
  currentVerseKey.setIntros(true);
268
- currentVerseKey.setVerse(0);
269
268
 
269
+ // For chapter 1, check if the book intro (0:0) is empty.
270
+ // If so, chapter 1:0 content is being used as book intro in getBookIntroduction()
271
+ // and should be skipped here to avoid duplication.
272
+ if (currentChapter == 1) {
273
+ VerseKey bookIntroKey = currentVerseKey;
274
+ bookIntroKey.setChapter(0);
275
+ bookIntroKey.setVerse(0);
276
+ module->setKey(bookIntroKey);
277
+
278
+ string bookIntro = string(module->getRawEntry());
279
+ StringHelper::trim(bookIntro);
280
+
281
+ // Restore the key
282
+ module->setKey(currentVerseKey);
283
+
284
+ // If book intro is empty, chapter 1:0 is used as book intro
285
+ // so we should not include it here as chapter heading
286
+ if (bookIntro.empty()) {
287
+ return "";
288
+ }
289
+ }
290
+
291
+ currentVerseKey.setVerse(0);
270
292
  module->setKey(currentVerseKey);
271
293
 
272
294
  chapterHeading = string(module->getRawEntry());
@@ -294,48 +316,6 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module, const st
294
316
  return chapterHeading;
295
317
  }
296
318
 
297
- string TextProcessor::getCurrentPreverseHeading(sword::SWModule* module, const string& moduleFileUrl)
298
- {
299
- string preverse = "";
300
- VerseKey currentVerseKey = module->getKey();
301
- int currentChapter = currentVerseKey.getChapter();
302
- int currentVerseNr = currentVerseKey.getVerse();
303
-
304
- // First, we need to access the rendered text to populate entry attributes
305
- // The entry attributes are only available after rendering/stripping
306
- module->renderText();
307
-
308
- // Get the entry attributes map
309
- sword::AttributeTypeList& attributes = module->getEntryAttributes();
310
-
311
- // Look for Heading/Preverse entries (indexed 0, 1, 2, ...)
312
- auto headingIt = attributes.find("Heading");
313
- if (headingIt != attributes.end()) {
314
- auto preverseIt = headingIt->second.find("Preverse");
315
- if (preverseIt != headingIt->second.end()) {
316
- // Iterate through all preverse entries (0, 1, 2, ...)
317
- for (auto& entry : preverseIt->second) {
318
- string preverseContent = string(entry.second.c_str());
319
- StringHelper::trim(preverseContent);
320
-
321
- if (!preverseContent.empty()) {
322
- // Render the preverse content through the module
323
- sword::SWBuf renderedBuf = module->renderText(preverseContent.c_str());
324
- string rendered = string(renderedBuf.c_str());
325
-
326
- if (this->_markupEnabled && !this->_rawMarkupEnabled) {
327
- rendered = this->getFilteredText(rendered, currentChapter, currentVerseNr, false, false, moduleFileUrl);
328
- }
329
-
330
- preverse += rendered;
331
- }
332
- }
333
- }
334
- }
335
-
336
- return preverse;
337
- }
338
-
339
319
  string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasInconsistentClosingEndDivs, bool forceNoMarkup)
340
320
  {
341
321
  string moduleFileUrl = this->getFileUrl(this->_moduleStore.getModuleDataPath(module));
@@ -450,13 +430,7 @@ vector<Verse> TextProcessor::getVersesFromReferences(string moduleName, vector<s
450
430
  bool entryExisting = module->hasEntry(module->getKey());
451
431
 
452
432
  if (entryExisting) {
453
- // Add preverse heading before verse text
454
- if (!moduleMarkupIsBroken) {
455
- string preverseHeading = this->getCurrentPreverseHeading(module, moduleFileUrl);
456
- currentVerseText += preverseHeading;
457
- }
458
-
459
- currentVerseText += this->getCurrentVerseText(module, false, hasInconsistentClosingEndDivs, moduleMarkupIsBroken, moduleFileUrl);
433
+ currentVerseText = this->getCurrentVerseText(module, false, hasInconsistentClosingEndDivs, moduleMarkupIsBroken, moduleFileUrl);
460
434
  }
461
435
 
462
436
  Verse currentVerse;
@@ -547,13 +521,6 @@ vector<Verse> TextProcessor::getText(string moduleName, string key, QueryLimit q
547
521
  verseText += chapterHeading;
548
522
  }
549
523
 
550
- // Preverse heading (introductory material attached to this verse via entry attributes)
551
- // This includes intro images and other material that should appear before the verse text
552
- if (!moduleMarkupIsBroken) {
553
- string preverseHeading = this->getCurrentPreverseHeading(module, moduleFileUrl);
554
- verseText += preverseHeading;
555
- }
556
-
557
524
  // Current verse text
558
525
  verseText += this->getCurrentVerseText(module,
559
526
  hasStrongs,
@@ -595,18 +562,37 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
595
562
  if (module == 0) {
596
563
  cerr << "getLocalModule returned zero pointer for " << moduleName << endl;
597
564
  } else {
565
+ // Get module data path BEFORE manipulating the module key
566
+ string moduleDataPath = this->_moduleStore.getModuleDataPath(module);
567
+ string moduleFileUrl = this->getFileUrl(moduleDataPath);
568
+
598
569
  module->setKeyText(bookCode.c_str());
599
- VerseKey *verseKey = (VerseKey *)module->getKey();
570
+
571
+ // Create a local VerseKey copy to avoid pointer invalidation issues
572
+ VerseKey verseKey = module->getKey();
600
573
 
601
574
  // Include chapter/book/testament/module intros
602
- verseKey->setIntros(true);
603
- verseKey->setChapter(0);
604
- verseKey->setVerse(0);
575
+ verseKey.setIntros(true);
576
+
577
+ // First try to get book intro from chapter 0, verse 0
578
+ verseKey.setChapter(0);
579
+ verseKey.setVerse(0);
605
580
  module->setKey(verseKey);
606
581
 
607
582
  bookIntroText = string(module->getRawEntry());
608
583
  StringHelper::trim(bookIntroText);
609
584
 
585
+ // If book intro (0:0) is empty, also fetch chapter 1:0
586
+ // Some modules (like NET) store book-level intro content in chapter 1:0
587
+ if (bookIntroText.empty()) {
588
+ verseKey.setChapter(1);
589
+ verseKey.setVerse(0);
590
+ module->setKey(verseKey);
591
+
592
+ bookIntroText = string(module->getRawEntry());
593
+ StringHelper::trim(bookIntroText);
594
+ }
595
+
610
596
  static regex titleStartElementFilter = regex("<title");
611
597
  static regex titleEndElementFilter = regex("</title>");
612
598
  static regex noteStartElementFilter = regex("<note");
@@ -625,7 +611,6 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
625
611
  filteredText = regex_replace(filteredText, chapterDivFilter, "");
626
612
 
627
613
  // Prefix img src attributes starting with "/" with the module file URL
628
- string moduleFileUrl = this->getFileUrl(this->_moduleStore.getModuleDataPath(module));
629
614
  if (!moduleFileUrl.empty()) {
630
615
  static string imgSrcSlash = "src=\"/";
631
616
  string imgSrcReplacement = "src=\"" + moduleFileUrl + "/";
@@ -64,7 +64,6 @@ private:
64
64
  int verseCount=-1);
65
65
 
66
66
  std::string getCurrentChapterHeading(sword::SWModule* module, const std::string& moduleFileUrl);
67
- std::string getCurrentPreverseHeading(sword::SWModule* module, const std::string& moduleFileUrl);
68
67
  std::string getCurrentVerseText(sword::SWModule* module, bool hasStrongs, bool hasInconsistentClosingEndDivs, bool forceNoMarkup, const std::string& moduleFileUrl);
69
68
  std::string getFilteredText(const std::string& text, int chapter, int verseNr, bool hasStrongs, bool hasInconsistentClosingEndDivs, const std::string& moduleFileUrl);
70
69
  std::string getFileUrl(const std::string& nativePath);