I want to use syntax highlighting along with redcloth.
The description of coderay says:
Fast and easy syntax highlighting for selected languages, written in Ruby. Comes with RedCloth integration and LOC counter. 1
But I did not find a documentation about how to do this?
Where should I put the code to do the hightlighting? I thought about putting it into module ApplicationHelper
is this a good idea?
OPTION 1:
Simpe as this: http://railscasts.com/episodes/207-syntax-highlighting?autoplay=true When using rails3 change helper to this:
def coderay(text)
text.gsub!(/\<code(?: lang="(.+?)")?\>(.+?)\<\/code\>/m) do
code = CodeRay.scan($2, $1).div(:css => :class)
"<notextile>#{code}</notextile>"
end
return text.html_safe
end
If you use HAML you will want to use ~ sign:
~ raw textilize(coderay(...))
OPTION 2:
CodeRay has built-in support for RedCloth.
gem "RedCloth", :require => 'redcloth' gem 'coderay', :require => ['coderay', 'coderay/for_redcloth']
~ raw textilize("Some code here @that should@ be formated.") ~ raw textilize("Some code here @[ruby]that should@ be formated.")
# File at /my/file/path/filename.doc h1. My title bc[ruby].. # Nekaj za napisat def self.myfun puts "asdas" end # Inside your view file ~ raw textilize(File.read("/my/file/path/filename.doc"))
I prefere the second option.
You can find more about styling with Textile markup language at http://en.wikipedia.org/wiki/Textile_(markup_language)