mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-05 16:37:20 -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"
|
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]
|
firstLine := bytes.Split(fileSrc, []byte("\n"))[0]
|
||||||
|
|
||||||
for _, d := range defs {
|
for _, d := range defs {
|
||||||
if d.ftdetect[0].Match([]byte(filename)) {
|
if d.ftdetect[0].Match([]byte(filename)) {
|
||||||
return d.ft
|
return d
|
||||||
}
|
}
|
||||||
if d.ftdetect[1].Match(firstLine) {
|
if len(d.ftdetect) > 1 {
|
||||||
return d.ft
|
if d.ftdetect[1].Match(firstLine) {
|
||||||
|
return d
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Unknown"
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user