unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Adam Porter <adam@alphapapa.net>
Cc: emacs-devel@gnu.org
Subject: Re: [ELPA/elpa-admin] Render README.org as HTML with ox-html
Date: Mon, 06 Sep 2021 23:31:25 -0400	[thread overview]
Message-ID: <jwv5yvd3xof.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87a6ku2z8x.fsf@alphapapa.net> (Adam Porter's message of "Thu, 02 Sep 2021 21:01:50 -0500")

> 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 "<p>To install this package, run in Emacs:</p>
>                         <pre>M-x <span class=\"kw\">package-install</span> RET <span class=\"kw\">%s</span> RET</pre>"
>                        name))
> -      (let ((rm (elpaa--get-README pkg-spec srcdir)))
> -        (when rm
> -          (write-region rm nil (concat name "-readme.txt"))
> -          (insert "<h2>Full description</h2><pre>\n" (elpaa--html-quote rm)
> -                  "\n</pre>\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 "<pre>\n"
> +                                        (elpaa--html-quote readme-content)
> +                                        "\n</pre>\n")))))
> +        (when readme-content
> +          (write-region readme-content nil output-filename)
> +          (insert "<h2>Full description</h2>\n" page-content)))
>        ;; (message "latest=%S; files=%S" latest files)
>        (unless (< (length files) (if (zerop (length latest)) 1 2))
>          (insert (format "<h2>Old versions</h2><table>\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




  reply	other threads:[~2021-09-07  3:31 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-29 22:52 [ELPA/elpa-admin] Render README.org as ASCII with ox-ascii Adam Porter
2021-08-29 23:28 ` Adam Porter
2021-08-29 23:38 ` Clément Pit-Claudel
2021-08-30  0:01   ` Adam Porter
2021-08-30  1:49     ` Clément Pit-Claudel
2021-08-30  2:15       ` Adam Porter
2021-08-30  0:48 ` Stefan Monnier
2021-08-30  1:29   ` Adam Porter
2021-08-30  2:13   ` [ELPA/elpa-admin] Render README.org as HTML with ox-html Adam Porter
2021-09-03  2:01     ` Adam Porter
2021-09-07  3:31       ` Stefan Monnier [this message]
2021-09-07  8:12         ` Philip Kaludercic
2021-09-07 10:26         ` Adam Porter
2021-09-10 20:58           ` Stefan Monnier
2021-09-12 13:03             ` Adam Porter
2021-09-20  4:29               ` Stefan Monnier
2021-09-20  6:41                 ` Stefan Kangas
2021-09-20 13:40                   ` Basil L. Contovounesios
2021-09-20 19:57                   ` Adam Porter
2021-09-20 23:26                 ` Adam Porter
2021-10-09 15:08                   ` Stefan Monnier
2021-10-09 16:39                     ` Eric Abrahamsen
2021-10-10  3:37                       ` Stefan Monnier
2021-10-10  3:54                         ` Corwin Brust
2021-10-10 13:27                           ` Stefan Monnier
2021-10-10  4:32                         ` Eric Abrahamsen
2021-10-10 14:50                     ` Adam Porter
2021-10-10 15:30                       ` Stefan Monnier
2021-08-30 17:49   ` [ELPA/elpa-admin] Render README.org as ASCII with ox-ascii Philip Kaludercic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv5yvd3xof.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=adam@alphapapa.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).