Add support for Roff man pages filenames

This commit is contained in:
Lauris BH
2020-09-17 11:27:28 +03:00
parent d7f6b27b7d
commit cb353b4b05
2 changed files with 45 additions and 0 deletions

View File

@ -22,6 +22,7 @@ var DefaultStrategies = []Strategy{
GetLanguagesByFilename,
GetLanguagesByShebang,
GetLanguagesByExtension,
GetLanguagesByManpage,
GetLanguagesByContent,
GetLanguagesByClassifier,
}
@ -383,6 +384,26 @@ func GetLanguagesByExtension(filename string, _ []byte, _ []string) []string {
return nil
}
var (
manpageExtension = regex.MustCompile(`\.(?:[1-9](?:[a-z_]+[a-z_0-9]*)?|0p|n|man|mdoc)(?:\.in)?$`)
)
// GetLanguagesByManpage returns a slice of possible manpage languages for the given filename.
// It complies with the signature to be a Strategy type.
func GetLanguagesByManpage(filename string, _ []byte, _ []string) []string {
filename = strings.ToLower(filename)
// Check if matches Roff man page filenames
if manpageExtension.Match([]byte(filename)) {
return []string{
"Roff Manpage",
"Roff",
}
}
return nil
}
func getDotIndexes(filename string) []int {
dots := make([]int, 0, 2)
for i, letter := range filename {