mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Prefer text mime types over binary ones
This commit is contained in:
@@ -19,20 +19,9 @@ File.read(File.expand_path("../mimes.yml", __FILE__)).lines.each do |line|
|
||||
|
||||
if extensions
|
||||
extensions.split(/,/).each do |extension|
|
||||
if extension =~ /^-(\w+)/
|
||||
extension = $1
|
||||
mime_type.extensions.delete(extension)
|
||||
|
||||
MIME::Types.instance_eval do
|
||||
@__types__.instance_eval do
|
||||
@extension_index[extension].delete(mime_type)
|
||||
end
|
||||
end
|
||||
else
|
||||
mime_type.extensions << extension
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mime_type.encoding = encoding
|
||||
|
||||
@@ -72,6 +61,8 @@ module Linguist
|
||||
|
||||
# Internal: Lookup mime type for extension or mime type
|
||||
#
|
||||
# ext_or_mime_type - A file extension ".txt" or mime type "text/plain".
|
||||
#
|
||||
# Returns a MIME::Type
|
||||
def self.lookup_mime_type_for(ext_or_mime_type)
|
||||
ext_or_mime_type ||= ''
|
||||
@@ -82,6 +73,10 @@ module Linguist
|
||||
guesses = ::MIME::Types.type_for(ext_or_mime_type)
|
||||
end
|
||||
|
||||
# Prefer text mime types over binary
|
||||
guesses.detect { |type| type.ascii? } ||
|
||||
|
||||
# Otherwise use the first guess
|
||||
guesses.first
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,7 +39,6 @@ application/vnd.openofficeorg.extension @oxt
|
||||
application/vnd.openxmlformats-officedocument.presentationml.presentation @pptx
|
||||
application/x-chrome-extension @crx
|
||||
application/x-ms-xbap @xbap :8bit
|
||||
application/x-pagemaker @-pm
|
||||
application/x-shockwave-flash @swf
|
||||
application/x-silverlight-app @xap
|
||||
application/x-troff-ms :8bit
|
||||
@@ -48,4 +47,3 @@ application/xaml+xml @xaml :8bit
|
||||
image/x-icns @icns
|
||||
text/cache-manifest @manifest
|
||||
text/x-nimrod @nim
|
||||
video/vnd.nokia.interleaved-multimedia @-nim
|
||||
|
||||
Reference in New Issue
Block a user