---
prodded around on #senpai asking whether i should add this, got no
strong response so throwing this here for posterity.
the original idea was to have a nerd-fonts image button next to the
image but i decided against that and to use a different underline.
UnderlineDashed was picked as it's the most similar to UnderlineDotted,
but i could go with a solid underline if deemed more readable.
ui/style.go | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/ui/style.go b/ui/style.go
index c563aca..03572a2 100644
--- a/ui/style.go+++ b/ui/style.go
@@ -4,6 +4,7 @@ import (
"fmt"
"math/rand"
"net/url"
+ "path" "regexp"
"strconv"
"strings"
@@ -114,6 +115,7 @@ func (s StyledString) ParseURLs() StyledString {
u := urls[i]
ub, ue := u[0], u[1]
link := s.string[u[0]:u[1]]
+ img := false var params string
if link[0] == '#' {
if prev := lastRuneBefore(s.string, u[0]); !(prev == 0 || unicode.IsSpace(prev) || prev == '(' || prev == '[') {
@@ -129,6 +131,13 @@ func (s StyledString) ParseURLs() StyledString {
link = "https://" + link
}
params = fmt.Sprintf("id=_%010d", rand.Int31())
+ // roughly guess whether this link is an image or not based on file extension+ if u, err := url.Parse(link); err == nil {+ switch strings.ToLower(path.Ext(u.Path)) {+ case ".jpg", ".jpeg", ".png", ".gif":+ img = true+ }+ } }
// find last style starting before or at url begin
for ; j < len(s.styles); j++ {
@@ -140,6 +149,9 @@ func (s StyledString) ParseURLs() StyledString {
// a style already starts at this position, edit it
st.Style.Hyperlink = link
st.Style.HyperlinkParams = params
+ if img {+ st.Style.UnderlineStyle = vaxis.UnderlineDashed+ } }
lastStyle = st
styles = append(styles, st)
@@ -149,6 +161,9 @@ func (s StyledString) ParseURLs() StyledString {
st := lastStyle.Style
st.Hyperlink = link
st.HyperlinkParams = params
+ if img {+ st.UnderlineStyle = vaxis.UnderlineDashed+ } styles = append(styles, rangedStyle{
Start: ub,
Style: st,
base-commit: f61411c169f0386d66fa3cedd9758a38eab2d68f
--
2.45.2