Convert URL from relative to absolute

Greetings,

Please advice pointers, sample code to convert all relative urls to absolute urls in an html document, using Rust.

Best Regards,
G

You'll need https://lib.rs/html5ever and the https://lib.rs/url crate. Check out https://lib.rs/ammonia — it already filters HTML and URLs in them.

This is great! It narrowed my searching scope.

I have figured following code, but looks like I got more than I wished. I only need rel2abs conversion nothing else. Is there way to disable all other functions of ammonia.clean?

pub fn _rel2abs(base_url: &str, input: &str) -> String {
Builder::new().url_relative(UrlRelative::RewriteWithBase(
Url::parse(base_url).unwrap(),
))
.clean(input)
.to_string()
}

The codes seems working for a small html fragment, not a complete document.