CodeRay目前支持的语法包括:
- Ruby
- C
- Delphi
- HTML
- RHTML (Rails)
- Nitro-XHTML
- YAML
- SQL
- Python
- Perl
- PHP
- Java
1,安装coderay gem代码
- gem install coderay
- require 'coderay'
- def parse_coderay(text)
- text.scan(/(\[code\:([a-z].+?)\](.+?)\[\/code\])/m).each do |match|
- text.gsub!(match[0],CodeRay.scan(match[2].strip, match[1].to_sym).div( :line_numbers => :table,:css => :class))
- end
- return text
- end
- \[code:ruby\]
- def aaa
- puts "aaaa"
- end
- \[\/code\]
4,借用railscasts的coderay样式
http://railscasts.com/stylesheets/coderay.css
5,在html.erb页面中
- <div class="CodeRay"><%= parse_coderay @post.content %></div>