usfm3
An error-tolerant USFM 3.x parser written in Rust. Outputs USJ (JSON), USX (XML), normalized USFM, and verse-reference maps.
Also available as a Python package and npm package (WebAssembly).
Features
- Parses all USFM 3.x markers including tables, milestones, sidebars, figures, and nested character styles
- Error-tolerant: always produces a document tree, even from malformed input
- Structured diagnostics with source locations, severity levels, and machine-readable codes
- Semantic validation (chapter/verse sequence, attribute rules, milestone pairing, etc.)
- Multiple output formats: USJ, USX, USFM, and verse-reference maps
Installation
[]
= "0.1"
Usage
let result = parse;
// Check for errors
for diag in result.diagnostics.iter
// Output as USJ (JSON)
let usj = to_usj_string_pretty.unwrap;
// Output as USX (XML)
let usx = to_usx_string.unwrap;
// Output as normalized USFM
let usfm = to_usfm_string;
// Output as verse-reference map
let vref = to_vref_json_string;
// Run semantic validation
let validation_diags = validate;
Output Formats
| Format | Function | Description |
|---|---|---|
| USJ | usj::to_usj_string() |
Unified Scripture JSON |
| USX | usx::to_usx_string() |
Unified Scripture XML |
| USFM | usfm::to_usfm_string() |
Normalized USFM with regularized whitespace |
| VRef | vref::to_vref_json_string() |
Verse reference to plain text map |
License
MIT