Skip to content

Instantly share code, notes, and snippets.

@Uysim
Created November 18, 2019 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Uysim/a2ee4c961d05892ab90a8c35410d1267 to your computer and use it in GitHub Desktop.
Save Uysim/a2ee4c961d05892ab90a8c35410d1267 to your computer and use it in GitHub Desktop.
Change Link target to blank with Nokogiri
html = '<a href="https://google.com"></a>'
fragment = Nokogiri::HTML::fragment(html)
fragment.css('a[href]').each do |link|
link.set_attribute('target', '_blank')
end
fragment.to_html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment