Trait html2text::render::text_renderer::TextDecorator

source ·
pub trait TextDecorator {
    type Annotation: Eq + PartialEq + Debug + Clone + Default;

Show 25 methods // Required methods fn decorate_link_start(&mut self, url: &str) -> (String, Self::Annotation); fn decorate_link_end(&mut self) -> String; fn decorate_em_start(&self) -> (String, Self::Annotation); fn decorate_em_end(&self) -> String; fn decorate_strong_start(&self) -> (String, Self::Annotation); fn decorate_strong_end(&self) -> String; fn decorate_strikeout_start(&self) -> (String, Self::Annotation); fn decorate_strikeout_end(&self) -> String; fn decorate_code_start(&self) -> (String, Self::Annotation); fn decorate_code_end(&self) -> String; fn decorate_preformat_first(&self) -> Self::Annotation; fn decorate_preformat_cont(&self) -> Self::Annotation; fn decorate_image( &mut self, src: &str, title: &str ) -> (String, Self::Annotation); fn header_prefix(&self, level: usize) -> String; fn quote_prefix(&self) -> String; fn unordered_item_prefix(&self) -> String; fn ordered_item_prefix(&self, i: i64) -> String; fn make_subblock_decorator(&self) -> Self; fn finalise( &mut self, links: Vec<String> ) -> Vec<TaggedLine<Self::Annotation>>; // Provided methods fn push_colour(&mut self, _: Colour) -> Option<Self::Annotation> { ... } fn pop_colour(&mut self) -> bool { ... } fn push_bgcolour(&mut self, _: Colour) -> Option<Self::Annotation> { ... } fn pop_bgcolour(&mut self) -> bool { ... } fn decorate_superscript_start(&self) -> (String, Self::Annotation) { ... } fn decorate_superscript_end(&self) -> String { ... }
}
Expand description

Allow decorating/styling text.

Decorating refers to adding extra text around the rendered version of some elements, such as surrounding emphasised text with * like in markdown: Some *bold* text. The decorations are formatted and wrapped along with the rest of the rendered text. This is suitable for rendering HTML to an environment where terminal attributes are not available.

In addition, instances of TextDecorator can also return annotations of an associated type Annotation which will be associated with spans of text. This can be anything from () as for PlainDecorator or a more featured type such as RichAnnotation. The annotated spans (TaggedLine) can be used by application code to add e.g. terminal colours or underlines.

Required Associated Types§

source

type Annotation: Eq + PartialEq + Debug + Clone + Default

An annotation which can be added to text, and which will be attached to spans of text.

Required Methods§

Return an annotation and rendering prefix for a link.

Return a suffix for after a link.

source

fn decorate_em_start(&self) -> (String, Self::Annotation)

Return an annotation and rendering prefix for em

source

fn decorate_em_end(&self) -> String

Return a suffix for after an em.

source

fn decorate_strong_start(&self) -> (String, Self::Annotation)

Return an annotation and rendering prefix for strong

source

fn decorate_strong_end(&self) -> String

Return a suffix for after a strong.

source

fn decorate_strikeout_start(&self) -> (String, Self::Annotation)

Return an annotation and rendering prefix for strikeout

source

fn decorate_strikeout_end(&self) -> String

Return a suffix for after a strikeout.

source

fn decorate_code_start(&self) -> (String, Self::Annotation)

Return an annotation and rendering prefix for code

source

fn decorate_code_end(&self) -> String

Return a suffix for after a code.

source

fn decorate_preformat_first(&self) -> Self::Annotation

Return an annotation for the initial part of a preformatted line

source

fn decorate_preformat_cont(&self) -> Self::Annotation

Return an annotation for a continuation line when a preformatted line doesn’t fit.

source

fn decorate_image( &mut self, src: &str, title: &str ) -> (String, Self::Annotation)

Return an annotation and rendering prefix for a link.

source

fn header_prefix(&self, level: usize) -> String

Return prefix string of header in specific level.

source

fn quote_prefix(&self) -> String

Return prefix string of quoted block.

source

fn unordered_item_prefix(&self) -> String

Return prefix string of unordered list item.

source

fn ordered_item_prefix(&self, i: i64) -> String

Return prefix string of ith ordered list item.

source

fn make_subblock_decorator(&self) -> Self

Return a new decorator of the same type which can be used for sub blocks.

source

fn finalise(&mut self, links: Vec<String>) -> Vec<TaggedLine<Self::Annotation>>

Finish with a document, and return extra lines (eg footnotes) to add to the rendered text.

Provided Methods§

source

fn push_colour(&mut self, _: Colour) -> Option<Self::Annotation>

Return an annotation corresponding to adding colour, or none.

source

fn pop_colour(&mut self) -> bool

Pop the last colour pushed if we pushed one.

source

fn push_bgcolour(&mut self, _: Colour) -> Option<Self::Annotation>

Return an annotation corresponding to adding background colour, or none.

source

fn pop_bgcolour(&mut self) -> bool

Pop the last background colour pushed if we pushed one.

source

fn decorate_superscript_start(&self) -> (String, Self::Annotation)

Return an annotation and rendering prefix for superscript text

source

fn decorate_superscript_end(&self) -> String

Return a suffix for after a superscript.

Object Safety§

This trait is not object safe.

Implementors§