rust-html2text icon indicating copy to clipboard operation
rust-html2text copied to clipboard

Text decorator functions for all elements?

Open robinkrahl opened this issue 5 years ago • 2 comments

Is it possible to implement text decorator functions for all elements? The current implementations for plain and rich text are already very helpful, but I would like to tweak the appearance of some specific elements. Let’s say I want to print headings with a bold typeface or I want to set the color based on the element’s class. This could be done with functions like:

fn decorate_element_start(&self, name: &str, attrs: HashMap<String, String>) -> Self::Annotation
fn decorate_element_end(&self, name: &str) -> Self::Annotation

robinkrahl avatar Jul 21 '20 21:07 robinkrahl

That sounds potentially useful, and could become part of the solution for #20.

I'm slightly concerned at the overhead (creating hash maps and calling the decorator for every element), but I guess the compiler could remove most of that for decorators which don't make use of it.

jugglerchris avatar Jul 22 '20 20:07 jugglerchris