Class: Html::LinkSanitizer
- Defined in:
- lib/html/sanitizer/sanitizer.rb
Overview
Html::LinkSanitizer
Removes a tags and href attributes leaving only the link text
link_sanitizer = Html::LinkSanitizer.new link_sanitizer.sanitize(‘<a href=“example.com”>Only the link text will be kept.</a>’) # => Only the link text will be kept.
Constant Summary
Constants inherited from Sanitizer
Instance Method Summary collapse
-
#initialize ⇒ LinkSanitizer
constructor
A new instance of LinkSanitizer.
- #sanitize(html, options = {}) ⇒ Object
Methods inherited from Sanitizer
full_sanitizer, link_sanitizer, white_list_sanitizer
Constructor Details
#initialize ⇒ LinkSanitizer
Returns a new instance of LinkSanitizer.
41 42 43 44 45 |
# File 'lib/html/sanitizer/sanitizer.rb', line 41 def initialize @link_scrubber = TargetScrubber.new @link_scrubber. = %w(a href) @link_scrubber.attributes = %w(href) end |
Instance Method Details
#sanitize(html, options = {}) ⇒ Object
47 48 49 |
# File 'lib/html/sanitizer/sanitizer.rb', line 47 def sanitize(html, = {}) Loofah.scrub_fragment(html, @link_scrubber).to_s end |