Rails markdown 避免显示 input,button 等元素.怎么做?

hlcfan · March 29, 2012 · Last by hlcfan replied at March 29, 2012 · 2921 hits

我把输入的文字 markdown 后,要显示出来。必须要加 raw 吗? 如果写 raw 的话,一些 input button 之类的标签也会打印出来。怎么办?

gem 'rdiscount'

写个 helper 方法,

def content
  RDiscount.new(content).to_html
end



页面直接可以用<%= Helper.content(post.content) %>弄出来了,也可以直接考虑写在 model 里面

#1 楼 @ywjno 你好,这个可以避免显示 input 等之类的标签吗?

求解啊,貌似 redcarpet 里没有相关选项。

<>这样的话需要自己转移吧,比如变成\<\>,我也没试过

redcarpet HTML render 有个选项是过滤所有 html: filter_html

也可以继承 html render 然后重写 block_html(raw_html) 和 raw_html(raw_html) 方法,前面一个是 block 级,后面一个是 span 级

#5 楼 @doitian 你好,谢谢。我加了 filter_html,但是没用。那我重写 block_html,raw_html 方法。

You need to Sign in before reply, if you don't have an account, please Sign up first.