Biblia Codex - Module Parser
The Codex web app parses and visualizes theological modules (MySword, MyBible, and Devotionals) in standard HTML/React. Because it executes entirely in the JavaScript environment, special rules apply to how strings and binaries are handled.
🛠 Parsing Architecture
Database Access with
sql.js(WebAssembly)- Modules are
.sqlite3or.mybiblebinaries loaded as JSON/ArrayBuffers. - You must structure the loading using
sql.jskeeping in mind its entirely synchronous, memory-bound API. (Queries evaluate synchronously once initialized). - Blobs fetched via Capacitor APIs (
@capacitor/filesystem) should be properly converted intoUint8Arraybefore providing them toSQL.Database().
- Modules are
MySword Parser Configuration (
mySwordParser.ts)- Performance: JS Regular Expressions (
RegExp) must be highly optimized since they run over thousands of verses. - Text Filtering:
- Basic styling: Replace
<FI>...<Fi>,<FU>...<Fu>to standard HTML. - Words of Jesus: Replace
<FR>...<Fr>/<J>...<J>according to user text display settings. - Strong's:
<WG...>and<WH...>tags must be wrapped in<a>tags with classesstrongs-link, allowing clicks to route properly internally. - Morphology & Interlinear:
<WT...>,<E>,<T>,<X>,<H>,<G>tags should output spans utilizing custom Tailwind/CSS classes.
- Basic styling: Replace
- Settings Dependency: Before displaying verse tags, check visibility toggles from the client's
settingsobjects (showStrongs,morphTags,interlinearMode).
- Performance: JS Regular Expressions (
Storage & Serialization
- Persist massive parsed data into
idbinstead oflocalStorage. - Ensure you compress or serialize objects carefully (React markdown nodes or simple HTML strings).
- Persist massive parsed data into
🤝 Best Practices & Common Errors
- Regex Undefined Replacements: When substituting tags, ensure capture groups
$1strictly exist. Handle MySword/MyBible variations separately (e.g.<i>...</i>vs<FI>...<Fi>) instead of catching them under one messy regex group. - Safety: Always sanitize HTML when using React
dangerouslySetInnerHTML. EnsuremySwordParseronly returns safe native elements without malicious<script>tags, especially when importing third party modules.