node-sword-interface 1.0.109 → 1.0.110

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/API.md CHANGED
@@ -53,7 +53,7 @@ This is the main class of node-sword-interface and it provides a set of static f
53
53
  * [.enableMarkup()](#NodeSwordInterface+enableMarkup)
54
54
  * [.disableMarkup()](#NodeSwordInterface+disableMarkup)
55
55
  * [.enableStrongsWithNbsp()](#NodeSwordInterface+enableStrongsWithNbsp)
56
- * [.getRawModuleEntry(moduleCode, key)](#NodeSwordInterface+getRawModuleEntry) ⇒ <code>String</code>
56
+ * [.getRawModuleEntry(moduleCode, key, processImageUrls)](#NodeSwordInterface+getRawModuleEntry) ⇒ <code>String</code>
57
57
  * [.getReferenceText(moduleCode, key)](#NodeSwordInterface+getReferenceText) ⇒ [<code>VerseObject</code>](#VerseObject)
58
58
  * [.getChapterText(moduleCode, bookCode, chapter)](#NodeSwordInterface+getChapterText) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
59
59
  * [.getBookText(moduleCode, bookCode, startVerseNr, verseCount)](#NodeSwordInterface+getBookText) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
@@ -346,7 +346,7 @@ Enables rendering of Strongs elements with non-breaking spaces.
346
346
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
347
347
  <a name="NodeSwordInterface+getRawModuleEntry"></a>
348
348
 
349
- ### nodeSwordInterface.getRawModuleEntry(moduleCode, key) ⇒ <code>String</code>
349
+ ### nodeSwordInterface.getRawModuleEntry(moduleCode, key, processImageUrls) ⇒ <code>String</code>
350
350
  Returns the raw text of an entry for the given module and key.
351
351
  If no entry exists for the given key the return value is undefined.
352
352
 
@@ -356,6 +356,7 @@ If no entry exists for the given key the return value is undefined.
356
356
  | --- | --- | --- |
357
357
  | moduleCode | <code>String</code> | The module code of the SWORD module. |
358
358
  | key | <code>String</code> | The key of the entry. |
359
+ | processImageUrls | <code>Boolean</code> | Whether to pre-process image URLs with platform-specific file paths (Optional, default: false). |
359
360
 
360
361
  <a name="NodeSwordInterface+getReferenceText"></a>
361
362
 
package/deploy_local.sh CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
- PROJECT_DIR='ezra-bible-app'
3
+ PROJECT_DIR='ezra-project-git'
4
4
  WORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5
5
  rm -rf $WORK_DIR/../$PROJECT_DIR/node_modules/node-sword-interface
6
6
  cp -a $WORK_DIR $WORK_DIR/../$PROJECT_DIR/node_modules/node-sword-interface
package/index.js CHANGED
@@ -382,10 +382,11 @@ class NodeSwordInterface {
382
382
  *
383
383
  * @param {String} moduleCode - The module code of the SWORD module.
384
384
  * @param {String} key - The key of the entry.
385
+ * @param {Boolean} processImageUrls - Whether to pre-process image URLs with platform-specific file paths (Optional, default: false).
385
386
  * @return {String}
386
387
  */
387
- getRawModuleEntry(moduleCode, key) {
388
- return this.nativeInterface.getRawModuleEntry(moduleCode, key);
388
+ getRawModuleEntry(moduleCode, key, processImageUrls = false) {
389
+ return this.nativeInterface.getRawModuleEntry(moduleCode, key, processImageUrls);
389
390
  }
390
391
 
391
392
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.109",
3
+ "version": "1.0.110",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -603,6 +603,13 @@ Napi::Value NodeSwordInterface::getRawModuleEntry(const Napi::CallbackInfo& info
603
603
  Napi::Env env = info.Env();
604
604
  Napi::String moduleName = info[0].As<Napi::String>();
605
605
  Napi::String key = info[1].As<Napi::String>();
606
+
607
+ // Optional 3rd parameter - default to false
608
+ bool processImageUrls = false;
609
+ if (info.Length() > 2 && info[2].IsBoolean()) {
610
+ processImageUrls = info[2].As<Napi::Boolean>().Value();
611
+ }
612
+
606
613
  ASSERT_SW_MODULE_EXISTS(moduleName);
607
614
 
608
615
  SWModule* swordModule = this->_moduleStore->getLocalModule(moduleName);
@@ -610,7 +617,13 @@ Napi::Value NodeSwordInterface::getRawModuleEntry(const Napi::CallbackInfo& info
610
617
  bool entryExisting = swordModule->hasEntry(swordModule->getKey());
611
618
 
612
619
  if (entryExisting) {
613
- Napi::String entryText = Napi::String::New(env, swordModule->getRawEntry());
620
+ string rawEntry = swordModule->getRawEntry();
621
+
622
+ if (processImageUrls) {
623
+ this->_textProcessor->processImageUrls(rawEntry, swordModule);
624
+ }
625
+
626
+ Napi::String entryText = Napi::String::New(env, rawEntry);
614
627
  unlockApi();
615
628
  return entryText;
616
629
  } else {
@@ -247,11 +247,7 @@ string TextProcessor::getFilteredText(const string& text, int chapter, int verse
247
247
  }
248
248
 
249
249
  // Prefix img src attributes starting with "/" with the module file URL
250
- if (!moduleFileUrl.empty()) {
251
- static string imgSrcSlash = "src=\"/";
252
- string imgSrcReplacement = "src=\"" + moduleFileUrl + "/";
253
- this->findAndReplaceAll(filteredText, imgSrcSlash, imgSrcReplacement);
254
- }
250
+ this->processImageUrls(filteredText, moduleFileUrl);
255
251
 
256
252
  return filteredText;
257
253
  }
@@ -610,16 +606,27 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
610
606
  filteredText = regex_replace(filteredText, chapterDivFilter, "");
611
607
 
612
608
  // Prefix img src attributes starting with "/" with the module file URL
613
- if (!moduleFileUrl.empty()) {
614
- static string imgSrcSlash = "src=\"/";
615
- string imgSrcReplacement = "src=\"" + moduleFileUrl + "/";
616
- this->findAndReplaceAll(filteredText, imgSrcSlash, imgSrcReplacement);
617
- }
609
+ this->processImageUrls(filteredText, moduleFileUrl);
618
610
  }
619
611
 
620
612
  return filteredText;
621
613
  }
622
614
 
615
+ void TextProcessor::processImageUrls(string& text, const string& moduleFileUrl)
616
+ {
617
+ if (!moduleFileUrl.empty()) {
618
+ static string imgSrcSlash = "src=\"/";
619
+ string imgSrcReplacement = "src=\"" + moduleFileUrl + "/";
620
+ this->findAndReplaceAll(text, imgSrcSlash, imgSrcReplacement);
621
+ }
622
+ }
623
+
624
+ void TextProcessor::processImageUrls(string& text, sword::SWModule* module)
625
+ {
626
+ string moduleFileUrl = this->getFileUrl(this->_moduleStore.getModuleDataPath(module));
627
+ this->processImageUrls(text, moduleFileUrl);
628
+ }
629
+
623
630
  string TextProcessor::replaceSpacesInStrongs(const string& text)
624
631
  {
625
632
  string input = text;
@@ -51,6 +51,9 @@ public:
51
51
 
52
52
  StrongsEntry* getStrongsEntry(std::string key);
53
53
 
54
+ void processImageUrls(std::string& text, const std::string& moduleFileUrl);
55
+ void processImageUrls(std::string& text, sword::SWModule* module);
56
+
54
57
  bool moduleHasStrongsZeroPrefixes(sword::SWModule* module);
55
58
  bool moduleHasStrongsPaddedZeroPrefixes(sword::SWModule* module);
56
59
  std::string padStrongsNumber(const std::string strongsNumber);