rust-ammonia / ammonia

Repair and secure untrusted HTML
Apache License 2.0
524 stars 43 forks source link

Set attribute based on value of another - attribute_filter enhancement? #163

Open OJFord opened 2 years ago

OJFord commented 2 years ago

Sorry if this is already possible, but I don't think it is: I'd like to be able to use attribute_filter, or something like it, in order to set a different attrB using (or not) the value from the attrA that was present and found by the filter (attrB may or may not exist already).

For example it might look something like:

use ammonia::Builder;
let a = Builder::new()
    .attribute_filter(|element, attribute, value| {
        match (element, attribute) {
            ("a", "href") => Some(hashset![("href", value), ("title", value)]),
            _ => None
        }
    })