flavorjones / loofah

Ruby library for HTML/XML transformation and sanitization
MIT License
934 stars 137 forks source link

Add scrub to append `target=_blank` to all links #272

Closed stefannibrasil closed 12 months ago

stefannibrasil commented 1 year ago

Hello! Not sure if this has been asked before (did not find anything by searching at the issues), but I was thinking if anyone else would find it helpful to add a scrub that adds target=_blank to all links. Similarly to how Loofah does with noopener and nofollow.

Loofah.html5_fragment(link_farmers_markup).scrub!(:targetblank)
--
223 | #     => "ohai! <a href='http://www.myswarmysite.com/' target="_blank">I like your blog post</a>"

If so, I'd be happy to contribute with that. Thanks!

flavorjones commented 1 year ago

@stefannibrasil That sounds like an awesome addition to the scrubbers! If you'd like to draft a PR I'd be happy to review or help out. Let me know what you need!

stefannibrasil commented 1 year ago

Awesome, thanks for letting me know @flavorjones I will work on this later and will let you know if I have any questions. Thank you!

stefannibrasil commented 1 year ago

Just opened a PR to add it - thanks @flavorjones !