diff options
Diffstat (limited to 'src/utils/html_to_md.rs')
| -rw-r--r-- | src/utils/html_to_md.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/utils/html_to_md.rs b/src/utils/html_to_md.rs new file mode 100644 index 0000000..2bc5e54 --- /dev/null +++ b/src/utils/html_to_md.rs @@ -0,0 +1,18 @@ +use std::{cell::RefCell, rc::Rc}; + +use html_to_markdown::{markdown, TagHandler}; + +pub fn html_to_md(html: &str) -> String { + let mut handlers: Vec<TagHandler> = vec![ + Rc::new(RefCell::new(markdown::ParagraphHandler)), + Rc::new(RefCell::new(markdown::HeadingHandler)), + Rc::new(RefCell::new(markdown::ListHandler)), + Rc::new(RefCell::new(markdown::TableHandler::new())), + Rc::new(RefCell::new(markdown::StyledTextHandler)), + Rc::new(RefCell::new(markdown::CodeHandler)), + Rc::new(RefCell::new(markdown::WebpageChromeRemover)), + ]; + + html_to_markdown::convert_html_to_markdown(html.as_bytes(), &mut handlers) + .unwrap_or_else(|_| html.to_string()) +} |
