commit dcaf0b6

delthas  ·  2022-03-29 13:35:38 +0000 UTC
parent 159853d
Add HTTPS schema by default to hyperlinks
1 files changed,  +4, -0
+4, -0
 1@@ -2,6 +2,7 @@ package ui
 2 
 3 import (
 4 	"fmt"
 5+	"net/url"
 6 	"strconv"
 7 	"strings"
 8 	"unicode/utf8"
 9@@ -137,6 +138,9 @@ func (s StyledString) ParseURLs() StyledString {
10 		u := urls[i]
11 		ub, ue := u[0], u[1]
12 		link := s.string[u[0]:u[1]]
13+		if u, err := url.Parse(link); err != nil || u.Scheme == "" {
14+			link = "https://" + link
15+		}
16 		// find last style starting before or at url begin
17 		for ; j < len(s.styles); j++ {
18 			st := s.styles[j]