glowpub 0.5.0

A glowfic to epub converter.
Documentation
use std::borrow::Cow;

use lol_html::{ElementContentHandlers, RewriteStrSettings, rewrite_str};

pub fn edit_image_urls(content: &str, mut f: impl FnMut(String) -> String) -> String {
    rewrite_str(
        content,
        RewriteStrSettings {
            element_content_handlers: vec![(
                Cow::Owned("img".parse().unwrap()),
                ElementContentHandlers::default().element(|el| {
                    if let Some(url) = el.get_attribute("src") {
                        let new_url = f(url);
                        el.set_attribute("src", &new_url).unwrap();
                    }
                    Ok(())
                }),
            )],
            ..RewriteStrSettings::default()
        },
    )
    .unwrap()
}