Greetings,
Please advice pointers, sample code to convert all relative urls to absolute urls in an html document, using Rust.
Best Regards,
G
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 html5ever — Rust parser // Lib.rs and the URL — Rust parser // Lib.rs crate. Check out Ammonia — Rust web dev library // Lib.rs — 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.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.