hicli/html: convert plaintext matrix.to links to matrix: URIs

This commit is contained in:
Tulir Asokan 2024-10-19 17:13:45 +03:00
parent 3fdaf8ae4e
commit c6cdb820ea

View file

@ -179,11 +179,18 @@ func writeURL(w *strings.Builder, addr []byte) {
writeEscapedBytes(w, addr) writeEscapedBytes(w, addr)
return return
} }
w.WriteString(`<a`)
if matrixURI, err := id.ProcessMatrixToURL(parsedURL); err == nil {
writeAttribute(w, "href", matrixURI.String())
writeAttribute(w, "class", matrixURIClassName(matrixURI)+" hicli-matrix-uri-plaintext")
} else {
if parsedURL.Scheme == "" { if parsedURL.Scheme == "" {
parsedURL.Scheme = "https" parsedURL.Scheme = "https"
} }
w.WriteString(`<a target="_blank" rel="noreferrer noopener"`) writeAttribute(w, "target", "_blank")
writeAttribute(w, "rel", "noreferrer noopener")
writeAttribute(w, "href", parsedURL.String()) writeAttribute(w, "href", parsedURL.String())
}
w.WriteByte('>') w.WriteByte('>')
writeEscapedBytes(w, addr) writeEscapedBytes(w, addr)
w.WriteString("</a>") w.WriteString("</a>")