1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-07-15 01:14:21 +02:00

Add analyser for bash.

This commit is contained in:
Alec Thomas
2017-09-18 20:30:19 +10:00
parent 57c8e08560
commit 2dc153de8a

View File

@ -1,9 +1,13 @@
package lexers package lexers
import ( import (
"regexp"
. "github.com/alecthomas/chroma" // nolint . "github.com/alecthomas/chroma" // nolint
) )
var bashAnalyserRe = regexp.MustCompile(`(?m)^#!.*/bin/(?:bash|zsh|sh|ksh)`)
// Bash lexer. // Bash lexer.
var Bash = Register(MustNewLexer( var Bash = Register(MustNewLexer(
&Config{ &Config{
@ -82,4 +86,9 @@ var Bash = Register(MustNewLexer(
Include("root"), Include("root"),
}, },
}, },
)) ).SetAnalyser(func(text string) float32 {
if bashAnalyserRe.FindString(text) != "" {
return 1.0
}
return 0.0
}))