CodeRay风格搞砸了 - 如何修复

时间:2015-03-16 11:44:29

标签: ruby-on-rails-4 syntax-highlighting redcarpet coderay

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

Coderay messed up code

请注意,我正在将CodeRay与Markdown(Redcarpet)结合使用。我在我的gemfile和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

通过附带的屏幕截图可以看到哪个有效。问题是格式化。有什么想法吗?

2 个答案:

答案 0 :(得分:1)

您是否曾尝试将表用于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
end

答案 1 :(得分:0)

我还注意到CodeRay repo附带的当前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选项的app帮助文件中,确保block_code选项:line_numbers设置为:inline,如下所示:

类CodeRayify&lt;隆重的接待::渲染HTML ::

    def block_code(code, language)
        CodeRay.scan(code, language).div(:line_numbers => :inline)
    end
end
相关问题