Skip to main content

CitationParser

Trait CitationParser 

Source
pub trait CitationParser {
    // Required method
    fn parse_document(&self, content: &str, locale: &Locale) -> ParsedDocument;

    // Provided methods
    fn finalize_html_output(&self, rendered: &str) -> String { ... }
    fn render_body_markup<F>(&self, body: &str, _fmt: &F) -> String
       where F: OutputFormat<Output = String> { ... }
    fn parse_citations(
        &self,
        content: &str,
        locale: &Locale,
    ) -> Vec<(usize, usize, Citation)> { ... }
}
Expand description

A trait for document parsers that can identify citations.

Each implementation is a format-specific adapter (Djot, Markdown, etc.). Adapters are responsible for source-syntax citation parsing, note discovery, frontmatter extraction, bibliography block detection, and HTML finalization. The shared pipeline consumes the resulting ParsedDocument without inspecting format-specific internals.

Required Methods§

Source

fn parse_document(&self, content: &str, locale: &Locale) -> ParsedDocument

Parse the document into citation placements and note metadata.

Provided Methods§

Source

fn finalize_html_output(&self, rendered: &str) -> String

Finalize rendered document markup as HTML.

Called after citation strings have been spliced back into the source markup and the result must be converted to HTML. The default implementation is a pass-through: it returns the markup unchanged. Format-specific adapters that require a markup-to-HTML conversion step (e.g. Djot via jotdown) must override this method.

Source

fn render_body_markup<F>(&self, body: &str, _fmt: &F) -> String
where F: OutputFormat<Output = String>,

Convert raw document body markup (with NUL citation placeholder tokens) to the target output format.

Called after citations have been replaced with NUL placeholder tokens. The default implementation returns the body unchanged (passthrough), which is correct for formats that have a downstream markup processor (HTML via finalize_html_output) or that emit verbatim markup (Plain, Djot, Markdown). Format-specific adapters that perform markup-to-target conversion for Typst/LaTeX must override this method.

Source

fn parse_citations( &self, content: &str, locale: &Locale, ) -> Vec<(usize, usize, Citation)>

Find and extract citations from a document string.

Returns a list of (start_index, end_index, citation_model) tuples.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§