Question

I'm using CodeRay and Haml to do syntax highlighting on some pages, and I write a lot of Ruby code. The problem is when I have something like this:

%pre
  %code.language-ruby
    :preserve
      def hello(name)
        puts "Hello #{name}!" 
      end

I keep getting errors because Haml keeps trying to evaluate the name variable inside the string, the #{var} syntax is a pretty common idiom in Ruby code and there aremany places where it is used, but I cannot use syntax highlighting of those codes because Haml wants to evaluate those variables inside the string.

Is there a way to tell Haml to not do that in some places?

Was it helpful?

Solution

Is there a way to tell Haml to not do that in some places?

By escaping the #:

puts "Hello \#{name}!" 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top