Class: HTMLPipeline::ExternalLinkFilter

Inherits:
NodeFilter
  • Object
show all
Defined in:
lib/html/pipeline/external_link/filter.rb

Constant Summary collapse

SELECTOR =
Selma::Selector.new(match_element: %(a[href^="http"]))

Instance Method Summary collapse

Instance Method Details

#handle_element(element) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/html/pipeline/external_link/filter.rb', line 13

def handle_element(element)
  return unless element["href"]

  href = element["href"].strip
  href_host = host_of(href)
  return unless href_host

  if href_host != hostname
    element["rel"] = "nofollow noopener"
    element["target"] = "_blank"
  end
end

#selectorObject



9
10
11
# File 'lib/html/pipeline/external_link/filter.rb', line 9

def selector
  SELECTOR
end