pub trait Writer {
Show 13 methods
// Required method
fn write(
&self,
document: &Document,
options: &WriterOptions,
) -> Result<String>;
// Provided methods
fn render_meta_inlines(
&self,
inlines: &[Inline],
options: &WriterOptions,
) -> Result<String> { ... }
fn render_meta_blocks(
&self,
blocks: &[Block],
options: &WriterOptions,
) -> Result<String> { ... }
fn default_template(&self) -> Option<&'static str> { ... }
fn standalone_document(
&self,
document: &Document,
options: &WriterOptions,
) -> Result<Option<String>> { ... }
fn meta_var_style(&self) -> MetaVarStyle { ... }
fn flatten_block_metadata(&self) -> bool { ... }
fn title_block(
&self,
document: &Document,
options: &WriterOptions,
) -> Result<Option<String>> { ... }
fn body_ends_with_newline(&self) -> bool { ... }
fn toc_style(&self) -> TocStyle { ... }
fn toc_link_anchors(&self) -> bool { ... }
fn numbers_sections_natively(&self) -> bool { ... }
fn numbers_sections_in_body(&self) -> bool { ... }
}Expand description
Renders the document model into some target format’s text.
The returned string carries no trailing newline; the CLI appends exactly one.
Required Methods§
Provided Methods§
Sourcefn render_meta_inlines(
&self,
inlines: &[Inline],
options: &WriterOptions,
) -> Result<String>
fn render_meta_inlines( &self, inlines: &[Inline], options: &WriterOptions, ) -> Result<String>
Render an inline sequence in this format, for interpolating inline metadata (a title, an
author) into a template variable. Wrapping the inlines in a Block::Plain yields them
with no paragraph chrome across formats; a writer whose Plain diverges overrides this.
§Errors
Propagates any error from Writer::write.
Sourcefn render_meta_blocks(
&self,
blocks: &[Block],
options: &WriterOptions,
) -> Result<String>
fn render_meta_blocks( &self, blocks: &[Block], options: &WriterOptions, ) -> Result<String>
Render a block sequence in this format, for interpolating block metadata (an abstract
authored as Markdown blocks) into a template variable.
§Errors
Propagates any error from Writer::write.
Sourcefn default_template(&self) -> Option<&'static str>
fn default_template(&self) -> Option<&'static str>
This format’s own standalone template, or None when standalone output is identical to the
fragment (no wrapping document exists for the format).
Sourcefn standalone_document(
&self,
document: &Document,
options: &WriterOptions,
) -> Result<Option<String>>
fn standalone_document( &self, document: &Document, options: &WriterOptions, ) -> Result<Option<String>>
A standalone document this format assembles structurally, embedding the metadata and block
list in one value rather than wrapping a text body in a template — the data form is the
canonical example. Returned in place of template rendering. None (the default) when the
format wraps its body with a text template instead.
§Errors
Propagates any error from rendering the document.
Sourcefn meta_var_style(&self) -> MetaVarStyle
fn meta_var_style(&self) -> MetaVarStyle
Which plain-text identity variables this writer’s standalone template draws on — the title,
authors, and date as markup-free text. The default is MetaVarStyle::None; an HTML-family
writer returns MetaVarStyle::Web and a LaTeX-family writer MetaVarStyle::Pdf.
Sourcefn flatten_block_metadata(&self) -> bool
fn flatten_block_metadata(&self) -> bool
Whether block-shaped metadata is flattened to its inline content when built into the template
context. A writer that places title, author, and date into single-line header fields — a man
page’s .TH line cannot carry paragraph structure — sets this so a lone-paragraph value
contributes its inline text and any other block shape contributes nothing. The default false
renders block metadata as blocks.
Sourcefn title_block(
&self,
document: &Document,
options: &WriterOptions,
) -> Result<Option<String>>
fn title_block( &self, document: &Document, options: &WriterOptions, ) -> Result<Option<String>>
A title presentation the template language cannot express from individual variables — an
underlined title for reStructuredText, say, whose rule length depends on the rendered title
width. Exposed to the template as the titleblock variable. None (the default) when the
format builds its title presentation from individual variables instead.
§Errors
Propagates any error from rendering the metadata.
Sourcefn body_ends_with_newline(&self) -> bool
fn body_ends_with_newline(&self) -> bool
Whether this writer lays the document out as newline-terminated lines, so a non-empty body
template variable ends with a newline. Writers that build their markup as one string ending
at its final glyph (HTML, LaTeX, and the like) leave the default false.
Sourcefn toc_style(&self) -> TocStyle
fn toc_style(&self) -> TocStyle
How this writer supplies a table of contents. The default renders a nested list into the
toc variable; a format whose template assembles its own contents from a directive overrides
to TocStyle::Native.
Sourcefn toc_link_anchors(&self) -> bool
fn toc_link_anchors(&self) -> bool
Whether a list-style table of contents attaches a back-reference anchor — an id on each
entry’s link — so the entries can be linked to. The default includes them; a format that
cannot represent an inline identifier (so an attributed link would degrade to raw markup)
overrides to false. Honored only when toc_style is TocStyle::List.
Sourcefn numbers_sections_natively(&self) -> bool
fn numbers_sections_natively(&self) -> bool
Whether this format numbers sections with its own typesetting counter rather than carrying the
number in the heading text. The default splices a header-section-number span into each
heading; a format with a native counter (the typesetting formats) overrides to true and is
driven by a numbersections template flag instead.
Sourcefn numbers_sections_in_body(&self) -> bool
fn numbers_sections_in_body(&self) -> bool
Whether this writer carries section numbers in the heading text, so the number is spliced into
each heading before rendering (and contents entries inherit it). The default leaves headings
untouched; a format that renders the number inline (HTML) overrides to true. A format with a
native counter relies on numbers_sections_natively
instead and leaves this false.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".