How Flowcoder uses pygments.appspot.com

Language: Ruby

require 'net/http'
require 'uri'

class Post < ActiveRecord::Base  
  before_save :pygmentize_body
  
  def pygmentize_body
    self.pygmentized_body = Net::HTTP.post_form(URI.parse('http://pygments.appspot.com/'), {'lang'=>language, 'code'=>body}).body
  end
    
end

# Then you can call @post.pygmentized_body to get the stored HTML with syntax highlighting without doing another request
Reveal More
Added over 2 years ago by Costco_normal trevorturk