我正在使用Redcarpet gem进行降价,我想为h2 Headers 生成自动锚点,以便链接到每个部分 .
show.html.erb
<div class = "content"><%= markdown(@post.body) %></div>
application_helper.rb
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
Pygments.highlight(code, :lexer => language)
end
end
def markdown(text)
renderer = HTMLwithPygments.new(:hard_wrap => true, :with_toc_data => true)
options = {
:fenced_code_blocks => true,
:no_intra_emphasis => true,
:autolink => true,
:strikethrough => true,
:lax_html_blocks => true,
:superscript => true,
}
Redcarpet::Markdown.new(renderer, options).render(text).html_safe
end
我读到:with_toc_data => true但它对我不起作用 . 我在选项区添加了它 .
1 回答
我做的与你描述的基本相同
我的视图包含以下代码
也许这有帮助 .