diff --git a/pkg/hicli/html.go b/pkg/hicli/html.go index bcc9fbb..d0c1332 100644 --- a/pkg/hicli/html.go +++ b/pkg/hicli/html.go @@ -199,25 +199,55 @@ func writeURL(w *strings.Builder, addr []byte) { 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 + w.WriteString(`') + writeEscapedBytes(w, addr) + w.WriteString("") + case "mxc": + mxc := id.ContentURIString(parsedURL.String()).ParseOrIgnore() + if !mxc.IsValid() { + writeEscapedBytes(w, addr) + return + } + w.WriteString("') + writeEscapedBytes(w, addr) + w.WriteString("") + case "matrix": + uri, err := id.ProcessMatrixURI(parsedURL) + if err != nil { + writeEscapedBytes(w, addr) + return + } + w.WriteString("') + writeEscapedBytes(w, addr) + w.WriteString("") default: writeEscapedBytes(w, addr) - return } - w.WriteString(`') - writeEscapedBytes(w, addr) - w.WriteString("") } func linkifyAndWriteBytes(w *strings.Builder, s []byte) { @@ -370,6 +400,8 @@ func writeA(w *strings.Builder, attr []html.Attribute) (mxc id.ContentURI) { mxc = id.ContentURI{} return } + writeAttribute(w, "class", "hicli-mxc-url") + writeAttribute(w, "data-mxc", mxc.String()) href = fmt.Sprintf(HTMLSanitizerImgSrcTemplate, mxc.Homeserver, mxc.FileID) default: return