首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CodeRay风格混乱--如何修复

CodeRay风格混乱--如何修复
EN

Stack Overflow用户
提问于 2015-03-16 11:44:29
回答 2查看 305关注 0票数 0

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

请注意,我将CodeRay与Markdown (Redcarpet)结合使用。我在我的宝石文件中添加了这两种宝石,在app/helpers/application_helper.rb中添加了以下内容:

代码语言:javascript
运行
复制
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

正如你所看到的屏幕快照所显示的那样。但问题是格式问题。有什么想法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-15 04:26:18

我还注意到,CodeRay回购版附带的当前CSS在移动/平板设备上没有很好的响应。

要修复,请执行以下步骤:

1.将其添加到您的CSS:

/*显示滚动条*/

代码语言:javascript
运行
复制
::-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

代码语言:javascript
运行
复制
    def block_code(code, language)
        CodeRay.scan(code, language).div(:line_numbers => :inline)
    end
end
票数 0
EN

Stack Overflow用户

发布于 2015-10-29 17:42:09

您是否尝试过将表用于line_numbers而不是内联?

代码语言:javascript
运行
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29075975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档