【发布时间】:2016-07-06 23:21:06
【问题描述】:
我正在尝试使用 markdown 写博客,并决定安装 redcarpet gem。一切看起来都很好,pygments.rb 在语法突出显示方面做得很好,但是问题是,每当我尝试使用 ``` 放置代码块时,我都会缩进所有行(第一行除外)增加 6 个空格。如何摆脱它?
application_helper.rb
module ApplicationHelper
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
Pygments.highlight(code, lexer: language)
end
end
def markdown(content)
renderer = HTMLwithPygments.new(hard_wrap: true, filter_html: true)
options = {
autolink: true,
no_intra_emphasis: true,
disable_indented_code_blocks: true,
fenced_code_blocks: true,
lax_html_blocks: true,
strikethrough: true,
superscript: true
}
Redcarpet::Markdown.new(renderer, options).render(content).html_safe
end
end
发布视图 - show.html.haml
.container
.show.title
= @post.title
.show.header
= @post.header
.show.created_at
= @post.created_at
.show.content
= markdown @post.content
这就是代码在 sublime 中的样子:
这是复制粘贴相同代码以发布内容时呈现的帖子的样子:
我正在使用带有 2 个空格缩进的 SublimeText3,视图为 html.haml 格式。
这是帖子内容的准确输入:
```ruby
module ApplicationHelper
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
Pygments.highlight(code, lexer: language)
end
end
def markdown(content)
renderer = HTMLwithPygments.new(hard_wrap: true, filter_html: true)
options = {
autolink: true,
no_intra_emphasis: true,
disable_indented_code_blocks: true,
fenced_code_blocks: true,
lax_html_blocks: true,
strikethrough: true,
superscript: true
}
Redcarpet::Markdown.new(renderer, options).render(content).html_safe
end
end
【问题讨论】:
标签: ruby-on-rails haml markdown redcarpet