From 60c959ddfad184988be74c1ed32f1759d1a24610 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 29 Aug 2021 17:45:22 -0500 Subject: [PATCH] * elpa-admin.el: Export Org readmes to ASCII and HTML (elpaa--export-org): New function. (elpaa--org-export-options): New variable. (elpaa--html-make-pkg): Export Org readmes to HTML and plain-text, and other readme formats to plain-text. --- elpa-admin.el | 63 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/elpa-admin.el b/elpa-admin.el index ac72f2f..40a355f 100644 --- a/elpa-admin.el +++ b/elpa-admin.el @@ -69,6 +69,11 @@ to be installed and has only been tested on some Debian systems.") (defvar elpaa--debug nil) +(defvar elpaa--org-export-options + '(:with-author nil :with-creator nil :with-broken-links t) + "Options used common to all Org export backends. +See variable `org-export-options-alist'.") + (unless (fboundp 'ignore-error) (defmacro ignore-error (condition &rest body) `(condition-case nil (progn ,@body) (,condition nil)))) @@ -1209,15 +1214,23 @@ return section under HEADER in package's main file." (delete-region (point) (point-max)) (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)) +(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." + (declare (indent defun)) + (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" (format "ox-%s" backend) + file + "--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))) (defun elpaa--get-NEWS (pkg-spec dir) (let ((text @@ -1313,11 +1326,33 @@ return section under HEADER in package's main file." (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)
-                  "\n
\n"))) + (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 (concat name "-readme.txt")) + readme-content page-content) + (pcase readme-file-name + ("README.org" + (setf readme-content (elpaa--export-org readme-file-name 'ascii + :ext-plist (append '(:ascii-charset utf-8) + elpaa--org-export-options)) + page-content (elpaa--export-org readme-file-name 'html + :body-only t :ext-plist elpaa--org-export-options))) + (_ ;; Non-Org readme. + (setf readme-content (elpaa--get-section + "Commentary" readme-file-name + dir pkg-spec) + page-content (when readme-content + (concat "
\n"
+                                        (elpaa--html-quote readme-content)
+                                        "\n
\n"))))) + (when readme-content + (write-region readme-content nil output-filename) + (insert "

Full description

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

Old versions

\n")) -- 2.7.4