Skip to main content

TagHandlerFactory

Trait TagHandlerFactory 

Source
pub trait TagHandlerFactory {
    // Required method
    fn instantiate(&self) -> Box<dyn TagHandler>;
}
Expand description

TagHandler factory. This trait is required in providing proper custom tag parsing capabilities to users of this library.

The problem with directly providing tag handlers is that they’re not stateless. Once tag handler is parsing some tag, it holds data, such as start position, indent etc.

Since there is a blanket impl on Fn() -> TagHandler, any function or closure returning TagHandler can be used in place of a dedicated TagHandlerFactory instance, including trait functions like Default::default.

§Examples

use std::collections::HashMap;
use html2md::{parse_html_custom, TagHandlerFactory, dummy::DummyHandler};

let mut tag_factory: HashMap<String, Box<dyn TagHandlerFactory>> = HashMap::new();
tag_factory.insert(
    String::from("span"),
    Box::new(DummyHandler::default),
);
let markdown = parse_html_custom(html, &tag_factory);

Required Methods§

Source

fn instantiate(&self) -> Box<dyn TagHandler>

Implementors§

Source§

impl<F: Fn() -> T, T: TagHandler + 'static> TagHandlerFactory for F