我有一个文字:
<p>This is some text <br/> with two<br /> lines</p>
这是我期望的输出:
This is some text <br/> with two<br /> lines
我在我的模型中使用帮助器(我知道,但这只是我想要的方式):
result = ActionView::Base.full_sanitizer.sanitize(text, :tags => ['br'])
但它不起作用。我得到的结果没有任何标签:
This is some text with two lines
我也尝试过:
result = ActionView::Base.full_sanitizer.sanitize(text, :tags => %w(br))
但它不起作用。
出了什么问题,如何检索包含<br/>
标签的文字?
答案 0 :(得分:2)
我想你试试这个
text = "<p>This is some text <br/> with two<br /> lines</p>"
#=> "<p>This is some text <br/> with two<br /> lines</p>"
result = ActionController::Base.helpers.sanitize(text, :tags => ['br'])
#=> "This is some text <br /> with two<br /> lines"