mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-08-28 04:46:30 -04:00
Return the def object rather than the filetype string
This commit is contained in:
+7
-5
@@ -2,17 +2,19 @@ package highlight
|
||||
|
||||
import "bytes"
|
||||
|
||||
func DetectFiletype(defs []*Def, filename string, fileSrc []byte) string {
|
||||
func DetectFiletype(defs []*Def, filename string, fileSrc []byte) *Def {
|
||||
firstLine := bytes.Split(fileSrc, []byte("\n"))[0]
|
||||
|
||||
for _, d := range defs {
|
||||
if d.ftdetect[0].Match([]byte(filename)) {
|
||||
return d.ft
|
||||
return d
|
||||
}
|
||||
if d.ftdetect[1].Match(firstLine) {
|
||||
return d.ft
|
||||
if len(d.ftdetect) > 1 {
|
||||
if d.ftdetect[1].Match(firstLine) {
|
||||
return d
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown"
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user