diff --git a/cmd/root.go b/cmd/root.go index 7b7e822..660ec0e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -75,14 +75,14 @@ Find document on: https://github.com/zu1k/nali return } if isJson { - _, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(line).Json()) + _, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(line).Json()) } else { _, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(line).ColorString()) } } } else { if isJson { - _, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(strings.Join(args, " ")).Json()) + _, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(strings.Join(args, " ")).Json()) } else { _, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(strings.Join(args, " ")).ColorString()) } diff --git a/pkg/entity/entity.go b/pkg/entity/entity.go index 618cc62..2c7afbc 100644 --- a/pkg/entity/entity.go +++ b/pkg/entity/entity.go @@ -90,7 +90,10 @@ func (es Entities) ColorString() string { func (es Entities) Json() string { var s strings.Builder for _, e := range es { + if e.Type == TypePlain { + continue + } s.WriteString(e.Json() + "\n") } - return strings.TrimSpace(s.String()) + return s.String() } diff --git a/pkg/entity/parse.go b/pkg/entity/parse.go index 93bd99f..2ad9d3a 100644 --- a/pkg/entity/parse.go +++ b/pkg/entity/parse.go @@ -48,6 +48,13 @@ func ParseLine(line string) Entities { for _, e := range tmp { start := e.Loc[0] if start >= idx { + if start > idx { + es = append(es, &Entity{ + Loc: [2]int{idx, start}, + Type: TypePlain, + Text: line[idx:start], + }) + } res := db.Find(dbif.QueryType(e.Type), e.Text) if res != nil { e.InfoText = res.String() @@ -57,6 +64,12 @@ func ParseLine(line string) Entities { } } } - + if total := len(line); idx < total { + es = append(es, &Entity{ + Loc: [2]int{idx, total}, + Type: TypePlain, + Text: line[idx:total], + }) + } return es }