如何在 Rails 中解析 HTML?
我保存了一个带有 html 标签的字符串。
=> "<p>hey man this is crazy g funk</p>\n<p>here i come with another crazy message from..</p>\n<p>dj eassssy d!@#!.</p>"
您如何解析它以使其显示 HTML 标记所暗示的方式?
我试过:
= Post.text
=h Post.text
= RedCloth.new(Post.text).to_html
= Hpricot(Post.text)
I have a string with html tags in it saved.
=> "<p>hey man this is crazy g funk</p>\n<p>here i come with another crazy message from..</p>\n<p>dj eassssy d!@#!.</p>"
How do you parse this so that it displays the way the HTML tags are implying?
I tried:
= Post.text
=h Post.text
= RedCloth.new(Post.text).to_html
= Hpricot(Post.text)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,我们使用 html 解析器来解析 html。 “以便它显示 HTML 标签所暗示的方式”是什么意思?显示在什么上?大概不是网络浏览器..
Generally one parses html with html parsers. What do you mean "so that it displays the way the HTML tags are implying"? Displays on what? Presumably not a web browser..
你想这样做:
或者在 haml 中
原因是因为rails转义了你的html并将
转换为
<p>
。You want to do this:
or in haml
The reason is because rails escapes your html and will convert
<p>
into<p>
.