Class: HTMLPipeline::ExternalLinkFilter
- Inherits:
-
NodeFilter
- Object
- NodeFilter
- HTMLPipeline::ExternalLinkFilter
- 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 |
#selector ⇒ Object
9 10 11 |
# File 'lib/html/pipeline/external_link/filter.rb', line 9 def selector SELECTOR end |