Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple_format is stripping out target _blank

= simple_format(styled_text_for_tagged_text(block.text_block.body, article))

This appears to be stripping attributes like target="_blank" out of my link. I can't use auto_link. Any suggestions on how to fix this?

like image 270
Evan Avatar asked Dec 21 '15 16:12

Evan


1 Answers

A much better way to do this is to turn off the sanitizer in the simple_format method, and call sanitize on the contents yourself, where you can specify not to strip the target attributes out.

= simple_format(sanitize(body, attributes: ["href", "target"]), {}, sanitize: false)

Then you get the benefits of both simple_format and sanitize.

Ref Rails removes target="_blank"

like image 55
Andrew Avatar answered Oct 31 '22 13:10

Andrew