From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: Re: [ELPA/elpa-admin] Render README.org as HTML with ox-html Date: Sun, 29 Aug 2021 21:13:14 -0500 Message-ID: <87zgszy91h.fsf_-_@alphapapa.net> References: <87h7f7zww5.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32749"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Aug 30 04:14:10 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mKWoL-0008IF-2t for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Aug 2021 04:14:09 +0200 Original-Received: from localhost ([::1]:32896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKWoJ-0003Rk-7H for ged-emacs-devel@m.gmane-mx.org; Sun, 29 Aug 2021 22:14:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKWnh-0002mb-NK for emacs-devel@gnu.org; Sun, 29 Aug 2021 22:13:30 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:53036) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKWnf-0001Hz-DC for emacs-devel@gnu.org; Sun, 29 Aug 2021 22:13:29 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mKWnd-0007UQ-G7 for emacs-devel@gnu.org; Mon, 30 Aug 2021 04:13:25 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:273452 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: > I hope we can generate HTML rather than "clean text", but in the mean > time, clean text is better than raw source, so: thanks. Building on the previous patches, here's my attempt at exporting Org to HTML. I don't know if it accounts for everything that should be accounted for (there's much I don't understand about the build process), so it might need a few changes, but I think it should basically work. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-elpa-admin.el-Export-Org-readmes-to-readable-text.patch >From d54be5068756e2a4845e866332c82508512e3145 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 29 Aug 2021 17:45:22 -0500 Subject: [PATCH 1/2] * elpa-admin.el: Export Org readmes to readable text Exports "README.org" files using ox-ascii.el, which is more readable on the ELPA Web site. (elpaa--export-org): New function. (elpaa--get-README): Add docstring, call new function. --- elpa-admin.el | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/elpa-admin.el b/elpa-admin.el index ac72f2f..3682bec 100644 --- a/elpa-admin.el +++ b/elpa-admin.el @@ -1210,14 +1210,36 @@ return section under HEADER in package's main file." (buffer-string))))))) (defun elpaa--get-README (pkg-spec dir) - (elpaa--get-section - "Commentary" (elpaa--spec-get pkg-spec :readme - '("README" "README.rst" - ;; Most README.md files seem to be currently - ;; worse than the Commentary: section :-( - ;; "README.md" - "README.org")) - dir pkg-spec)) + "Return readme for PKG-SPEC in DIR as a string. +If readme is an Org file, render it to plain-text using Org +Export." + (let ((readme-file + (elpaa--spec-get pkg-spec :readme + '("README" "README.rst" + ;; Most README.md files seem to be currently + ;; worse than the Commentary: section :-( + ;; "README.md" + "README.org")))) + (pcase readme-file + ("README.org" + (elpaa--export-org readme-file 'ascii '(:ascii-charset utf-8 :with-broken-links t))) + (_ (elpaa--get-section + "Commentary" readme-file + dir pkg-spec))))) + +(defun elpaa--export-org (file backend &optional ext-plist) + "Return Org FILE as an exported string. +BACKEND and EXT-PLIST are passed to `org-export-as', which see. +Uses `elpaa--call-sandboxed', since exporting with Org may run +arbitrary code." + (with-temp-buffer + (unless (zerop (elpaa--call-sandboxed + t "emacs" "--batch" "-l" "ox-ascii" + file + "--eval" (format "(message \"%%s\" (org-export-as '%s nil nil nil '%S))" + backend ext-plist))) + (error "Unable to export Org file: %S" file)) + (buffer-string))) (defun elpaa--get-NEWS (pkg-spec dir) (let ((text -- 2.7.4 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-elpa-admin.el-Export-Org-to-HTML-content-and-files.patch >From 4c7d4b5c1de11f80f411f7f2e7e423a0b893f7a5 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 29 Aug 2021 21:03:37 -0500 Subject: [PATCH 2/2] * elpa-admin.el: Export Org to HTML content and files (elpaa--export-org): Export to specified backend, optionally with body-only. (elpaa--get-README): Use elpaa--export-org to export HTML. (elpaa--html-make-pkg): Export Org readmes to HTML, and other readme formats to plain text. --- elpa-admin.el | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/elpa-admin.el b/elpa-admin.el index 3682bec..791bc67 100644 --- a/elpa-admin.el +++ b/elpa-admin.el @@ -1222,22 +1222,27 @@ Export." "README.org")))) (pcase readme-file ("README.org" - (elpaa--export-org readme-file 'ascii '(:ascii-charset utf-8 :with-broken-links t))) + (elpaa--export-org + readme-file 'html + :body-only t :ext-plist '(:ascii-charset utf-8 :with-broken-links t))) (_ (elpaa--get-section "Commentary" readme-file dir pkg-spec))))) -(defun elpaa--export-org (file backend &optional ext-plist) +(cl-defun elpaa--export-org (file backend &key body-only ext-plist) "Return Org FILE as an exported string. BACKEND and EXT-PLIST are passed to `org-export-as', which see. Uses `elpaa--call-sandboxed', since exporting with Org may run arbitrary code." + (cl-check-type backend symbol) + (cl-assert (memq body-only '(nil t)) t + "BODY-ONLY may only be nil or t") (with-temp-buffer (unless (zerop (elpaa--call-sandboxed - t "emacs" "--batch" "-l" "ox-ascii" + t "emacs" "--batch" "-l" (format "ox-%s" backend) file - "--eval" (format "(message \"%%s\" (org-export-as '%s nil nil nil '%S))" - backend ext-plist))) + "--eval" (format "(message \"%%s\" (org-export-as '%s nil nil %S '%S))" + backend body-only ext-plist))) (error "Unable to export Org file: %S" file)) (buffer-string))) @@ -1335,10 +1340,33 @@ arbitrary code." (insert (format "

To install this package, run in Emacs:

M-x package-install RET %s RET
" name)) - (let ((rm (elpaa--get-README pkg-spec srcdir))) - (when rm - (write-region rm nil (concat name "-readme.txt")) - (insert "

Full description

\n" (elpaa--html-quote rm)
+      (let ((readme-file-name
+             (elpaa--spec-get pkg-spec :readme
+                              '("README" "README.rst"
+                                ;; Most README.md files seem to be currently
+                                ;; worse than the Commentary: section :-(
+                                ;; "README.md"
+                                "README.org")))
+            output-filename readme-content page-content)
+        (pcase readme-file-name
+          ("README.org"
+           (setf output-filename (concat name "-readme.html")
+                 readme-content (elpaa--export-org
+                                 readme-file-name 'html
+                                 :ext-plist '(:with-broken-links t))
+                 page-content (elpaa--export-org
+                               readme-file-name 'html
+                               :body-only t :ext-plist '(:with-broken-links t))))
+          (_ ;; Non-Org readme.
+           (setf output-filename (concat name "-readme.txt")
+                 readme-content (elpaa--get-section
+                                 "Commentary" readme-file-name
+                                 dir pkg-spec)
+                 page-content (when readme-content
+                                (elpaa--html-quote readme-content)))))
+        (when readme-content
+          (write-region readme-content nil output-filename)
+          (insert "

Full description

\n" page-content
                   "\n
\n"))) ;; (message "latest=%S; files=%S" latest files) (unless (< (length files) (if (zerop (length latest)) 1 2)) -- 2.7.4 --=-=-=--