summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/main.go b/main.go
index 8e3243d..5e837f6 100644
--- a/main.go
+++ b/main.go
@@ -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)
}
}