mini-cite 0.2.0

BibTeX-backed inline citations and footnotes for the mini-* family.
Documentation
//! Renders a parsed BibTeX entry into a one-line citation string.
//!
//! Deliberately style-agnostic: there is no CSL engine here and no per-entry-type
//! template — an `@article` and a `@book` render the same way. The goal is a readable
//! footnote line, not bibliographic conformance.

use crate::parser::Entry;

/// The fields rendered, in output order.
///
/// A field absent from an entry contributes nothing — no placeholder, and no
/// separator, so a missing `journal` cannot leave a stray `. .` in the output.
const RENDERED_FIELDS: [&str; 5] = ["author", "title", "journal", "publisher", "year"];

/// Renders one entry as a single-line citation.
///
/// `key` is the citation key the entry was loaded under. It is the fallback when the
/// entry carries none of [`RENDERED_FIELDS`] — a footnote reading `smith2020` is
/// unhelpful, but an empty footnote is worse, and both are better than a build that
/// fails over a thin `.bib` record.
pub fn format_citation(key: &str, entry: &Entry) -> String {
    let rendered = RENDERED_FIELDS
        .iter()
        .filter_map(|field| entry.fields.get(*field))
        .map(|value| value.trim())
        .filter(|value| !value.is_empty())
        .collect::<Vec<_>>()
        .join(". ");

    if rendered.is_empty() {
        return key.to_string();
    }

    // One terminating period, whether or not the last field already ended in one.
    match rendered.ends_with(['.', '!', '?']) {
        true => rendered,
        false => format!("{rendered}."),
    }
}

#[cfg(test)]
#[path = "../tests/unit/format.rs"]
mod tests;