From mboxrd@z Thu Jan 1 00:00:00 1970 From: Robert Klein Subject: Re: HTML/images zipped? Date: Mon, 29 Jun 2015 10:47:30 +0200 Message-ID: <20150629104730.5d15ec42@pckr150.mpip-mainz.mpg.de> References: <6sw6c7bng2haym.fsf@pfdstudio.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/f4lmPsynkix6_nLNcnjNIk." Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9Uj5-0006CI-NN for emacs-orgmode@gnu.org; Mon, 29 Jun 2015 04:47:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z9Uj1-00086v-MS for emacs-orgmode@gnu.org; Mon, 29 Jun 2015 04:47:39 -0400 Received: from gate1.mpip-mainz.mpg.de ([194.95.63.248]:53533) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9Uj1-00085u-Cx for emacs-orgmode@gnu.org; Mon, 29 Jun 2015 04:47:35 -0400 In-Reply-To: <6sw6c7bng2haym.fsf@pfdstudio.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Peter Davis Cc: emacs-orgmode@gnu.org --MP_/f4lmPsynkix6_nLNcnjNIk. Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, please find an experimental htmlzip exporter attached. Publishing doesn't work, yet (and would, as I began to write it, export to individual zip files -- one per published org file -- instead of a single zip file). It is a derived HTML exporter. I took a lot of stuff from the corresponding functions in the HTML and LaTeX exporter. I'm putting an advice on org-html--format-image during "zip" export to get a list of inline images, so I can put them together with the html in the zip file. (Another possibility would be to `rewrite' the functions org-html-latex-environment, org-html-latex-fragment, and org-html-link as translate functions for the new exporter (with the only purpose to run a org-htmlzip--image-list instead of org-html--image-list). Best regards Robert On Fri, 26 Jun 2015 09:10:25 -0400 Peter Davis wrote: > > Is there any way to export HTML with all references images, > etc. packaged in a ZIP file? > > Thank you. > > -pd > > --MP_/f4lmPsynkix6_nLNcnjNIk. Content-Type: text/x-emacs-lisp Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=ox-htmlzip.el ;;; ox-htmlzip.el --- Zipped HTML Back-End for Org Export Engine ;; Copyright (C) 2015 Free Software Foundation, Inc. ;; Author: Robert Klein ;; Keywords: HTML, zip ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; This library implements an zip-addon for the HTML back-end for the ;; Org generic exporter. ;;; Code: ;;; Dependencies (require 'ox) (require 'ox-html) ;; in turn requires ox-publish and ox. ;;; Define Derived Back-End (org-export-define-derived-backend 'htmlzip 'html :menu-entry '(?h "Export to HTML" ((?z "To zipped file" org-htmlzip-export-to-htmlzip) )) :options-alist '() :translate-alist '()) ;;; Internal variables (defvar org-htmlzip--image-list nil "Images to upload/change URL in buffer.") ;;; Internal Functions (defun org-htmlzip--add-image (source attributes info) "Add image file name org-htmlzip--image-list. Used as an advice for org-html--image-format during htmlzip export." (add-to-list 'org-htmlzip--image-list source)) ;;; helper functions for export ;;; End-user functions ;;;###autoload (defun org-htmlzip-export-to-htmlzip (&optional async subtreep visible-only body-only ext-plist) "Export current buffer to a HTML file. If narrowing is active in the current buffer, only export its narrowed part. If a region is active, export that region. A non-nil optional argument ASYNC means the process should happen asynchronously. The resulting file should be accessible through the `org-export-stack' interface. When optional argument SUBTREEP is non-nil, export the sub-tree at point, extracting information from the headline properties first. When optional argument VISIBLE-ONLY is non-nil, don't export contents of hidden elements. When optional argument BODY-ONLY is non-nil, only write code between \"\" and \"\" tags. EXT-PLIST, when provided, is a property list with external parameters overriding Org default settings, but still inferior to file-local settings. Return output file's name." (interactive) (advice-add 'org-html--format-image :before #'org-htmlzip--add-image) (setq org-htmlzip--image-list nil) (let* ((extension (concat "." (or (plist-get ext-plist :html-extension) org-html-extension "html"))) (file (org-export-output-file-name extension subtreep)) (org-export-coding-system org-html-coding-system) (zipfile (org-export-to-file 'html file async subtreep visible-only body-only ext-plist (lambda (file) (org-htmlzip--zip file))))) (setq org-htmlzip--image-list nil) (advice-remove 'org-html--format-image #'org-htmlzip--add-image) zipfile)) (defun org-htmlzip--zip (htmlfile) " Zip a HTML file. HTMLFILE is the name of the exported HTML file being zipped. Inline image file names are taken from the global variable or-html--image-list. Return ZIP file name." (let* ((base-name (file-name-sans-extension (file-name-nondirectory htmlfile))) (full-name (file-truename htmlfile)) (out-dir (file-name-directory htmlfile)) (zip-file (concat base-name ".zip")) ;; Properly set working directory for compilation. (default-directory (if (file-name-absolute-p htmlfile) (file-name-directory full-name) default-directory))) ;; delete zip file if it exists (when (file-exists-p zip-file) (delete-file zip-file)) ;; zip newly exported files (shell-command (concat "zip " (shell-quote-argument zip-file) " " (shell-quote-argument htmlfile) " " (mapconcat 'shell-quote-argument org-htmlzip--image-list " "))) zip-file)) ;;;###autoload (defun org-htmlzip-publish-to-htmlzip (plist filename pub-dir) "Publish an org file to ZIP (via HTML). FILENAME is the filename of the Org file to be published. PLIST is the property list for the given project. PUB-DIR is the publishing directory. Return output file name." ;; Unlike to `org-html-publish-to-html', PDF file is generated ;; in working directory and then moved to publishing directory. (advice-add 'org-html--format-image :before #'org-htmlzip--add-image) (setq org-htmlzip--image-list nil) (let ((outfile (org-publish-attachment plist (org-htmlzip--zip (org-publish-org-to 'htmlzip filename ".html" plist (file-name-directory filename))) pub-dir))) (setq org-htmlzip--image-list nil) (advice-remove 'org-html--format-image #'org-htmlzip--add-image) outfile)) (provide 'ox-htmlzip) ;; Local variables: ;; generated-autoload-file: "org-loaddefs.el" ;; End: ;;; ox-htmlzip.el ends here --MP_/f4lmPsynkix6_nLNcnjNIk.--