mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-06 08:57:15 -04:00
Add badges to readme
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
# Highlight
|
# Highlight
|
||||||
|
[](https://goreportcard.com/report/github.com/zyedidia/highlight)
|
||||||
|
[](http://godoc.org/github.com/zyedidia/highlight)
|
||||||
|
[](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
|
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.
|
languages currently supported, see the [`syntax_files`](./syntax_files) directory.
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package highlight
|
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 {
|
func DetectFiletype(defs []*Def, filename string, firstLine []byte) *Def {
|
||||||
for _, d := range defs {
|
for _, d := range defs {
|
||||||
if d.ftdetect[0].MatchString(filename) {
|
if d.ftdetect[0].MatchString(filename) {
|
||||||
|
|||||||
+4
-4
@@ -35,13 +35,13 @@ type LineStates interface {
|
|||||||
// A Highlighter contains the information needed to highlight a string
|
// A Highlighter contains the information needed to highlight a string
|
||||||
type Highlighter struct {
|
type Highlighter struct {
|
||||||
lastRegion *region
|
lastRegion *region
|
||||||
def *Def
|
Def *Def
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHighlighter returns a new highlighter from the given syntax definition
|
// NewHighlighter returns a new highlighter from the given syntax definition
|
||||||
func NewHighlighter(def *Def) *Highlighter {
|
func NewHighlighter(def *Def) *Highlighter {
|
||||||
h := new(Highlighter)
|
h := new(Highlighter)
|
||||||
h.def = def
|
h.Def = def
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canM
|
|||||||
|
|
||||||
firstLoc := []int{len(line), 0}
|
firstLoc := []int{len(line), 0}
|
||||||
var firstRegion *region
|
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)
|
loc := findIndex(r.start, line, start == 0, canMatchEnd)
|
||||||
if loc != nil {
|
if loc != nil {
|
||||||
if loc[0] < firstLoc[0] {
|
if loc[0] < firstLoc[0] {
|
||||||
@@ -205,7 +205,7 @@ func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canM
|
|||||||
}
|
}
|
||||||
|
|
||||||
fullHighlights := make([]Group, len(line))
|
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)
|
matches := findAllIndex(p.regex, line, start == 0, canMatchEnd)
|
||||||
for _, m := range matches {
|
for _, m := range matches {
|
||||||
for i := m[0]; i < m[1]; i++ {
|
for i := m[0]; i < m[1]; i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user