class Sanitize::Policy::Text
- Sanitize::Policy::Text
- Sanitize::Policy
- Reference
- Object
Overview
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"
Defined in:
Instance Method Summary
-
#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).
-
#transform_text(text : String) : String?
Receives the content of a text node and returns the transformed content.
Instance methods inherited from class Sanitize::Policy
block_tag?(name)
block_tag?,
block_whitespace : String
block_whitespace,
block_whitespace=(block_whitespace)
block_whitespace=,
process(html : String | XML::Node) : String
process,
process_document(html : String | XML::Node) : String
process_document,
transform_tag(name : String, attributes : Hash(String, String)) : String | Processor::CONTINUE | Processor::STOP
transform_tag,
transform_text(text : String) : String?
transform_text
Instance Method Detail
def transform_tag(name : String, attributes : Hash(String, String)) : String | CONTINUE | STOP
#
Description copied from class Sanitize::Policy
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.
def transform_text(text : String) : String?
#
Description copied from class Sanitize::Policy
Receives the content of a text node and returns the transformed content.
If the return value is nil
, the content is skipped.