all repos — rel2abs @ d12532c24732837934a5e9987e7614764c01ca93

go library to convert all relative urls in a html document to absolute ones

Logs for testing
Anirudh Oppiliappan x@icyphox.sh
Sun, 26 Sep 2021 15:49:21 +0530
commit

d12532c24732837934a5e9987e7614764c01ca93

parent

6680474200d2c244c4fae71ab11101deb905e53a

1 files changed, 2 insertions(+), 4 deletions(-)

jump to
M rel2abs.gorel2abs.go

@@ -13,11 +13,13 @@ if n.Type == html.ElementNode && n.Data == "a" {

for _, a := range n.Attr { if a.Key == "href" { rel, err := url.Parse(a.Val) + fmt.Println("rel:", rel) if err != nil { return fmt.Errorf("relative url: %w\n", err) } a.Val = nurl.ResolveReference(rel).String() + fmt.Println("resolved:", a.Val) } } for c := n.FirstChild; c != nil; c = c.NextSibling {

@@ -29,10 +31,6 @@ }

// Converts all relative URLs in htmlContent to absolute URLs, // resolved against a base URL. -// Example, with base as http://example.com/foo: -// <a href="#fn-1"> -// becomes -// <a href="http://example.com/foo#fn-1"> func Rel2Abs(htmlContent []byte, base string) ([]byte, error) { doc, err := html.Parse(bytes.NewReader(htmlContent)) if err != nil {