mod mapping;
mod tables;
use std::fs;
use std::path::Path;
use citum_schema::InputBibliography;
pub use mapping::{contributors_from_biblatex_persons, input_reference_from_biblatex};
pub use tables::{
BiblatexEntryTypeDescriptor, BiblatexFieldDescriptor, biblatex_entry_type_descriptors,
biblatex_field_descriptors,
};
use crate::RefsError;
pub fn parse_biblatex_str(src: &str) -> Result<InputBibliography, RefsError> {
let bibliography = ::biblatex::Bibliography::parse(src)
.map_err(|e| RefsError::ParseError("BibLaTeX".to_string(), e.to_string()))?;
let references = bibliography
.iter()
.map(mapping::input_reference_from_biblatex)
.collect();
Ok(InputBibliography {
references,
..Default::default()
})
}
pub fn load_biblatex(path: &Path) -> Result<InputBibliography, RefsError> {
let src = fs::read_to_string(path)?;
parse_biblatex_str(&src)
}