2023-10-03 17:02:22 -04:00
|
|
|
package highlight
|
|
|
|
|
2023-10-04 10:37:47 -04:00
|
|
|
import "strings"
|
|
|
|
|
2023-10-03 17:02:22 -04:00
|
|
|
type Syntax struct {
|
|
|
|
FileType string
|
|
|
|
FileMatch []string
|
|
|
|
Flags int
|
|
|
|
}
|
2023-10-04 10:37:47 -04:00
|
|
|
|
|
|
|
// HLDB - The "database" of syntax types
|
|
|
|
var HLDB = []*Syntax{{
|
|
|
|
"c",
|
|
|
|
[]string{".c", ".h", ".cpp"},
|
|
|
|
HighlightNumbers,
|
|
|
|
}, {
|
|
|
|
"go",
|
|
|
|
[]string{".go", "go.mod"},
|
|
|
|
HighlightNumbers,
|
|
|
|
}, {
|
|
|
|
"makefile",
|
|
|
|
[]string{"Makefile", "makefile"},
|
|
|
|
0,
|
|
|
|
}}
|
|
|
|
|
|
|
|
func GetSyntaxByFilename(filename string) *Syntax {
|
|
|
|
if filename == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
extInd := strings.LastIndex(filename, ".")
|
|
|
|
ext := filename[extInd:len(filename)]
|
|
|
|
|
|
|
|
for i := 0; i < len(HLDB); i++ {
|
|
|
|
s := HLDB[i]
|
|
|
|
for j := range s.FileMatch {
|
|
|
|
if s.FileMatch[j] == ext || strings.Contains(filename, s.FileMatch[j]) {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|