sil*_*non 4 haml ruby-on-rails redcarpet
我正在使用Rails 3.2.11,Haml 4.0和Redcarpet 2.2.2.
我想配置Haml的:markdown过滤器来使用Redcarpet with_toc_data: true.在ApplicationHelper我尝试定义:
def markdown(text)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(with_toc_data: true))
raw markdown.render(text.to_s)
end
Run Code Online (Sandbox Code Playgroud)
虽然内容:markdown被渲染,但没有TOC数据.如何更改:markdown解析方式?
目前无法将选项传递给Haml中的过滤引擎.现在最好的解决方案可能是:markdown用一个具有你想要的选项的新过滤器替换现有的过滤器.
尝试将这样的内容添加到初始化程序:
module Haml::Filters
remove_filter("Markdown") #remove the existing Markdown filter
module Markdown
include Haml::Filters::Base
def render(text)
Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(with_toc_data: true)).render(text)
end
end
end
Run Code Online (Sandbox Code Playgroud)