Add syntax highlighting for Scheme files.
authorRicardo Wurmus <rekado@elephly.net>
Tue, 4 Sep 2018 00:47:26 +0000 (02:47 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Tue, 4 Sep 2018 00:47:26 +0000 (02:47 +0200)
assets/css/code.css [new file with mode: 0644]
assets/css/screen.css
guix.scm
mumi/web/view/html.scm
mumi/web/view/utils.scm

diff --git a/assets/css/code.css b/assets/css/code.css
new file mode 100644 (file)
index 0000000..c308845
--- /dev/null
@@ -0,0 +1,33 @@
+/* Syntax highlighting code, by David Thompson, borrowed
+   from:
+     https://git.dthompson.us/blog.git/blob_plain/refs/heads/haunt-migration:/css/dthompson.css
+   David Thompson gives permission for this to be GPLv3+ and CC BY-SA 4.0
+
+   Modified significantly since.
+*/
+
+
+.syntax-special, .syntax-element {
+    color: #856;
+    font-weight: bold;
+}
+
+.syntax-symbol {
+    color: #423;
+}
+
+.syntax-string {
+    color: #484;
+}
+
+.syntax-keyword, .syntax-attribute {
+    color: #921;
+}
+
+.syntax-comment {
+    color: #666;
+}
+
+.syntax-open, .syntax-close {
+    color: #688;
+}
index 79dd0a396c5088601de29ea08a7844a93e45bdba..d26f91e6556da5bd674d8791d6d0c0ee3596ab6e 100644 (file)
@@ -151,6 +151,10 @@ table {
 .multipart.text-x-patch {
 }
 
+.multipart.scheme {
+    white-space: pre-wrap;
+}
+
 .attachment:before {
     background-image: url('/img/file.svg');
     background-size: 1rem;
index b0907dc1ffb36437fbc893b02d9eaed1bfd241ad..19aa606610903e62b1268ef394ba97a5a3ff3092 100644 (file)
--- a/guix.scm
+++ b/guix.scm
@@ -135,6 +135,7 @@ Debbugs bug tracker's SOAP service.")
   (build-system gnu-build-system)
   (inputs
    `(("guile-debbugs" ,guile-debbugs-next)
+     ("guile-syntax-highlight" ,guile-syntax-highlight)
      ("mailutils" ,mailutils-next)
      ("guile" ,guile-2.2.4)))
   (native-inputs
index 91c98091c263eefd350c5021edf189ed5c6ab2ab..59771610c055183745ea7d2e39a536e2427bb3d2 100644 (file)
                (@ (rel "stylesheet")
                   (media "screen")
                   (type "text/css")
-                  (href "/css/screen.css"))))
+                  (href "/css/screen.css")))
+              (link
+               (@ (rel "stylesheet")
+                  (media "screen")
+                  (type "text/css")
+                  (href "/css/code.css"))))
              (body ,@body)))
     #:extra-headers ,extra-headers))
 
index ce2827ed5dd1230b04651e614a9c9f44b10a2912..9547f4bffe0ec48019e14d313be8b81739882635 100644 (file)
@@ -20,6 +20,8 @@
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:use-module (srfi srfi-1)
+  #:use-module (syntax-highlight)
+  #:use-module (syntax-highlight scheme)
   #:use-module (debbugs email)
   #:use-module (mumi messages)
   #:export (prettify
@@ -111,23 +113,28 @@ BUG-NUM), even when it is a multipart message."
                  (string-contains type "application")
                  (first (assoc-ref headers "content-disposition"))))
            (attachment-name
-            (or (and=> binary-attachment?
+            (or (and=> (assoc-ref headers "content-disposition")
                        (lambda (value)
-                         (and=> (string-match "filename=([^ ;]+)" value)
+                         (and=> (string-match "filename=([^ ;]+)" (first value))
                                 (lambda (m)
                                   (match:substring m 1)))))
                 "file")))
-      (if binary-attachment?
-          `(div (@ (class "attachment"))
-                "Attachment: "
-                (a (@ (href ,(string-append "/issue/"
-                                            (number->string bug-num)
-                                            "/attachment/"
-                                            (number->string (email-msg-num message))
-                                            "/" (string-join (map number->string path) "/"))))
-                   ,attachment-name))
-          `(div (@ (class ,(string-join `("multipart" ,(or type "")))))
-                ,(prettify body)))))
+      (cond
+       (binary-attachment?
+        `(div (@ (class "attachment"))
+              "Attachment: "
+              (a (@ (href ,(string-append "/issue/"
+                                          (number->string bug-num)
+                                          "/attachment/"
+                                          (number->string (email-msg-num message))
+                                          "/" (string-join (map number->string path) "/"))))
+                 ,attachment-name)))
+       ((string-suffix? ".scm" attachment-name)
+        `(div (@ (class "multipart scheme"))
+              ,(highlights->sxml (highlight lex-scheme body))))
+       (else
+        `(div (@ (class ,(string-join `("multipart" ,(or type "")))))
+              ,(prettify body))))))
   (cond
    ((multipart-message? message)
     => (lambda (attributes)