使用 Rails、Datamapper 和 Datamapper 保留空白Coderay(哦,是的,还有 Haml)
我试图在 ruby 应用程序中显示语法突出显示的 C 代码。 Coderay 似乎是事实上的解决方案,因为我没有对样式做任何其他特殊的事情。
下面的代码给出了 div 中突出显示的代码,但没有前导空格。 (使用 Sequel Pro 查看时,数据库中存在空格)
代码保存在常规文本列中:
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
I'm trying to show syntax highlighted C code in a ruby app. Coderay seemed like the defacto solution since I'm not doing anything else special with the styling.
The following code give me highlighted code in a div, but with no leading whitespace. (The whitespace is present in the DB when viewed with Sequel Pro)
The code is saved in a regular Text column:
class Project
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property code, Text
end
And the view is rendered in haml via:
~ CodeRay.scan(@project.code, :c).div(:css => :class).html_safe
EDIT
See solution below, it was because of the html5 boilerplate reset css
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是个普茨,所有示例代码都是正确的,它是 html5 样板 css 删除了空格。具体来说:
删除空白:行前;修复它
I'm a putz, all the example code is right, it was the html5 boilerplate css removing the whitespace. Specifically:
dropping the white-space:pre-line; fixes it