diff options
| -rw-r--r-- | main.go | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -26,6 +26,7 @@ func main() { selector := flag.String("selector", "", "DOM query") mode := flag.String("mode", "query", "Operation mode: query, replace, append, prepend") filename := flag.String("filename", "", "Path to HTML file") + writeData := flag.String("wdata", "", "Data to write when in non-query mode") flag.Parse() //args := flag.Args() @@ -66,8 +67,27 @@ func main() { }) } case ModeReplace: + doc.Find(*selector).Each(func(i int, s *goquery.Selection) { + s.ReplaceWithHtml(*writeData) + }) case ModeAppend: + doc.Find(*selector).Each(func(i int, s *goquery.Selection) { + s.AppendHtml(*writeData) + }) case ModePrepend: + doc.Find(*selector).Each(func(i int, s *goquery.Selection) { + s.PrependHtml(*writeData) + }) + } + + if parsedMode != ModeQuery { + // in non-query mode, print entire document back with modifications + htmlStr, err := doc.Html() + if err != nil { + fmt.Fprintf(os.Stderr, "failed to render node: %s", err.Error()) + os.Exit(1) + } + fmt.Println(htmlStr) } } |
