diff --git a/README.md b/README.md index 2c65d1c..3213bfe 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,6 @@ Keybinding | Description ## TODO -* Response specific filters (xpath, etc..) * Better navigation * Autocompletion * Tests diff --git a/formatter/html.go b/formatter/html.go index ac28312..93d3011 100644 --- a/formatter/html.go +++ b/formatter/html.go @@ -5,10 +5,12 @@ import ( "errors" "io" + "github.com/PuerkitoBio/goquery" "github.com/x86kernel/htmlcolor" ) type htmlFormatter struct { + parsedBody goquery.Document TextFormatter } @@ -28,3 +30,25 @@ func (f *htmlFormatter) Format(writer io.Writer, data []byte) error { func (f *htmlFormatter) Title() string { return "[html]" } + +func (f *htmlFormatter) Search(q string, body []byte) ([]string, error) { + if q == "" { + buf := bytes.NewBuffer(make([]byte, 0, len(body))) + err := f.Format(buf, body) + return []string{buf.String()}, err + } + doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(body)) + if err != nil { + return nil, err + } + + results := make([]string, 0, 8) + doc.Find(q).Each(func(_ int, s *goquery.Selection) { + htmlResult, err := goquery.OuterHtml(s) + if err == nil { + results = append(results, htmlResult) + } + }) + + return results, nil +}