【问题标题】:Preserve Whitespace with Rails, Datamapper & Coderay (Oh yeah and Haml too)使用 Rails、Datamapper 和 Coderay 保留空白(哦,是的,还有 Haml)
【发布时间】:2011-07-25 15:52:41
【问题描述】:

我正在尝试在 ruby​​ 应用程序中显示语法突出显示的 C 代码。 Coderay 似乎是事实上的解决方案,因为我没有对样式做任何其他特别的事情。

以下代码在 div 中为我提供了突出显示的代码,但没有前导空格。 (使用 Sequel Pro 查看时,DB 中存在空格)

代码保存在常规文本列中:

class Project
  include DataMapper::Resource

  property :id,     Serial
  property :name,   String,   :required => true
  property code,    Text
end

并且视图通过以下方式在haml中呈现:

~ CodeRay.scan(@project.code, :c).div(:css => :class).html_safe

编辑

请参阅下面的解决方案,这是因为 html5 样板重置 css

【问题讨论】:

    标签: ruby-on-rails haml coderay html5boilerplate


    【解决方案1】:

    我是个普通人,所有示例代码都是正确的,它是 html5 样板 css 删除了空格。具体来说:

    pre {  padding: 15px;  white-space: pre;  white-space: pre-wrap;  white-space: pre-line;  word-wrap: break-word; }
    

    删除空白:pre-line;修复它

    【讨论】:

      猜你喜欢
      • 2011-12-15
      • 2016-08-26
      • 1970-01-01
      • 2022-01-15
      • 2011-07-24
      • 2013-08-11
      • 1970-01-01
      • 2010-09-20
      • 1970-01-01
      相关资源
      最近更新 更多