Skip to content

Instantly share code, notes, and snippets.

@mifan
Created February 19, 2010 13:38
Show Gist options
  • Save mifan/308698 to your computer and use it in GitHub Desktop.
Save mifan/308698 to your computer and use it in GitHub Desktop.
require 'systemu'
require 'tempfile'
require 'string'
# snippet highlight
class Highlight
def self.format(code,type)
result = ''
tmpfile = nil
begin
tmpfile = Tempfile.new('twpaste')
tmpfile.puts(code)
tmpfile.flush
result = `pygmentize -f html -l #{type} -O encoding=utf8,linenos=1 #{tmpfile.path}`
if $? != 0
result = code
end
ensure
tmpfile.close if tmpfile
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment