Skip to main content

OutputFormat

Trait OutputFormat 

Source
pub trait OutputFormat: Default + Clone {
    type Output;

Show 34 methods // Required methods fn text(&self, s: &str) -> Self::Output; fn join(&self, items: Vec<Self::Output>, delimiter: &str) -> Self::Output; fn finish(&self, output: Self::Output) -> String; fn emph(&self, content: Self::Output) -> Self::Output; fn strong(&self, content: Self::Output) -> Self::Output; fn small_caps(&self, content: Self::Output) -> Self::Output; fn superscript(&self, content: Self::Output) -> Self::Output; fn affix( &self, prefix: &str, content: Self::Output, suffix: &str, ) -> Self::Output; fn inner_affix( &self, prefix: &str, content: Self::Output, suffix: &str, ) -> Self::Output; fn wrap_punctuation( &self, wrap: &WrapPunctuation, content: Self::Output, marks: &QuoteMarks, script: ScriptClass, realization: Option<&PunctuationRealization>, ) -> Self::Output; fn semantic(&self, class: &str, content: Self::Output) -> Self::Output; fn annotation(&self, content: Self::Output) -> Self::Output; fn link(&self, url: &str, content: Self::Output) -> Self::Output; // Provided methods fn quote_marks<'a>( &self, depth: usize, marks: &'a QuoteMarks, ) -> (&'a str, &'a str) { ... } fn quote_with_depth( &self, content: Self::Output, depth: usize, marks: &QuoteMarks, ) -> Self::Output { ... } fn quote(&self, content: Self::Output, marks: &QuoteMarks) -> Self::Output { ... } fn paragraph(&self, content: Self::Output) -> Self::Output { ... } fn block_quote(&self, content: Self::Output) -> Self::Output { ... } fn bullet_list(&self, items: Vec<Self::Output>) -> Self::Output { ... } fn ordered_list(&self, items: Vec<Self::Output>) -> Self::Output { ... } fn list_item(&self, content: Self::Output) -> Self::Output { ... } fn heading(&self, _level: u8, content: Self::Output) -> Self::Output { ... } fn unnumbered_heading( &self, level: u8, content: Self::Output, ) -> Self::Output { ... } fn code_block( &self, _lang: Option<&str>, content: Self::Output, ) -> Self::Output { ... } fn inline_code(&self, content: Self::Output) -> Self::Output { ... } fn strikeout(&self, content: Self::Output) -> Self::Output { ... } fn hard_break(&self) -> Self::Output { ... } fn semantic_with_attributes( &self, class: &str, content: Self::Output, _attributes: &[SemanticAttribute], ) -> Self::Output { ... } fn citation(&self, _ids: Vec<String>, content: Self::Output) -> Self::Output { ... } fn visible_runs(&self, fragment: &str) -> Vec<Range<usize>> { ... } fn visible_text<'a>(&self, fragment: &'a str) -> Cow<'a, str> { ... } fn format_id(&self, id: &str) -> String { ... } fn bibliography(&self, entries: Vec<Self::Output>) -> Self::Output { ... } fn entry( &self, _id: &str, content: Self::Output, _url: Option<&str>, _metadata: &ProcEntryMetadata, ) -> Self::Output { ... }
}
Expand description

Trait for defining how to render template components into a specific format.

Implementations of this trait define how various formatting instructions (emphasis, quotes, links, etc.) are translated into specific markup or text.

Required Associated Types§

Source

type Output

The type used for intermediate rendered content.

For simple text formats, this is usually String. More complex formats might use an AST or a specialized builder type.

Required Methods§

Source

fn text(&self, s: &str) -> Self::Output

Convert a raw string into the format’s output type.

The implementation should handle any necessary character escaping required by the target format.

Source

fn join(&self, items: Vec<Self::Output>, delimiter: &str) -> Self::Output

Join multiple outputs into a single output using a delimiter.

Source

fn finish(&self, output: Self::Output) -> String

Convert the intermediate output into the final result string.

This is called exactly once at the end of the rendering process for a top-level component (citation or bibliography entry).

Source

fn emph(&self, content: Self::Output) -> Self::Output

Render content with emphasis (typically italics).

Source

fn strong(&self, content: Self::Output) -> Self::Output

Render content with strong emphasis (typically bold).

Source

fn small_caps(&self, content: Self::Output) -> Self::Output

Render content in small capitals.

Source

fn superscript(&self, content: Self::Output) -> Self::Output

Render content as superscript text.

Source

fn affix( &self, prefix: &str, content: Self::Output, suffix: &str, ) -> Self::Output

Apply outer prefix and suffix strings to the content.

These are typically the “prefix” and “suffix” fields from the Citum style.

Source

fn inner_affix( &self, prefix: &str, content: Self::Output, suffix: &str, ) -> Self::Output

Apply inner prefix and suffix strings to the content.

These are applied inside any wrapping punctuation.

Source

fn wrap_punctuation( &self, wrap: &WrapPunctuation, content: Self::Output, marks: &QuoteMarks, script: ScriptClass, realization: Option<&PunctuationRealization>, ) -> Self::Output

Wrap the content in specific punctuation (parentheses, brackets, or quotes).

marks supplies the locale-resolved quote characters for the Quotes variant. script selects the half-width or full-width glyph form for the Parentheses/Brackets variants — see realize_wrap and docs/specs/PUNCTUATION_REALIZATION.md.

Source

fn semantic(&self, class: &str, content: Self::Output) -> Self::Output

Apply a semantic identifier (class) to the content.

This is used for machine readability or fine-grained CSS styling. Examples include “citum-title”, “citum-author”, “citum-doi”.

Source

fn annotation(&self, content: Self::Output) -> Self::Output

Render an annotation block.

This is typically called at the end of a bibliography entry to render reader-supplied notes.

Hyperlink the content to a URL.

Provided Methods§

Source

fn quote_marks<'a>( &self, depth: usize, marks: &'a QuoteMarks, ) -> (&'a str, &'a str)

Return the opening and closing quote delimiters for a nesting depth.

Depth 0 is an outer quote pair, depth 1 is the first inner quote pair, and deeper levels alternate between those two pairs. marks carries the locale-resolved quote characters; callers with no resolved locale can pass &QuoteMarks::default() to keep the historical English fallback.

Source

fn quote_with_depth( &self, content: Self::Output, depth: usize, marks: &QuoteMarks, ) -> Self::Output

Render content enclosed in quotation marks at a specific nesting depth.

Source

fn quote(&self, content: Self::Output, marks: &QuoteMarks) -> Self::Output

Render content enclosed in outer quotation marks.

Source

fn paragraph(&self, content: Self::Output) -> Self::Output

Render a paragraph block.

Source

fn block_quote(&self, content: Self::Output) -> Self::Output

Render a block quotation.

Source

fn bullet_list(&self, items: Vec<Self::Output>) -> Self::Output

Render an unordered (bullet) list from pre-rendered item strings.

Source

fn ordered_list(&self, items: Vec<Self::Output>) -> Self::Output

Render an ordered (numbered) list from pre-rendered item strings.

Source

fn list_item(&self, content: Self::Output) -> Self::Output

Render a list item.

Source

fn heading(&self, _level: u8, content: Self::Output) -> Self::Output

Render a heading at the given level (1 = top-level).

Source

fn unnumbered_heading(&self, level: u8, content: Self::Output) -> Self::Output

Render an unnumbered heading at the given level.

Used for generated section headings (e.g. bibliography group headings) that must not participate in document section numbering. Defaults to Self::heading; formats with numbered headings (LaTeX) override this with their unnumbered variants.

Source

fn code_block(&self, _lang: Option<&str>, content: Self::Output) -> Self::Output

Render a fenced or indented code block with an optional language hint.

content is the raw (unescaped) code text.

Source

fn inline_code(&self, content: Self::Output) -> Self::Output

Render inline code.

Source

fn strikeout(&self, content: Self::Output) -> Self::Output

Render strikethrough text.

Source

fn hard_break(&self) -> Self::Output

Render a hard line break.

Source

fn semantic_with_attributes( &self, class: &str, content: Self::Output, _attributes: &[SemanticAttribute], ) -> Self::Output

Apply a semantic identifier plus optional attributes to the content.

Formats that do not support extra attributes can ignore them and reuse Self::semantic.

Source

fn citation(&self, _ids: Vec<String>, content: Self::Output) -> Self::Output

Render a full citation container with one or more reference IDs.

Source

fn visible_runs(&self, fragment: &str) -> Vec<Range<usize>>

Byte ranges of fragment that are visible (non-markup) text, in order.

The default treats the whole fragment as visible, which is correct for PlainText and safe for any third-party format that hasn’t implemented a lexer: boundary logic simply falls back to looking at raw characters, as it always has. Backends whose inline methods (emph, link, wrap_punctuation, …) emit markup should override this to exclude it.

Source

fn visible_text<'a>(&self, fragment: &'a str) -> Cow<'a, str>

The visible (markup-stripped) text of a rendered fragment.

Borrows fragment unchanged when it is entirely visible (the common case); otherwise stitches the visible runs into an owned String.

Source

fn format_id(&self, id: &str) -> String

Format a reference ID for use as a target or link (e.g. adding a prefix).

Source

fn bibliography(&self, entries: Vec<Self::Output>) -> Self::Output

Render a full bibliography container.

The default implementation joins the entries with double newlines.

Source

fn entry( &self, _id: &str, content: Self::Output, _url: Option<&str>, _metadata: &ProcEntryMetadata, ) -> Self::Output

Render a single bibliography entry with its unique identifier and optional link.

The default implementation just returns the content.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§