1mod driver;
2mod entry;
3pub(crate) mod field;
4mod output;
5
6use unicode_normalization::UnicodeNormalization;
7
8use crate::syntax::bibtex;
9
10use self::{driver::Driver, output::Inline};
11
12#[must_use]
13pub fn render(entry: &bibtex::Entry) -> Option<String> {
14 let mut output = String::new();
15 let mut driver = Driver::default();
16 driver.process(entry);
17 driver.finish().for_each(|(inline, punct)| {
18 let text = match inline {
19 Inline::Regular(text) => text,
20 Inline::Italic(text) => format!("*{text}*"),
21 Inline::Quoted(text) => format!("\"{text}\""),
22 Inline::Link { url, alt } => format!("[{alt}]({url})"),
23 };
24 output.push_str(&text);
25 output.push_str(punct.as_str());
26 });
27
28 if output.is_empty() {
29 None
30 } else {
31 output.push('.');
32 Some(output.nfc().collect())
33 }
34}
35
36#[cfg(test)]
37mod tests;