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,18 +19,7 @@ File.read(File.expand_path("../mimes.yml", __FILE__)).lines.each do |line|
|
|||||||
|
|
||||||
if extensions
|
if extensions
|
||||||
extensions.split(/,/).each do |extension|
|
extensions.split(/,/).each do |extension|
|
||||||
if extension =~ /^-(\w+)/
|
mime_type.extensions << extension
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -72,6 +61,8 @@ module Linguist
|
|||||||
|
|
||||||
# Internal: Lookup mime type for extension or mime type
|
# 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
|
# Returns a MIME::Type
|
||||||
def self.lookup_mime_type_for(ext_or_mime_type)
|
def self.lookup_mime_type_for(ext_or_mime_type)
|
||||||
ext_or_mime_type ||= ''
|
ext_or_mime_type ||= ''
|
||||||
@@ -82,7 +73,11 @@ module Linguist
|
|||||||
guesses = ::MIME::Types.type_for(ext_or_mime_type)
|
guesses = ::MIME::Types.type_for(ext_or_mime_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
guesses.first
|
# Prefer text mime types over binary
|
||||||
|
guesses.detect { |type| type.ascii? } ||
|
||||||
|
|
||||||
|
# Otherwise use the first guess
|
||||||
|
guesses.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ application/vnd.openofficeorg.extension @oxt
|
|||||||
application/vnd.openxmlformats-officedocument.presentationml.presentation @pptx
|
application/vnd.openxmlformats-officedocument.presentationml.presentation @pptx
|
||||||
application/x-chrome-extension @crx
|
application/x-chrome-extension @crx
|
||||||
application/x-ms-xbap @xbap :8bit
|
application/x-ms-xbap @xbap :8bit
|
||||||
application/x-pagemaker @-pm
|
|
||||||
application/x-shockwave-flash @swf
|
application/x-shockwave-flash @swf
|
||||||
application/x-silverlight-app @xap
|
application/x-silverlight-app @xap
|
||||||
application/x-troff-ms :8bit
|
application/x-troff-ms :8bit
|
||||||
@@ -48,4 +47,3 @@ application/xaml+xml @xaml :8bit
|
|||||||
image/x-icns @icns
|
image/x-icns @icns
|
||||||
text/cache-manifest @manifest
|
text/cache-manifest @manifest
|
||||||
text/x-nimrod @nim
|
text/x-nimrod @nim
|
||||||
video/vnd.nokia.interleaved-multimedia @-nim
|
|
||||||
|
|||||||
Reference in New Issue
Block a user