view/utils: Mark up URLs.
authorRicardo Wurmus <rekado@elephly.net>
Wed, 13 May 2020 06:16:43 +0000 (08:16 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Wed, 13 May 2020 06:16:43 +0000 (08:16 +0200)
mumi/web/view/utils.scm

index f863528d592a70220099d04bc2b315cb06b49fc3..0735bf5f6d3cab1477f3480af9fe653ebf846467 100644 (file)
@@ -31,6 +31,7 @@
   #:use-module (email email)
   #:use-module (mumi messages)
   #:use-module (rnrs bytevectors)
+  #:use-module (web uri)
   #:export (prettify
             avatar-color
             display-message-body
@@ -111,6 +112,22 @@ with the next context."
                (else 'text)))
              (formatted-line
               (cond
+               ((or (string-contains line "https://")
+                    (string-contains line "http://")) =>
+                    (lambda (index)
+                      (let* ((pre (string-take line index))
+                             (post (string-drop line index))
+                             (uri+ (string-split post (char-set #\< #\> #\space))))
+                        (match uri+
+                          ((uri-string . rest)
+                           (or (and=> (string->uri uri-string)
+                                      (lambda (uri)
+                                        `(span (@ (class "line"))
+                                               ,(string-trim-right pre #\<)
+                                               (a (@ (href ,uri-string))
+                                                  ,uri-string)
+                                               ,@rest)))
+                               `(span (@ (class "line")) ,line)))))))
                ((or (string-prefix? "Signed-off-by" line)
                     (string-prefix? "Co-authored-by" line))
                 `(span (@ (class "line commit attribution")) ,line))