diff --git a/README.md b/README.md index 971b3d1..5750ddb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Highlight +[![Go Report Card](https://goreportcard.com/badge/github.com/zyedidia/highlight)](https://goreportcard.com/report/github.com/zyedidia/highlight) +[![GoDoc](https://godoc.org/github.com/zyedidia/highlight?status.svg)](http://godoc.org/github.com/zyedidia/highlight) +[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/zyedidia/highlight/blob/master/LICENSE) This is a package for syntax highlighting a large number of different languages. To see the list of languages currently supported, see the [`syntax_files`](./syntax_files) directory. diff --git a/ftdetect.go b/ftdetect.go index a649d4b..e04130f 100644 --- a/ftdetect.go +++ b/ftdetect.go @@ -1,5 +1,8 @@ package highlight +// DetectFiletype will use the list of syntax definitions provided and the filename and first line of the file +// to determine the filetype of the file +// It will return the corresponding syntax definition for the filetype func DetectFiletype(defs []*Def, filename string, firstLine []byte) *Def { for _, d := range defs { if d.ftdetect[0].MatchString(filename) { diff --git a/highlighter.go b/highlighter.go index 4b8abf0..5e4aa0b 100644 --- a/highlighter.go +++ b/highlighter.go @@ -35,13 +35,13 @@ type LineStates interface { // A Highlighter contains the information needed to highlight a string type Highlighter struct { lastRegion *region - def *Def + Def *Def } // NewHighlighter returns a new highlighter from the given syntax definition func NewHighlighter(def *Def) *Highlighter { h := new(Highlighter) - h.def = def + h.Def = def return h } @@ -178,7 +178,7 @@ func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canM firstLoc := []int{len(line), 0} var firstRegion *region - for _, r := range h.def.rules.regions { + for _, r := range h.Def.rules.regions { loc := findIndex(r.start, line, start == 0, canMatchEnd) if loc != nil { if loc[0] < firstLoc[0] { @@ -205,7 +205,7 @@ func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canM } fullHighlights := make([]Group, len(line)) - for _, p := range h.def.rules.patterns { + for _, p := range h.Def.rules.patterns { matches := findAllIndex(p.regex, line, start == 0, canMatchEnd) for _, m := range matches { for i := m[0]; i < m[1]; i++ {