Sanitize::Policy::Whitelist
Inherits Sanitize::Policy / Reference / Object
This is a simple policy based on a tag and attribute whitelist.
This policy accepts only <div> and <p> tags with optional title attributes:
policy = Sanitize::Policy::Whitelist.new({
"div" => Set{"title"},
"p" => Set{"title"},
})
The special * key applies to all tag names and can be used to allow global
attributes:
This example is equivalent to the above. If more tag names were added, they
would also accept title attributes.
policy = Sanitize::Policy::Whitelist.new({
"div" => Set(String).new,
"p" => Set(String).new,
"*" => Set{"title"},
})
Attributes are always optional, so this policy won't enforce the presence of an attribute.
If a tag's attribute list is empty, no attributes are allowed for this tag.
Attribute values are not changed by this policy.
Constructors
Instance methods
Mapping of accepted tag names and attributes.
Receives the element name and attributes of an opening tag and returns the transformed element name (usually the same as the input name).
attributes are transformed directly in place.
Special return values:
Processor::CONTINUE: Tells the processor to strip the current tag but continue traversing its children.Processor::CONTINUE: Tells the processor to skip the current tag and its children completely and move to the next sibling.
Receives the content of a text node and returns the transformed content.
If the return value is nil, the content is skipped.