Simplified BibleReader parsing - NKJV files now use standard mdbible format with numbered verses

This commit is contained in:
Ryderjj89
2025-09-28 13:30:01 -04:00
parent eaba20c208
commit 1b1cadf260
1191 changed files with 16 additions and 61 deletions

View File

@@ -61,38 +61,12 @@ function getDataDir(version) {
return esvSearchEngine ? ESV_DATA_DIR : NKJV_DATA_DIR; // default to available version
}
// Helper function to read markdown files with encoding normalization
// Helper function to read markdown files
async function readMarkdownFile(filePath) {
try {
// Try UTF-8 first
let content = await fs.readFile(filePath, 'utf-8');
// Check if content contains replacement characters (indicates wrong encoding)
if (content.includes('\ufffd')) {
// Try with ISO-8859-1 (Latin-1) encoding common for Windows files
try {
const isoContent = await fs.readFile(filePath, 'latin1');
// Convert ISO-8859-1 to UTF-8
content = isoContent.normalize('NFC');
} catch (isoError) {
console.warn(`Failed to read with Latin-1 encoding for ${filePath}`);
}
}
// Remove BOM if present
content = content.replace(/^\uFEFF/, '');
// Additional cleanup for NKJV files
if (filePath.includes('/NKJV/')) {
// Replace any remaining encoding issues
content = content.replace(/\ufffd/g, ''); // Remove any remaining replacement chars
// Clean up any anomalous line breaks that might emerge in NKJV
content = content.replace(/\r\n/g, '\n'); // Normalize line endings
content = content.replace(/\r/g, '\n'); // Handle stray \r characters
}
return content;
const content = await fs.readFile(filePath, 'utf-8');
// Remove BOM if present and normalize encoding issues
return content.replace(/^\uFEFF/, ''); // Remove UTF-8 BOM
} catch (error) {
throw new Error(`Failed to read file: ${filePath}`);
}