class Rails::Html::LinkSanitizer

Rails::Html::LinkSanitizer

Removes a tags and href attributes leaving only the link text

link_sanitizer = ::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 49
def initialize
  @link_scrubber = TargetScrubber.new
  @link_scrubber.tags = %w(a href)
  @link_scrubber.attributes = %w(href)
end

Public Instance Methods

sanitize(html, options = {}) click to toggle source
# File lib/rails/html/sanitizer.rb, line 55
def sanitize(html, options = {})
  Loofah.scrub_fragment(html, @link_scrubber).to_s
end