Easy Syntax Highlighting
source link: https://soffes.blog/easy-syntax-highlighting
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Easy Syntax Highlighting — Hi, I’m Sam
Easy Syntax Highlighting — Hi, I’m Sam
Hi, I’m Sam
This is my blog. I also have a website thing.
Easy Syntax Highlighting
Posted on October 26, 2011
Syntax highlight in Ruby is annoying. Pygments is the best way to do syntax highlighting, but it's a Python project. (Why no one has ported that to Ruby yet is beyond me. Granted there are a few, but they are all kinda annoying, slow, or don't work that well.)
Anyway, for awhile the best way was to hit a web service running on App Engine to use Pygments since that's actually running Python. This totally sucks because you have to rely on that service—it could be down, network latency, etc.
Damian Janowski put out a fantastic gem that solves this called Pygmentize. It's dead simple to use too.
require "pygmentize" source = "function foo() { return 'bar'; }" Pygmentize.process(source, :javascript)
The best part about all of this is that you can run it on Heroku! I switched my blog to use it and it's working great. By the way, if you're using Heroku, be sure you use the Cedar Stack.
Here's my little example page running on Heroku. The full source is on GitHub too. Enjoy!
Removed Facebook Comments
Posted on October 20, 2011
Sorry if you left some comments. I appreciate it, but it wasn't really a good solution. They weren't that pretty, loaded slow, and didn't notify me when people posted. I had no way to track comments on my posts.
I might build something, but now, I'll just go back to no comments. If you want to leave a comment or ask a question, I'm @soffes on Twitter. You can always email me too.
© 2006-2022 Sam Soffes
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK