pickaxe/
markdown.rs

1pub use htmd::HtmlToMarkdown;
2
3use crate::errors::{PackageError, Result};
4
5
6/// Convert an HTML string to markdown with the specified converter.
7///
8/// * `html` - The HTML string to convert.
9/// * `converter` - The converter to use.
10pub fn html_to_markdown_with_converter(html: String, converter: HtmlToMarkdown) -> Result<String> {
11    Ok(
12        converter.convert(&html)
13            .map_err(|e| PackageError::UnknownError(e.to_string()))?
14    )
15}
16
17/// Convert an HTML string to markdown.
18/// 
19/// * `html` - The HTML string to convert.
20pub fn html_to_markdown(html: String) -> Result<String> {
21    Ok(
22        html_to_markdown_with_converter(
23            html,
24            HtmlToMarkdown::builder()
25                .skip_tags(vec!["script", "style", "img"])
26                .build()
27        )?
28    )
29}