InlineSubstitutionRenderer

Trait InlineSubstitutionRenderer 

Source
pub trait InlineSubstitutionRenderer: Debug {
    // Required methods
    fn render_special_character(
        &self,
        type_: SpecialCharacter,
        dest: &mut String,
    );
    fn render_quoted_substitition(
        &self,
        type_: QuoteType,
        scope: QuoteScope,
        attrlist: Option<Attrlist<'_>>,
        id: Option<String>,
        body: &str,
        dest: &mut String,
    );
    fn render_character_replacement(
        &self,
        type_: CharacterReplacementType,
        dest: &mut String,
    );
    fn render_line_break(&self, dest: &mut String);
    fn render_image(&self, params: &ImageRenderParams<'_>, dest: &mut String);
    fn image_uri(
        &self,
        target_image_path: &str,
        parser: &Parser,
        asset_dir_key: Option<&str>,
    ) -> String;
    fn render_icon(&self, params: &IconRenderParams<'_>, dest: &mut String);
    fn render_link(&self, params: &LinkRenderParams<'_>, dest: &mut String);
    fn render_anchor(
        &self,
        id: &str,
        reftext: Option<String>,
        dest: &mut String,
    );

    // Provided method
    fn icon_uri(
        &self,
        name: &str,
        _attrlist: &Attrlist<'_>,
        parser: &Parser,
    ) -> String { ... }
}
Expand description

An implementation of InlineSubstitutionRenderer is used when converting the basic raw text of a simple block to the format which will ultimately be presented in the final converted output.

An implementation is provided for HTML output; alternative implementations (not provided in this crate) could support other output formats.

Required Methods§

Source

fn render_special_character(&self, type_: SpecialCharacter, dest: &mut String)

Renders the substitution for a special character.

The renderer should write the appropriate rendering to dest.

Source

fn render_quoted_substitition( &self, type_: QuoteType, scope: QuoteScope, attrlist: Option<Attrlist<'_>>, id: Option<String>, body: &str, dest: &mut String, )

Renders the content of a quote substitution.

The renderer should write the appropriate rendering to dest.

Source

fn render_character_replacement( &self, type_: CharacterReplacementType, dest: &mut String, )

Renders the content of a character replacement.

The renderer should write the appropriate rendering to dest.

Source

fn render_line_break(&self, dest: &mut String)

Renders a line break.

The renderer should write an appropriate rendering of line break to dest.

This is used in the implementation of post-replacement substitutions.

Source

fn render_image(&self, params: &ImageRenderParams<'_>, dest: &mut String)

Renders an image.

The renderer should write an appropriate rendering of the specified image to dest.

Source

fn image_uri( &self, target_image_path: &str, parser: &Parser, asset_dir_key: Option<&str>, ) -> String

Construct a URI reference or data URI to the target image.

If the target_image_path is a URI reference, then leave it untouched.

The target_image_path is resolved relative to the directory retrieved from the specified document-scoped attribute key, if provided.

NOT YET IMPLEMENTED: If the data-uri attribute is set on the document, and the safe mode level is less than SafeMode::SECURE, the image will be safely converted to a data URI by reading it from the same directory. If neither of these conditions are satisfied, a relative path (i.e., URL) will be returned.

§Parameters
  • target_image_path: path to the target image
  • parser: Current document parser state
  • asset_dir_key: If provided, the attribute key used to look up the directory where the image is located. If not provided, imagesdir is used.
§Return

Returns a string reference or data URI for the target image that can be safely used in an image tag.

Source

fn render_icon(&self, params: &IconRenderParams<'_>, dest: &mut String)

Renders an icon.

The renderer should write an appropriate rendering of the specified icon to dest.

Renders a link.

The renderer should write an appropriate rendering of the specified link, to dest.

Source

fn render_anchor(&self, id: &str, reftext: Option<String>, dest: &mut String)

Renders an anchor.

The rendered should write an appropriate rendering of the specified anchor with ID and possible ref text (only used by some renderers).

Provided Methods§

Source

fn icon_uri( &self, name: &str, _attrlist: &Attrlist<'_>, parser: &Parser, ) -> String

Construct a reference or data URI to an icon image for the specified icon name.

If the icon attribute is set on this block, the name is ignored and the value of this attribute is used as the target image path. Otherwise, construct a target image path by concatenating the value of the iconsdir attribute, the icon name, and the value of the icontype attribute (defaulting to png).

The target image path is then passed through the image_uri() method. If the data-uri attribute is set on the document, the image will be safely converted to a data URI.

The return value of this method can be safely used in an image tag.

Implementors§