我试图在我的项目中使用CodeRay,它似乎正在工作,但是样式和格式似乎很混乱:

请注意,我将CodeRay与Markdown (Redcarpet)结合使用。我在我的宝石文件中添加了这两种宝石,在app/helpers/application_helper.rb中添加了以下内容:
class CodeRayify < Redcarpet::Render::HTML
def block_code(code, language)
CodeRay.scan(code, language).div(:line_numbers => :inline)
end
end
def markdown(text)
coderayified = CodeRayify.new(:filter_html => true, :hard_wrap => true)
language ||= :plaintext
options = {
:fenced_code_blocks => true,
:no_intra_emphasis => false,
:autolink => true,
:strikethrough => true,
:lax_html_blocks => true,
:superscript => true
}
markdown_to_html = Redcarpet::Markdown.new(coderayified, options)
markdown_to_html.render(text).html_safe
end正如你所看到的屏幕快照所显示的那样。但问题是格式问题。有什么想法吗?
发布于 2016-03-15 04:26:18
我还注意到,CodeRay回购版附带的当前CSS在移动/平板设备上没有很好的响应。
要修复,请执行以下步骤:
1.将其添加到您的CSS:中
/*显示滚动条*/
::-webkit-scrollbar {
-webkit-appearance: none;
margin-top: 10px;
width: 7px;
height: 8px;
background-color: #eee;
border-radius: 4px;
}
::-webkit-scrollbar-thumb {
border-radius: 4px;
height: 10px;
background-color: rgba(0,0,0,.5);
-webkit-box-shadow: 0 0 1px rgba(255,255,255,.5);
}2.在CodeRay选项的应用程序助手文件中,确保block_code options :line_numbers设置为:inline,如下所示:
类CodeRayify <红地毯::呈现::HTML
def block_code(code, language)
CodeRay.scan(code, language).div(:line_numbers => :inline)
end
end发布于 2015-10-29 17:42:09
您是否尝试过将表用于line_numbers而不是内联?
module ApplicationHelper
class CodeRayify < Redcarpet::Render::HTML
def block_code(code, language)
CodeRay.scan(code, language).div(:line_numbers => :table)
end
end
def markdown(text)
coderayified = CodeRayify.new(:filter_html => true,
:hard_wrap => true)
options = {
:fenced_code_blocks => true,
:no_intra_emphasis => true,
:autolink => true,
:strikethrough => true,
:lax_html_blocks => true,
:superscript => true
}
markdown_to_html = Redcarpet::Markdown.new(coderayified, options)
markdown_to_html.render(text).html_safe
end
endhttps://stackoverflow.com/questions/29075975
复制相似问题