From 8c9f7852bbd35e0ddf693ff1c8e46fbc9be4f125 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 25 Nov 2020 08:52:51 -0800 Subject: [PATCH] Fix link parsing --- CHANGELOG | 3 ++- pkg/gmitohtml/assets.go | 16 +++++++++++++--- pkg/gmitohtml/convert.go | 23 ++++++++++++++++++----- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 389a39f..b06524c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ 1.0.1: -- Display navigation bar in pages - Add option to allow local file access +- Display navigation bar in pages +- Support dark themed pages via prefers-color-scheme 1.0.0: - Initial release diff --git a/pkg/gmitohtml/assets.go b/pkg/gmitohtml/assets.go index 80371c3..dc0a1e5 100644 --- a/pkg/gmitohtml/assets.go +++ b/pkg/gmitohtml/assets.go @@ -399,15 +399,25 @@ template { color: white; background-color: black; } + h1, h2, h3, h4, h5, h6 { color: white; } + a { - color: #8d94ff; + color: rgb(26, 168, 245); + text-decoration: none; } - a:hover { - color: white; + a:hover, + a:focus, + a:active { + color: rgb(24, 151, 219); + text-decoration: underline; } + a:visited { + color: rgb(200, 118, 255); + } + input { background-color: black; color: white; diff --git a/pkg/gmitohtml/convert.go b/pkg/gmitohtml/convert.go index caa730a..9e7049b 100644 --- a/pkg/gmitohtml/convert.go +++ b/pkg/gmitohtml/convert.go @@ -38,7 +38,11 @@ func rewriteURL(u string, loc *url.URL) string { } else if loc != nil && len(u) > 0 && !strings.HasPrefix(u, "//") { newPath := u if u[0] != '/' { - newPath = path.Join(loc.Path, u) + if loc.Path[len(loc.Path)-1] == '/' { + newPath = path.Join("/", loc.Path, u) + } else { + newPath = path.Join("/", path.Dir(loc.Path), u) + } } return "http://" + daemonAddress + "/" + scheme + "/" + loc.Host + newPath } @@ -84,17 +88,26 @@ func Convert(page []byte, u string) []byte { if line[splitStart] == ' ' || line[splitStart] == '\t' { splitStart++ } - split := bytes.SplitN(line[splitStart:], []byte(" "), 2) - if len(split) != 2 { + + var split [][]byte + firstSpace := bytes.IndexRune(line[splitStart:], ' ') + firstTab := bytes.IndexRune(line[splitStart:], '\t') + if firstSpace != -1 && (firstTab == -1 || firstSpace < firstTab) { + split = bytes.SplitN(line[splitStart:], []byte(" "), 2) + } else if firstTab != -1 { split = bytes.SplitN(line[splitStart:], []byte("\t"), 2) } - linkURL := line[splitStart:] - linkLabel := line[splitStart:] + var linkURL []byte + var linkLabel []byte if len(split) == 2 { linkURL = split[0] linkLabel = split[1] + } else { + linkURL = line[splitStart:] + linkLabel = line[splitStart:] } + link := append([]byte(``)...) link = append(link, html.EscapeString(string(linkLabel))...)