From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [ELPA/elpa-admin] Render README.org as HTML with ox-html Date: Mon, 06 Sep 2021 23:31:25 -0400 Message-ID: References: <87h7f7zww5.fsf@alphapapa.net> <87zgszy91h.fsf_-_@alphapapa.net> <87a6ku2z8x.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17009"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Adam Porter Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 07 05:32:37 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 1mNRqe-0004Bn-A6 for ged-emacs-devel@m.gmane-mx.org; Tue, 07 Sep 2021 05:32:36 +0200 Original-Received: from localhost ([::1]:48848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNRqc-0006uY-Pi for ged-emacs-devel@m.gmane-mx.org; Mon, 06 Sep 2021 23:32:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNRpg-0006DU-5L for emacs-devel@gnu.org; Mon, 06 Sep 2021 23:31:36 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:54032) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNRpb-00040I-9l for emacs-devel@gnu.org; Mon, 06 Sep 2021 23:31:34 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 12FD880928; Mon, 6 Sep 2021 23:31:32 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 699D0808E4; Mon, 6 Sep 2021 23:31:30 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1630985490; bh=LHrTFnvrvpHuJB/gD22EAjQZX07WPDuV2tOxcR345bU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Qt7yWvu1NWzn7MdKRYVDlGiA0VeAGF18VxcCc+z9agF0v6ZkZYIzJoa4OPIkqNStd VVxhzQAkWdPfBoHzdVUiSQO04LCoYIeVamB4HQI9/o/9CpqwTSB0cSSxnlYotyX3tV vdKvVGnKYvXj8xNmrqN6pm3aJ86LjzzHzH7gZX0reSOVQKFUKQOrrOqyeOcywXuEO1 UKF3UQJqqwd82j67HTo0s6AYbOfJyhGRDQFypHqXLFN3BlCn88D2Zice5kKWSu0CYs DZCXsiP4Nj7Un8O9Q+rTgCzPCIxZv6iIYs4/VEl4y2FaDVKZDq5JRv5SVLZVJoBaUk yC7Fx0peF/DSg== Original-Received: from milanesa (unknown [104.247.244.135]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A541912023D; Mon, 6 Sep 2021 23:31:26 -0400 (EDT) In-Reply-To: <87a6ku2z8x.fsf@alphapapa.net> (Adam Porter's message of "Thu, 02 Sep 2021 21:01:50 -0500") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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:274191 Archived-At: > After some more thinking, the ASCII-only patch seemed redundant, so here > is a new, simpler patch that also accounts for a few other details I had > overlooked. It exports Org readmes to HTML in the ELPA Web page and to > plain-text for the PACKAGE-readme.txt file. Sorry for not getting back to you sooner. I still haven't been able to devote the attention that this deserves, but here's some comments for now: > +(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))) `elpaa--call-sandboxed` doesn't return the exit status of the process. `emacs --batch` will load the site-init files which may emit messages, and those will "pollute" your temp buffer. It's not hypothetical, because the Emacs that's in Debian does exactly that, so the Emacs on elpa.gnu.org (which is arguably the most important Emacs for this code) emits such warnings (that's how I know ;-). So you probably want to pass the result of `org-export-as` to `write-region` to save it explicitly to some file of your choice. I'd also use `%S` rather than `%s` for `backend` (basically I follow the rule that we should always use `%S` except for those cases where the arg is a string and we want to plug its contents). [ Also, I haven't yet tried the code on elpa.gnu.org but that's still running Emacs-26, so there might be compatibility issues for Org. It should be upgraded to Emacs-27 "real soon now", tho, so maybe it's not worth the trouble. ] > @@ -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) The byte-compiler tells me `dir` is an unknown variable. > + 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")) Hmm... this function is already too long, so please move this to a separate function. After tweaking your code a bit to get it to work (see patch below), I'm still not getting the HTML I expect (the "HTML" doc only contains Debian Emacs's extraneous init messages but not the actual HTML from org-export-as, even though running the Emacs command by hand does output it, I haven't had time to dig deeper into the problem). One other thing. I think it would make sense to make `elpaa--get-section` return a pair of the string content and some "type" (org, markdown, plaintext, ...) so as to automatically use your HTML renderer for any .org file we find instead of only when the org file is specified explicitly via `:readme "README.org"`. WDYT? Stefan