html2md/rewriter/
styles.rs

1use lol_html::html_content::{ContentType::Text, Element};
2
3/// Rewrite the initial elements that need extra styles.
4pub(crate) fn rewrite_style_element(el: &mut Element) -> Result<(), std::io::Error> {
5    let tag_name = el.tag_name();
6
7    let mark = match tag_name.as_str() {
8        "b" | "strong" => "**",
9        "i" | "em" => "*",
10        "s" | "del" => "~~",
11        "u" | "ins" => "__",
12        _ => return Ok(()), // Return early if tag is not one of the specified
13    };
14
15    el.before(mark, Text);
16    el.after(mark, Text);
17
18    Ok(())
19}
20
21/// Rewrite the initial elements that need extra styles.
22pub(crate) fn rewrite_style_element_send(
23    el: &mut lol_html::send::Element,
24) -> Result<(), std::io::Error> {
25    let tag_name = el.tag_name();
26
27    let mark = match tag_name.as_str() {
28        "b" | "strong" => "**",
29        "i" | "em" => "*",
30        "s" | "del" => "~~",
31        "u" | "ins" => "__",
32        _ => return Ok(()), // Return early if tag is not one of the specified
33    };
34
35    el.before(mark, Text);
36    el.after(mark, Text);
37
38    Ok(())
39}