fn load_bibtex(bibtex_data: String) -> Result<Value> {
    let bibtex_model = nom_bibtex::Bibtex::parse(&bibtex_data).map_err(|e| format!("{:?}", e))?;
    let mut bibtex_map = Map::new();

    let preambles_array =
        bibtex_model.preambles().iter().map(|v| Value::String(v.to_string())).collect();
    bibtex_map.insert(String::from("preambles"), Value::Array(preambles_array));

    let comments_array =
        bibtex_model.comments().iter().map(|v| Value::String(v.to_string())).collect();
    bibtex_map.insert(String::from("comments"), Value::Array(comments_array));

    let mut variables_map = Map::new();
    for (key, val) in bibtex_model.variables() {
        variables_map.insert(key.to_string(), Value::String(val.to_string()));
    }
    bibtex_map.insert(String::from("variables"), Value::Object(variables_map));

    let bibliographies_array = bibtex_model
        .bibliographies()
        .iter()
        .map(|b| {
            let mut m = Map::new();
            m.insert(String::from("entry_type"), Value::String(b.entry_type().to_string()));
            m.insert(String::from("citation_key"), Value::String(b.citation_key().to_string()));

            let mut tags = Map::new();
            for (key, val) in b.tags() {
                tags.insert(key.to_lowercase().to_string(), Value::String(val.to_string()));
            }
            m.insert(String::from("tags"), Value::Object(tags));
            Value::Object(m)
        })
        .collect();
    bibtex_map.insert(String::from("bibliographies"), Value::Array(bibliographies_array));

    let bibtex_value: Value = Value::Object(bibtex_map);
    to_value(bibtex_value).map_err(|err| err.into())
}
/// Parse a BIBTEX string and convert it to a Tera Value
Parse a BIBTEX string and convert it to a Tera Value
Parse a BIBTEX string and convert it to a Tera Value
fn load_bibtex(bibtex_data: String) -> Result<Value> {
    let bibtex_model = nom_bibtex::Bibtex::parse(&bibtex_data).map_err(|e| format!("{:?}", e))?;
    let mut bibtex_map = Map::new();
    let preambles_array =
        bibtex_model.preambles().iter().map(|v| Value::String(v.to_string())).collect();
    bibtex_map.insert(String::from("preambles"), Value::Array(preambles_array));
    let comments_array =
        bibtex_model.comments().iter().map(|v| Value::String(v.to_string())).collect();
    bibtex_map.insert(String::from("comments"), Value::Array(comments_array));
    let mut variables_map = Map::new();
    for (key, val) in bibtex_model.variables() {
        variables_map.insert(key.to_string(), Value::String(val.to_string()));
    }
    bibtex_map.insert(String::from("variables"), Value::Object(variables_map));
    let bibliographies_array = bibtex_model
        .bibliographies()
        .iter()
        .map(|b| {
            let mut m = Map::new();
            m.insert(String::from("entry_type"), Value::String(b.entry_type().to_string()));
            m.insert(String::from("citation_key"), Value::String(b.citation_key().to_string()));
            let mut tags = Map::new();
            for (key, val) in b.tags() {
                tags.insert(key.to_lowercase().to_string(), Value::String(val.to_string()));
            }
            m.insert(String::from("tags"), Value::Object(tags));
            Value::Object(m)
        })
        .collect();
    bibtex_map.insert(String::from("bibliographies"), Value::Array(bibliographies_array));
    let bibtex_value: Value = Value::Object(bibtex_map);
    to_value(bibtex_value).map_err(|err| err.into())
}
fn load_bibtex ( bibtex_data : String ) -> Result < Value > { let bibtex_model = nom_bibtex :: Bibtex :: parse ( & bibtex_data ) . map_err ( | e | format ! ( " " e ) ) ? ; let mut bibtex_map = Map :: new ( ) ; let preambles_array = bibtex_model . preambles ( ) . iter ( ) . map ( | v | Value :: String ( v . to_string ( ) ) ) . collect ( ) ; bibtex_map . insert ( String :: from ( " " ) , Value :: Array ( preambles_array ) ) ; let comments_array = bibtex_model . comments ( ) . iter ( ) . map ( | v | Value :: String ( v . to_string ( ) ) ) . collect ( ) ; bibtex_map . insert ( String :: from ( " " ) , Value :: Array ( comments_array ) ) ; let mut variables_map = Map :: new ( ) ; for ( key , val ) in bibtex_model . variables ( ) { variables_map . insert ( key . to_string ( ) , Value :: String ( val . to_string ( ) ) ) ; } bibtex_map . insert ( String :: from ( " " ) , Value :: Object ( variables_map ) ) ; let bibliographies_array = bibtex_model . bibliographies ( ) . iter ( ) . map ( | b | { let mut m = Map :: new ( ) ; m . insert ( String :: from ( " " ) , Value :: String ( b . entry_type ( ) . to_string ( ) ) ) ; m . insert ( String :: from ( " " ) , Value :: String ( b . citation_key ( ) . to_string ( ) ) ) ; let mut tags = Map :: new ( ) ; for ( key , val ) in b . tags ( ) { tags . insert ( key . to_lowercase ( ) . to_string ( ) , Value :: String ( val . to_string ( ) ) ) ; } m . insert ( String :: from ( " " ) , Value :: Object ( tags ) ) ; Value :: Object ( m ) } ) . collect ( ) ; bibtex_map . insert ( String :: from ( " " ) , Value :: Array ( bibliographies_array ) ) ; let bibtex_value : Value = Value :: Object ( bibtex_map ) ; to_value ( bibtex_value ) . map_err ( | err | err . into ( ) ) }
Parse a BIBTEX string and convert it to a Tera Value
Parse a BIBTEX string and convert it to a Tera Value
bibtex_data
String
bibtex_data
String