abstract class Sanitize::Policy
- Sanitize::Policy
- Reference
- Object
Overview
A policy defines the rules for transforming an HTML/XML tree.
HTMLSanitizer
is a policy for HTML sanitization.Whitelist
is a whitelist-based transformer that's useful either for simple stripping applications or as a building block for more advanced sanitization policies.Text
is a policy that turns HTML into plain text.
Direct Known Subclasses
Defined in:
Constant Summary
-
HTML_BLOCK_ELEMENTS =
Set {"address", "article", "aside", "audio", "video", "blockquote", "br", "canvas", "dd", "div", "dl", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "noscript", "ol", "output", "p", "pre", "section", "table", "tfoot", "ul"}
Instance Method Summary
- #block_tag?(name)
-
#block_whitespace : String
Defines the string that is added when whitespace is needed when a block tag is stripped.
-
#block_whitespace=(block_whitespace)
Defines the string that is added when whitespace is needed when a block tag is stripped.
-
#process(html : String | XML::Node) : String
Processes the HTML fragment html with this policy using the default adapter (
Adapter::LibXML2
). -
#process_document(html : String | XML::Node) : String
Processes the HTML document html with this policy using the default adapter (
Adapter::LibXML2
). -
#transform_tag(name : String, attributes : Hash(String, String)) : String | Processor::CONTINUE | Processor::STOP
Receives the element name and attributes of an opening tag and returns the transformed element name (usually the same as the input name).
-
#transform_text(text : String) : String?
Receives the content of a text node and returns the transformed content.
Instance Method Detail
Defines the string that is added when whitespace is needed when a block tag is stripped.
Defines the string that is added when whitespace is needed when a block tag is stripped.
Processes the HTML fragment html with this policy using the default
adapter (Adapter::LibXML2
).
Processes the HTML document html with this policy using the default
adapter (Adapter::LibXML2
).
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.