Struct html2text::config::Config

source ·
pub struct Config<D: TextDecorator> { /* private fields */ }
Expand description

Configure the HTML processing.

Implementations§

source§

impl<D: TextDecorator> Config<D>

source

pub fn parse_html<R: Read>(&self, input: R) -> Result<RcDom, Error>

Parse the HTML into a DOM structure.

source

pub fn dom_to_render_tree(&self, dom: &RcDom) -> Result<RenderTree, Error>

Convert an HTML DOM into a RenderTree.

source

pub fn render_to_string( &self, render_tree: RenderTree, width: usize ) -> Result<String, Error>

Render an existing RenderTree into a string.

source

pub fn render_to_lines( &self, render_tree: RenderTree, width: usize ) -> Result<Vec<TaggedLine<Vec<D::Annotation>>>, Error>

Take an existing RenderTree, and returns text wrapped to width columns. The text is returned as a Vec<TaggedLine<_>>; the annotations are vectors of the provided text decorator’s Annotation. The “outer” annotation comes first in the Vec.

source

pub fn string_from_read<R: Read>( self, input: R, width: usize ) -> Result<String, Error>

Reads HTML from input, and returns a String with text wrapped to width columns.

source

pub fn lines_from_read<R: Read>( self, input: R, width: usize ) -> Result<Vec<TaggedLine<Vec<D::Annotation>>>, Error>

Reads HTML from input, and returns text wrapped to width columns. The text is returned as a Vec<TaggedLine<_>>; the annotations are vectors of the provided text decorator’s Annotation. The “outer” annotation comes first in the Vec.

source

pub fn pad_block_width(self) -> Self

Pad lines out to the full render width.

source

pub fn max_wrap_width(self, wrap_width: usize) -> Self

Set the maximum text wrap width. When set, paragraphs will be wrapped to that width even if there is more total width available for rendering.

source

pub fn allow_width_overflow(self) -> Self

Allow the output to be wider than the max width. When enabled, then output wider than the specified width will be returned instead of returning Err(TooNarrow) if the output wouldn’t otherwise fit.

source

pub fn min_wrap_width(self, min_wrap_width: usize) -> Self

Set the minimum width for text wrapping. The default is 3. Blocks of text will be forced to have at least this width (unless the text inside is less than that). Increasing this can increase the chance that the width will overflow, leading to a TooNarrow error unless allow_width_overflow() is set.

source

pub fn raw_mode(self, raw: bool) -> Self

Raw extraction, ensures text in table cells ends up rendered together This traverses tables as if they had a single column and every cell is its own row. Implies no_table_borders()

source

pub fn no_table_borders(self) -> Self

Do not render table borders

source§

impl Config<RichDecorator>

source

pub fn coloured<R, FMap>( self, input: R, width: usize, colour_map: FMap ) -> Result<String, Error>
where R: Read, FMap: Fn(&[RichAnnotation], &str) -> String,

Return coloured text. colour_map is a function which takes a list of RichAnnotation and some text, and returns the text with any terminal escapes desired to indicate those annotations (such as colour).

source

pub fn render_coloured<FMap>( &self, render_tree: RenderTree, width: usize, colour_map: FMap ) -> Result<String, Error>
where FMap: Fn(&[RichAnnotation], &str) -> String,

Return coloured text from a RenderTree. colour_map is a function which takes a list of RichAnnotation and some text, and returns the text with any terminal escapes desired to indicate those annotations (such as colour).

Auto Trait Implementations§

§

impl<D> Freeze for Config<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for Config<D>
where D: RefUnwindSafe,

§

impl<D> Send for Config<D>
where D: Send,

§

impl<D> Sync for Config<D>
where D: Sync,

§

impl<D> Unpin for Config<D>
where D: Unpin,

§

impl<D> UnwindSafe for Config<D>
where D: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.