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