class Rails::Html::LinkSanitizer
> ‘Only the link text will be kept.’
link_sanitizer.sanitize(‘<a href=“example.com”>Only the link text will be kept.</a>’)
link_sanitizer = Rails::Html::LinkSanitizer.new
Removes a
tags and href
attributes leaving only the link text.
=== Rails::Html::LinkSanitizer¶ ↑
def initialize
def initialize @link_scrubber = TargetScrubber.new @link_scrubber.tags = %w(a) @link_scrubber.attributes = %w(href) end
def sanitize(html, options = {})
def sanitize(html, options = {}) Loofah.scrub_fragment(html, @link_scrubber).to_s end