Publishing Emacs News as plain text, HTML, and attached Org file

Update 2016-02-05: Since @ThierryStoehr linked to this post about Emacs News-related code, I figured I’d add a link to the other support functions I’ve been using to help me with Emacs News summarization. There’s also this bit:

(let ((date (org-read-date nil nil "-mon")))
     (my/org-list-from-rss "" date) "\n"
     (shell-command-to-string (concat "~/bin/ emacs " date)) "\n"
     (shell-command-to-string (concat "~/bin/ org-mode " date)) "\n"
     "- New packages:\n"

Handy little things!


I’ve been publishing these weekly summaries of Emacs-related links on my blog and to the emacs-tangents mailing list / newsgroup. I started by posting plain text from Org Mode’s ASCII export, and people asked for Org Mode and HTML formats. So here’s some code that prepares things for pasting into a Gnus message buffer.

It turns out that order matters for multipart/alternative – start with plain text, then include richer alternatives. First time around, I put the HTML version first, so people didn’t end up seeing it. Anyway, here’s something that shows up properly now: text/plain, then text/html, with text/x-org attached. The heavy lifting is done with org-export-string-as, which exports into different formats.

  (defun my/share-emacs-news ()
    "Prepare current subtree for yanking into post."
    ;; Draft Gnus article
      (let ((org-export-html-preamble nil)
            (org-html-toplevel-hlevel 3)
        (setq output
               "<#multipart type=alternative>
<#part type=\"text/plain\" disposition=inline>
<#part type=\"text/html\" disposition=inline>
<#part type=\"text/x-org\" disposition=attachment name=\"\">
                (lambda (format)
                  (org-export-string-as (buffer-substring (point-min) (point-max)) format t))
                '(ascii html org))))
        (kill-new output))))

Howard Abrams showed me something like this in June 2015’s Emacs Hangout (~1:18:26) using org-mime-org-buffer-htmlize, which probably does the job in a much cooler way. =) I thought he had a blog post about it, but I can’t seem to find it. Anyway, there’s my little hack above!