Crates.io | bibparser |
lib.rs | bibparser |
version | 0.4.0 |
source | src |
created_at | 2022-01-30 01:32:44.36296 |
updated_at | 2022-07-16 00:43:18.652465 |
description | A parser for .bib files |
homepage | |
repository | https://github.com/typho/bibparser |
max_upload_size | |
id | 523844 |
size | 60,449 |
A Rust crate for parsing BibTeχ and BibLaTeχ files.
As opposed to the biblatex
crate, this crate does not try to interpret the content of fields.
This crate resulted from the usecase that biblatex
threw an error when math inline mode was not terminated before text was cut off.
Anyone, how wants to retrieve data from a .bib
file.
Add this to your Cargo.toml
:
[dependencies]
bibparser = "0.4.0"
Instantiate the parser and iterate over the items:
use bibparser::Parser;
//let mut p = Parser::from_file("source.bib")?;
let mut p = Parser::from_str(r#"@book{tolkien1937, author = {J. R. R. Tolkien}}"#)?;
for result in p.iter() {
let entry = result?;
println!("type = {}", entry.kind);
println!("id = {}", entry.id);
for (name, data) in entry.fields.iter() {
println!("\t{}\t= {}", name, data);
}
}
This library comes with one example:
$ cargo run --example cli -- --input refs.bib
You can also enable serde-json support in order to print data as JSON:
$ cargo run --features serde,serde_json --example cli -- --input refs.bib --json
In this example, the library would read file refs.bib
and then only print the entry with ID tolkien1937
to stdout.
On github.
On github.
.bib
are strongly associated with Teχ which is a programming language, not a markup language. As such only the plain Teχ engine would be capable of understanding the content (esp. the field's data
content). This library explicitly takes the approach to assume the content to be a markup language, which hopefully serves 99% of all usecases.