我如何转换/替换每一个换行'< br />'? [英] How can i convert/replace every newline to '<br/>'?
问题描述
set tabstop=4
set shiftwidth=4
set nu
set ai
syntax on
filetype plugin indent on
我试过了, content.gsub(\r\\\
但是当我点击view / show按钮来查看这些行的内容时,我得到了output / result =>
,< br />)
I tried this, content.gsub("\r\n","<br/>")
but when I click the view/show button to see the contents of these line, I get the output/result=>
set tabstop=4<br/> set shiftwidth=4<br/> set nu<br/> set ai<br/> syntax on<br/> filetype plugin indent on
但我试图将这些行作为单独的行。但都成为一条线。为什么?
But I tried to get those lines as a seperate lines. But all become as a single line. Why?
如何使用html中断(< br />
)来创建所有这些行?
How can I make all those lines with a html break (<br/>
) ?
我试过这个,没有用。
I tried this, that didn't work.
@addpost = Post.new params[:data]
@temptest = @addpost.content.html_safe
@addpost.content = @temptest
#logger.debug(@addpost)
@addpost.save
还尝试不保存到数据库中。仅在视图图层中尝试过,<%= t.content.html_safe%>
那也没用。
Also tried without saving into database. Tried only in view layer,<%= t.content.html_safe %>
That didn't work too.
从页面源获得此内容
<a href="/posts/36">vimrc file</a> <br/>
2011-12-06<br/><br/>
set tabstop=4<br/><br/>set shiftwidth=4<br/><br/>set nu<br/><br/>set ai<br/><br/>syntax on<br/><br/>filetype plugin indent on<br/>
<a href="/posts/36/edit">Edit</a>
<a href="/posts/36" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete</a>
<br/><br/>
推荐答案
您需要使用 html_safe 如果您想渲染嵌入式HTML:
You need to use html_safe
if you want to render embedded HTML:
<%= @the_string.html_safe %>
如果它可能为零, raw(@the_string)
不会抛出异常。我对 raw
有点矛盾;我几乎从不尝试显示可能是 nil
的字符串。
If it might be nil, raw(@the_string)
won't throw an exception. I'm a bit ambivalent about raw
; I almost never try to display a string that might be nil
.
这篇关于我如何转换/替换每一个换行'< br />'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!