class Loofah::Scrubbers::TargetBlank
behavior as setting rel=“noopener”.
On modern browsers, setting target=“_blank” on anchor elements implicitly provides the same
=> “ohai! <a href=‘www.myswarmysite.com/’ target=”_blank“>I like your blog post</a>”
Loofah.html5_fragment(link_farmers_markup).scrub!(:targetblank)
link_farmers_markup = “ohai! <a href=‘www.myswarmysite.com/’>I like your blog post</a>”
If there is a target already set, replaces it with target=“_blank”.:targetblank
adds a target=“_blank” attribute to all links.
=== scrub!(:targetblank)
def initialize # rubocop:disable Lint/MissingSuper
def initialize # rubocop:disable Lint/MissingSuper @direction = :top_down end
def scrub(node)
def scrub(node) return CONTINUE unless (node.type == Nokogiri::XML::Node::ELEMENT_NODE) && (node.name == "a") href = node["href"] node.set_attribute("target", "_blank") if href && href[0] != "#" STOP end