mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 06:33:06 -03:00
Rearranged code
This commit is contained in:
@ -4,8 +4,8 @@ package slinguist
|
||||
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||
// Extracted from github/linguist commit: {{ getCommit }}
|
||||
|
||||
// languagesByAlias keeps alias for different languages and use the name of the languages as a alias too. All the
|
||||
// keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores.
|
||||
// languagesByAlias keeps alias for different languages and use the name of the languages as an alias too.
|
||||
// All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores.
|
||||
var languagesByAlias = map[string]string{
|
||||
{{range $alias, $language := . -}}
|
||||
"{{ $alias }}": {{ printf "%q" $language -}},
|
||||
|
@ -5,25 +5,12 @@ package slinguist
|
||||
// Extracted from github/linguist commit: {{ getCommit }}
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetLanguageByContent(filename string, content []byte) (lang string, safe bool) {
|
||||
ext := strings.ToLower(filepath.Ext(filename))
|
||||
if fnMatcher, ok := matchers[ext]; ok {
|
||||
lang, safe = fnMatcher(content)
|
||||
} else {
|
||||
lang = OtherLanguage
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type languageMatcher func ([]byte) (string, bool)
|
||||
|
||||
var matchers = map[string]languageMatcher{
|
||||
var contentMatchers = map[string]languageMatcher{
|
||||
{{ range $index, $disambiguator := . -}}
|
||||
{{ printf "%q" $disambiguator.Extension }}: func(i []byte) (string, bool) {
|
||||
{{ range $i, $language := $disambiguator.Languages -}}
|
||||
|
@ -5,7 +5,13 @@ package slinguist
|
||||
// Extracted from github/linguist commit: {{ getCommit }}
|
||||
|
||||
var languagesByExtension = map[string][]string{
|
||||
{{range $extension, $languages := . -}}
|
||||
{{range $extension, $languages := .LanguagesByExtension -}}
|
||||
"{{ $extension }}": { {{- $languages | formatStringSlice -}} },
|
||||
{{end -}}
|
||||
}
|
||||
|
||||
var extensionsByLanguage = map[string][]string{
|
||||
{{range $language, $extensions := .ExtensionsByLanguage -}}
|
||||
"{{ $language }}": { {{- $extensions | formatStringSlice -}} },
|
||||
{{end -}}
|
||||
}
|
||||
|
Reference in New Issue
Block a user