node-sword-interface 1.0.98 → 1.0.99
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
package/src/node_sword_cli.cpp
CHANGED
|
@@ -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("
|
|
108
|
+
vector<Verse> verses = text_processor.getBookText("NET", "Luke");
|
|
109
109
|
cout << "Got " << verses.size() << " verses!" << endl;
|
|
110
|
-
|
|
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("
|
|
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
|
-
|
|
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::
|
|
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& moduleDataPath)
|
|
49
75
|
{
|
|
50
76
|
static string chapterFilter = "<chapter";
|
|
51
77
|
static regex pbElement = regex("<pb .*?/> ");
|
|
@@ -218,6 +244,14 @@ 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 data path as a file:// URL
|
|
248
|
+
if (!moduleDataPath.empty()) {
|
|
249
|
+
string fileUrl = this->getFileUrl(moduleDataPath);
|
|
250
|
+
static string imgSrcSlash = "src=\"/";
|
|
251
|
+
string imgSrcReplacement = "src=\"" + fileUrl + "/";
|
|
252
|
+
this->findAndReplaceAll(filteredText, imgSrcSlash, imgSrcReplacement);
|
|
253
|
+
}
|
|
254
|
+
|
|
221
255
|
return filteredText;
|
|
222
256
|
}
|
|
223
257
|
|
|
@@ -254,7 +288,8 @@ string TextProcessor::getCurrentChapterHeading(sword::SWModule* module)
|
|
|
254
288
|
// Therefore we do not render chapter headings for the first verse of the chapter in this case.
|
|
255
289
|
chapterHeading = "";
|
|
256
290
|
} else {
|
|
257
|
-
|
|
291
|
+
string moduleDataPath = this->_moduleStore.getModuleDataPath(module);
|
|
292
|
+
chapterHeading = this->getFilteredText(chapterHeading, currentChapter, currentVerseNr, false, false, moduleDataPath);
|
|
258
293
|
}
|
|
259
294
|
}
|
|
260
295
|
|
|
@@ -275,7 +310,8 @@ string TextProcessor::getCurrentVerseText(sword::SWModule* module, bool hasStron
|
|
|
275
310
|
filteredText = verseText;
|
|
276
311
|
|
|
277
312
|
if (!this->_rawMarkupEnabled) {
|
|
278
|
-
|
|
313
|
+
string moduleDataPath = this->_moduleStore.getModuleDataPath(module);
|
|
314
|
+
filteredText = this->getFilteredText(verseText, currentChapter, currentVerseNr, hasStrongs, hasInconsistentClosingEndDivs, moduleDataPath);
|
|
279
315
|
}
|
|
280
316
|
} else {
|
|
281
317
|
verseText = string(module->stripText());
|
|
@@ -522,6 +558,15 @@ string TextProcessor::getBookIntroduction(string moduleName, string bookCode)
|
|
|
522
558
|
filteredText = regex_replace(filteredText, headStartElementFilter, "<div class=\"sword-markup sword-head\"");
|
|
523
559
|
filteredText = regex_replace(filteredText, headEndElementFilter, "</div>");
|
|
524
560
|
filteredText = regex_replace(filteredText, chapterDivFilter, "");
|
|
561
|
+
|
|
562
|
+
// Prefix img src attributes starting with "/" with the module data path as a file:// URL
|
|
563
|
+
string moduleDataPath = this->_moduleStore.getModuleDataPath(module);
|
|
564
|
+
if (!moduleDataPath.empty()) {
|
|
565
|
+
string fileUrl = this->getFileUrl(moduleDataPath);
|
|
566
|
+
static string imgSrcSlash = "src=\"/";
|
|
567
|
+
string imgSrcReplacement = "src=\"" + fileUrl + "/";
|
|
568
|
+
this->findAndReplaceAll(filteredText, imgSrcSlash, imgSrcReplacement);
|
|
569
|
+
}
|
|
525
570
|
}
|
|
526
571
|
|
|
527
572
|
return filteredText;
|
|
@@ -64,7 +64,8 @@ private:
|
|
|
64
64
|
int verseCount=-1);
|
|
65
65
|
|
|
66
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);
|
|
67
|
+
std::string getFilteredText(const std::string& text, int chapter, int verseNr, bool hasStrongs=false, bool hasInconsistentClosingEndDivs=false, const std::string& moduleDataPath="");
|
|
68
|
+
std::string getFileUrl(const std::string& nativePath);
|
|
68
69
|
std::string replaceSpacesInStrongs(const std::string& text);
|
|
69
70
|
unsigned int findAndReplaceAll(std::string & data, std::string toSearch, std::string replaceStr);
|
|
70
71
|
|