Sanitize::Policy::Text
Inherits Sanitize::Policy / Reference / Object
Reduces an HTML tree to the content of its text nodes. It renders a plain text result, similar to copying HTML content rendered by a browser to a text editor. HTML special characters are escaped.
policy = Sanitize::Policy::Text.new
policy.process(%(foo <strong><a href="bar">bar</a>!</strong>)) # => "foo bar!"
policy.process(%(<p>foo</p><p>bar</p>)) # => "foo bar"
policy.block_whitespace = "\n"
policy.process(%(<p>foo</p><p>bar</p>)) # => "foo\nbar"
Instance methods
transform_tag(name : String, attributes : Hash(String, String)) : String | CONTINUE | STOP
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.
transform_text(text : String) : String | Nil
Receives the content of a text node and returns the transformed content.
If the return value is nil, the content is skipped.