filename = stdin.readline.strip # Read first line (filename).
contents = stdin.read # Read rest (code).
-detected = Linguist::FileBlob.new(filename).language
+class FakeBlob < Linguist::FileBlob
+ def initialize(path, content, base_bath=nil)
+ super(path, base_bath)
+ @content = content
+ end
+
+ def data
+ @content
+ end
+
+ def size
+ @content.bytesize
+ end
+end
+
+blob = FakeBlob.new(filename, contents)
+detected = if blob.language
+ blob.language.name
+ else
+ "Text only"
+ end
# Debugging
#puts "File #{filename}"
#pp detected
html = Pygments.highlight(contents,
- :lexer => detected.name,
+ :lexer => detected,
:formatter => 'html',
:options => {
:encoding => 'utf-8',