Created
November 18, 2019 03:43
-
-
Save Uysim/a2ee4c961d05892ab90a8c35410d1267 to your computer and use it in GitHub Desktop.
Change Link target to blank with Nokogiri
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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