From da325b9ef1f9e3ae139256b33a5da7e19eead4b8 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 29 Aug 2021 17:45:22 -0500 Subject: [PATCH 2/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