From e16318d58092338a3051edb6938ca3c45c1f221e Mon Sep 17 00:00:00 2001 From: Tadas Vilkeliskis Date: Tue, 30 Dec 2025 22:11:37 -0500 Subject: implement modificatoins --- main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'main.go') 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) } } -- cgit v1.2.3