class Rails::Html::LinkSanitizer
Rails::Html::LinkSanitizer¶ ↑
Removes a
tags and href
attributes leaving only
the link text.
link_sanitizer = Rails::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.'
Public Class Methods
new()
click to toggle source
# File lib/rails/html/sanitizer.rb, line 50 def initialize @link_scrubber = TargetScrubber.new @link_scrubber.tags = %w(a) @link_scrubber.attributes = %w(href) end
Public Instance Methods
sanitize(html, options = {})
click to toggle source
# File lib/rails/html/sanitizer.rb, line 56 def sanitize(html, options = {}) Loofah.scrub_fragment(html, @link_scrubber).to_s end