当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby - How do I get Haml to stop from evaluating #{var} values inside <pre> <code> tags?

问题描述:

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?

网友答案:

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

By escaping the #:

puts "Hello \#{name}!" 
分享给朋友:
您可能感兴趣的文章:
随机阅读: