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§
Required Methods§
sourcefn decorate_link_start(&mut self, url: &str) -> (String, Self::Annotation)
fn decorate_link_start(&mut self, url: &str) -> (String, Self::Annotation)
Return an annotation and rendering prefix for a link.
sourcefn decorate_link_end(&mut self) -> String
fn decorate_link_end(&mut self) -> String
Return a suffix for after a link.
sourcefn decorate_em_start(&self) -> (String, Self::Annotation)
fn decorate_em_start(&self) -> (String, Self::Annotation)
Return an annotation and rendering prefix for em
sourcefn decorate_em_end(&self) -> String
fn decorate_em_end(&self) -> String
Return a suffix for after an em.
sourcefn decorate_strong_start(&self) -> (String, Self::Annotation)
fn decorate_strong_start(&self) -> (String, Self::Annotation)
Return an annotation and rendering prefix for strong
sourcefn decorate_strong_end(&self) -> String
fn decorate_strong_end(&self) -> String
Return a suffix for after a strong.
sourcefn decorate_strikeout_start(&self) -> (String, Self::Annotation)
fn decorate_strikeout_start(&self) -> (String, Self::Annotation)
Return an annotation and rendering prefix for strikeout
sourcefn decorate_strikeout_end(&self) -> String
fn decorate_strikeout_end(&self) -> String
Return a suffix for after a strikeout.
sourcefn decorate_code_start(&self) -> (String, Self::Annotation)
fn decorate_code_start(&self) -> (String, Self::Annotation)
Return an annotation and rendering prefix for code
sourcefn decorate_code_end(&self) -> String
fn decorate_code_end(&self) -> String
Return a suffix for after a code.
sourcefn decorate_preformat_first(&self) -> Self::Annotation
fn decorate_preformat_first(&self) -> Self::Annotation
Return an annotation for the initial part of a preformatted line
sourcefn decorate_preformat_cont(&self) -> Self::Annotation
fn decorate_preformat_cont(&self) -> Self::Annotation
Return an annotation for a continuation line when a preformatted line doesn’t fit.
sourcefn decorate_image(
&mut self,
src: &str,
title: &str
) -> (String, Self::Annotation)
fn decorate_image( &mut self, src: &str, title: &str ) -> (String, Self::Annotation)
Return an annotation and rendering prefix for a link.
sourcefn header_prefix(&self, level: usize) -> String
fn header_prefix(&self, level: usize) -> String
Return prefix string of header in specific level.
sourcefn quote_prefix(&self) -> String
fn quote_prefix(&self) -> String
Return prefix string of quoted block.
sourcefn unordered_item_prefix(&self) -> String
fn unordered_item_prefix(&self) -> String
Return prefix string of unordered list item.
sourcefn ordered_item_prefix(&self, i: i64) -> String
fn ordered_item_prefix(&self, i: i64) -> String
Return prefix string of ith ordered list item.
sourcefn make_subblock_decorator(&self) -> Self
fn make_subblock_decorator(&self) -> Self
Return a new decorator of the same type which can be used for sub blocks.
sourcefn finalise(&mut self, links: Vec<String>) -> Vec<TaggedLine<Self::Annotation>>
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§
sourcefn push_colour(&mut self, _: Colour) -> Option<Self::Annotation>
fn push_colour(&mut self, _: Colour) -> Option<Self::Annotation>
Return an annotation corresponding to adding colour, or none.
sourcefn pop_colour(&mut self) -> bool
fn pop_colour(&mut self) -> bool
Pop the last colour pushed if we pushed one.
sourcefn push_bgcolour(&mut self, _: Colour) -> Option<Self::Annotation>
fn push_bgcolour(&mut self, _: Colour) -> Option<Self::Annotation>
Return an annotation corresponding to adding background colour, or none.
sourcefn pop_bgcolour(&mut self) -> bool
fn pop_bgcolour(&mut self) -> bool
Pop the last background colour pushed if we pushed one.
sourcefn decorate_superscript_start(&self) -> (String, Self::Annotation)
fn decorate_superscript_start(&self) -> (String, Self::Annotation)
Return an annotation and rendering prefix for superscript text
sourcefn decorate_superscript_end(&self) -> String
fn decorate_superscript_end(&self) -> String
Return a suffix for after a superscript.