简体   繁体   English

<a href>使用simple_format时</a>转义<a href>标签</a>

[英]Escape <a href> tags while using simple_format

I have an app where I would like to display the line breaks in the content of a text_area. 我有一个应用程序,我想在text_area的内容中显示换行符。

I know I can accomplish this using simple_format, but for SEO reasons I would also like to disallow them from inserting links into the content. 我知道我可以使用simple_format完成此任务,但出于搜索引擎优化的原因,我还想禁止他们在内容中插入链接。

How do I go about displaying the line breaks, and not render the <a> tags ? 如何显示换行符,而不是渲染<a>标签?

You can combine simple_format with sanitize : 您可以将simple_formatsanitize结合使用:

# prints <p>foo\n<br />barbaz</p>
simple_format sanitize("foo\nbar<a href='foo'>baz</a>", :tags => [])

Pass allowable tags as the :tags option (eg :tags => ["p", "em"] ). 将允许的标记作为:tags选项传递(例如:tags => ["p", "em"] )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM