mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
hicli/html: correctly linkify plaintext emails
This commit is contained in:
parent
c6cdb820ea
commit
e40a97f43b
1 changed files with 28 additions and 4 deletions
|
@ -174,19 +174,43 @@ func writeMention(w *strings.Builder, mention []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeURL(w *strings.Builder, addr []byte) {
|
func writeURL(w *strings.Builder, addr []byte) {
|
||||||
parsedURL, err := url.Parse(string(addr))
|
addrString := string(addr)
|
||||||
|
parsedURL, err := url.Parse(addrString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeEscapedBytes(w, addr)
|
writeEscapedBytes(w, addr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if parsedURL.Scheme == "" && parsedURL.Host == "" {
|
||||||
|
if parsedURL.RawQuery == "" && parsedURL.Fragment == "" && strings.LastIndexByte(parsedURL.Path, '/') == -1 && strings.IndexByte(parsedURL.Path, '@') > 0 {
|
||||||
|
parsedURL.Scheme = "mailto"
|
||||||
|
parsedURL.Opaque = parsedURL.Path
|
||||||
|
parsedURL.Path = ""
|
||||||
|
} else {
|
||||||
|
parsedURL, err = url.Parse("https://" + addrString)
|
||||||
|
if err != nil {
|
||||||
|
writeEscapedBytes(w, addr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if parsedURL.Scheme == "" {
|
||||||
|
parsedURL.Scheme = "https"
|
||||||
|
}
|
||||||
|
switch parsedURL.Scheme {
|
||||||
|
case "bitcoin", "ftp", "geo", "http", "im", "irc", "ircs", "magnet", "mailto",
|
||||||
|
"mms", "news", "nntp", "openpgp4fpr", "sip", "sftp", "sms", "smsto", "ssh",
|
||||||
|
"tel", "urn", "webcal", "wtai", "xmpp", "https":
|
||||||
|
case "mxc", "matrix":
|
||||||
|
// TODO
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
writeEscapedBytes(w, addr)
|
||||||
|
return
|
||||||
|
}
|
||||||
w.WriteString(`<a`)
|
w.WriteString(`<a`)
|
||||||
if matrixURI, err := id.ProcessMatrixToURL(parsedURL); err == nil {
|
if matrixURI, err := id.ProcessMatrixToURL(parsedURL); err == nil {
|
||||||
writeAttribute(w, "href", matrixURI.String())
|
writeAttribute(w, "href", matrixURI.String())
|
||||||
writeAttribute(w, "class", matrixURIClassName(matrixURI)+" hicli-matrix-uri-plaintext")
|
writeAttribute(w, "class", matrixURIClassName(matrixURI)+" hicli-matrix-uri-plaintext")
|
||||||
} else {
|
} else {
|
||||||
if parsedURL.Scheme == "" {
|
|
||||||
parsedURL.Scheme = "https"
|
|
||||||
}
|
|
||||||
writeAttribute(w, "target", "_blank")
|
writeAttribute(w, "target", "_blank")
|
||||||
writeAttribute(w, "rel", "noreferrer noopener")
|
writeAttribute(w, "rel", "noreferrer noopener")
|
||||||
writeAttribute(w, "href", parsedURL.String())
|
writeAttribute(w, "href", parsedURL.String())
|
||||||
|
|
Loading…
Add table
Reference in a new issue