Question

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

Was it helpful?

Solution

I'm a putz, all the example code is right, it was the html5 boilerplate css removing the whitespace. Specifically:

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

dropping the white-space:pre-line; fixes it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top