X-Git-Url: https://git.armaanb.net/?p=stagit.git;a=blobdiff_plain;f=highlight;h=2b46f20fdd885d4c0df382109c7c818d51520d2c;hp=c67e70319b31a8f834597897aa9cea7fd1a56ec6;hb=ba2dc046e649f0f48b0fbe65f12627bd33ec2d38;hpb=560f081852a8b04bcb628d7396d13a22c00ffa26 diff --git a/highlight b/highlight index c67e703..2b46f20 100755 --- a/highlight +++ b/highlight @@ -8,7 +8,27 @@ stdin = ARGF.file 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}" @@ -18,7 +38,7 @@ detected = Linguist::FileBlob.new(filename).language #pp detected html = Pygments.highlight(contents, - :lexer => detected.name, + :lexer => detected, :formatter => 'html', :options => { :encoding => 'utf-8',