Subject: [bug#62202] [PATCH v3 3/4] import: juliahub: Beautify description.

From: Nicolas Graves <[email-masked]>
Date: Thu, 21 Dec 2023 15:01:02 +0100

---
 guix/import/juliahub.scm | 53 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index ab838b6035..e4540de06d 100644
--- a/guix/import/juliahub.scm
+++ b/guix/import/juliahub.scm
@@ -30,8 +30,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
@@ -76,6 +78,53 @@ (define (ini-fetch url)
     (close-port port)
     (map ini-line->alist lines)))
 
+;; Beautify description.
+(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))
+    (h5 *preorder*   . ,(lambda args #f))
+    (h6 *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
+                       `("@code{" ,@(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)))
+   " "))
+
 ;; Filtering out julia-stdlibs.
 ;; To update them, see file sysimg.jl.
 (define %julia-stdlibs
@@ -264,7 +313,7 @@ (define* (juliahub->guix-package package-name
                      ((? string?) homepage)
                      (_ (juliahub-package-url package)))
                    (juliahub-package-description package)
-                   (beautify-description
+                   ((compose beautify-description juliahub-beautify-description)
                     (juliahub-package-readme package))
                    direct-dependencies
                    test-dependencies-names
-- 
2.41.0