Replace Transformer with Sanitizer

Tried to keep them separate but it was starting to get too messy. Users can just
pass in custom transformers in the second constructor argument. Plus, this more
closely matches the ruby sanitize API.

Changed config to be a struct. So far, have only made a `DEFAULT_CONFIG`. Need
to make all of the others as well.

Started working on a `remove_contents_when_unwrapped` option to the config that
will indicate whether to remove contents of elements that are unwrapped.
This commit is contained in:
2020-04-21 21:35:08 -04:00
parent 446aff77af
commit c9c89f3622
6 changed files with 373 additions and 229 deletions

25
src/config/default.rs Normal file
View File

@@ -0,0 +1,25 @@
use std::collections::{HashMap, HashSet};
use crate::sanitizer::SanitizerConfig;
lazy_static! {
pub static ref DEFAULT_CONFIG: SanitizerConfig = SanitizerConfig {
allow_comments: false,
allowed_elements: HashSet::new(),
allowed_attributes: HashSet::new(),
allowed_attributes_per_element: HashMap::new(),
add_attributes: HashMap::new(),
add_attributes_per_element: HashMap::new(),
allowed_protocols: HashMap::new(),
allowed_css_at_rules: HashSet::new(),
allowed_css_properties: HashSet::new(),
remove_contents_when_unwrapped: hashset! {
local_name!("iframe"),
local_name!("noembed"),
local_name!("noframes"),
local_name!("noscript"),
local_name!("script"),
local_name!("style"),
},
};
}