Subject: [PATCH 16/21] import: juliahub: Beautify description.

From: Nicolas Graves <[email-masked]>
Date: Wed, 15 Mar 2023 13:51:25 +0100

---
 guix/import/juliahub.scm | 60 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 4 deletions(-)

diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index 3985d8d0be..338f042441 100644
--- a/guix/import/juliahub.scm
+++ b/guix/import/juliahub.scm
@@ -32,8 +32,10 @@ (define-module (guix import juliahub)
   #:use-module (guix base32)
   #:use-module (guix packages)
   #:use-module (guix upstream)
-  #:use-module (json)
   #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (json)
+  #:use-module (htmlprag)
+  #:use-module (sxml transform)
 
   #:export (juliahub->guix-package
             %juliahub-updater
@@ -164,6 +166,53 @@ (define (parse-test-dependencies directory)
     (filter (lambda (x) (not (member x %julia-stdlibs)))
             (string-split (string-drop (string-drop-right pure 1) 7) #\,))))
 
+(define %juliahub-beautify-description-rules
+  `((h1 *preorder*   . ,(lambda args #f))
+    (h2 *preorder*   . ,(lambda args #f))
+    (h3 *preorder*   . ,(lambda args #f))
+    (h4 *preorder*   . ,(lambda args #f))
+    (hr *preorder*   . ,(lambda args #f))
+    (span *preorder* . ,(lambda args #f))
+    (img *preorder*  . ,(lambda args #f))
+    (pre *preorder*  . ,(lambda args #f))
+    (div *preorder*  . ,(lambda args #f))
+    (table *preorder* . ,(lambda args #f))
+    (imgalt *preorder* . ,(lambda args #f))
+    (@ *preorder* . ,(lambda args #f))
+    (*TOP*        . ,(lambda args (cdr args)))
+    (p            . ,(lambda args (cdr args)))
+    (em           . ,(lambda args (cdr args)))
+    (strong       . ,(lambda args (cdr args)))
+    (a            . ,(lambda args
+                       (match args
+                         ((tag link ref)
+                          (if ref ref #f))
+                         (_ #f))))
+    (ul           . ,(lambda args
+                       `("@itemize" ,@(cdr args) "\n@end itemize")))
+    (ol           . ,(lambda args
+                       `("@enumerate" ,@(cdr args) "@end enumerate")))
+    (blockquote   . ,(lambda args
+                       `("@quotation" ,@(cdr args) "@end quotation")))
+    (li           . ,(lambda args
+                       `("\n@item" ,@(cdr args))))
+    (code         . ,(lambda args
+                       (string-append
+                        "@code{"
+                        (string-join (cdr args) " ")
+                        "}")))
+    (*text*       . ,(lambda (tag x) x))
+    (*default*    . ,(lambda (tag . body)
+                       (cons tag body)))))
+
+(define (juliahub-beautify-description description)
+  (string-join
+   (filter (lambda (x) (if (equal? x " ") #f x))
+           (flatten
+            (pre-post-order (html->sxml description)
+                            %juliahub-beautify-description-rules)))
+   " "))
+
 ;; Julia package.
 (define-json-mapping <juliahub-package> make-juliahub-package juliahub-package?
   json->juliahub-package
@@ -211,8 +260,9 @@ (define (make-julia-sexp name source home-page synopsis description
      ,@(if (null? direct-dependencies)
            '()
            `((propagated-inputs
-              (list ,@(map (compose julia-name->guix-name juliahub-dependency-name)
-                           direct-dependencies)))))
+              (list
+               ,@(map (compose julia-name->guix-name juliahub-dependency-name)
+                      direct-dependencies)))))
      ,@(if (null? test-dependencies-names)
            '()
            `((native-inputs
@@ -264,7 +314,9 @@ (define* (juliahub->guix-package package-name
                      source
                      (juliahub-package-homepage package)
                      (juliahub-package-description package)
-                     (beautify-description (juliahub-package-readme package))
+                     ((compose beautify-description
+                               juliahub-beautify-description)
+                      (juliahub-package-readme package))
                      direct-dependencies
                      test-dependencies-names
                      licenses)
-- 
2.39.2