fn embed_html(html: &String) -> Result<String, std::io::Error> {
    let re = Regex::new(r#"(?P<before><img src=")(?P<filepath>.*?)(?P<after>".*>)"#).unwrap();
    let result = re.replace_all(&html, |caps: &Captures| {
        println!("Captured image: {:?}", &caps["filepath"]);
        let img = caps["filepath"].to_owned();
        let filetype = Path::new(&img)
        .extension()
        .and_then(OsStr::to_str).unwrap();
        println!("{}", img);
        let mut f = std::fs::File::open(&img).unwrap();
        let mut buffer = Vec::new();
        f.read_to_end(&mut buffer).unwrap();
        format!("{}data:image/{};base64,{}{}",&caps["before"], filetype, base64::encode(buffer), &caps["after"])
    });
    Ok(String::from(result.as_ref()))
}
/// Embeds image sources as base64 strings. This is useful for single-file documentation
Embeds image sources as base64 strings. This is useful for single-file documentation
Embeds image sources as base64 strings . This is useful for single - file documentation
fn embed_html(html: &String) -> Result<String, std::io::Error> {
    let re = Regex::new(r#"(?P<before><img src=")(?P<filepath>.*?)(?P<after>".*>)"#).unwrap();
    let result = re.replace_all(&html, |caps: &Captures| {
        println!("Captured image: {:?}", &caps["filepath"]);
        let img = caps["filepath"].to_owned();
        let filetype = Path::new(&img)
        .extension()
        .and_then(OsStr::to_str).unwrap();
        println!("{}", img);
        let mut f = std::fs::File::open(&img).unwrap();
        let mut buffer = Vec::new();
        f.read_to_end(&mut buffer).unwrap();
        format!("{}data:image/{};base64,{}{}",&caps["before"], filetype, base64::encode(buffer), &caps["after"])
    });
    Ok(String::from(result.as_ref()))
}
fn embed_html ( html : & String ) -> Result < String , std :: io :: Error > { let re = Regex :: new ( r#"(?P<before><img src=")(?P<filepath>.*?)(?P<after>".*>)"# ) . unwrap ( ) ; let result = re . replace_all ( & html , | caps : & Captures | { println ! ( " " caps [ " " ] ) ; let img = caps [ " " ] . to_owned ( ) ; let filetype = Path :: new ( & img ) . extension ( ) . and_then ( OsStr :: to_str ) . unwrap ( ) ; println ! ( " " img ) ; let mut f = std :: fs :: File :: open ( & img ) . unwrap ( ) ; let mut buffer = Vec :: new ( ) ; f . read_to_end ( & mut buffer ) . unwrap ( ) ; format ! ( " " caps [ " " ] filetype base64 encode ( buffer ) caps [ " " ] ) } ) ; Ok ( String :: from ( result . as_ref ( ) ) ) }
Embeds image sources as base64 strings.
Embeds image sources as base64 strings .
html
&String
html
&String