#207 Syntax Highlighting (revised)
Here I compare several syntax highlighting solutions and show how to use Pygments in a Rails app. I also show how to integrate it with Markdown and add caching.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
I wish CodeRay had a CoffeeScript scanner. That's really the only thing that tempts me to switch to Pygments.
Love these revised episodes. Would really like to see the episode on Cancan revised. :)
The information for implementing cancan hasn't really changed much for Rails 3. You can check out the wiki for cancan, which is what I recently used to get it up and running on my app: CanCan wiki
What's the difference in
cache('somekey') do ... end
andRails.cache.fetch('somekey') do ... end
? They seem fundamentally the same.Invocation of pygments.rb class methods within a Rails 3.2 app just kills the entire server process. Anyone here has any experience of this?
This is happening to me. Very frustrating.
Hi Ryan,
I tried the sample source code but it gives me this error. I hope you mentioned it in the notes or comments to other users to benefit.
And the solution is download and install the 64 bit version binary Python installer from Python.org website. Here is the direct download link
Got this up and running but seems to indent any code after line 1 by an extra four spaces. Anyone know if this is a pygments or Redcarpet issue or how to fix it?
Turns out this is a haml issue (http://stackoverflow.com/questions/6325416/maruku-incorrectly-parsing-second-line-of-code-blocks).
It can be fixed by adding 'preserve' i.e.
= preserve @foo
Thank you!
Awesome as usual. Seems like the caching would be a perfect fit for Redis. :-)
The redcarpet portion simply doesn't work for me. I can't get Pygments.highlight to work when called within redcarpet
I was also finding problems making Pigments work from within redcarpet. I finally opted for Coderay, as on the original version of this railscasts, here's what I did:
How to colorize code in comments using CodeRay
This helped me to build rack-markdown.
I downloaded and tried example, background doesn't work, how can I set background-color when I use the dark background theme? thanks.
Rouge is great gem for syntax highlighting and it's written in pure Ruby. I've written blog post with simple Rouge configuration with Redcarpet in Ruby on Rails.
Syntax highlighting in Ruby on Rails
I was able to get it working by following your blog post. I simplified the code a bit:
Syntax Highlighting using Rouge in Rails 4 Check it out: