all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* HTML/images zipped?
@ 2015-06-26 13:10 Peter Davis
  2015-06-26 13:15 ` Rasmus
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Peter Davis @ 2015-06-26 13:10 UTC (permalink / raw)
  To: emacs-orgmode


Is there any way to export HTML with all references images,
etc. packaged in a ZIP file?

Thank you.

-pd

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 13:10 HTML/images zipped? Peter Davis
@ 2015-06-26 13:15 ` Rasmus
  2015-06-26 14:05   ` Peter Davis
  2015-06-26 14:24   ` John Kitchin
  2015-06-26 13:44 ` Phillip Lord
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 18+ messages in thread
From: Rasmus @ 2015-06-26 13:15 UTC (permalink / raw)
  To: emacs-orgmode

Peter Davis <pfd@pfdstudio.com> writes:

> Is there any way to export HTML with all references images,
> etc. packaged in a ZIP file?

My guess is that at the moment your best bet is hacking some together with
ox-publish.  See org-publish-project-alist.

Hope it helps,
Rasmus

PS: On the list, we have talked about a .borg format that might serve for
similar situation but it's at an idea stage at the moment.

-- 
This message is brought to you by the department of redundant departments

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 13:10 HTML/images zipped? Peter Davis
  2015-06-26 13:15 ` Rasmus
@ 2015-06-26 13:44 ` Phillip Lord
  2015-06-26 14:08   ` Peter Davis
  2015-06-29  8:47 ` Robert Klein
  2015-06-30  5:38 ` Vaidheeswaran C
  3 siblings, 1 reply; 18+ messages in thread
From: Phillip Lord @ 2015-06-26 13:44 UTC (permalink / raw)
  To: Peter Davis; +Cc: emacs-orgmode


data-uri's is probably what you want. There is no standard format for
zipping multiple HTML files together, while including images (or video's
or audio) directly into the HTML works reasonably well.

I found a snippet to get ox-html to do this -- it would be a good
feature to add properly though!


Peter Davis <pfd@pfdstudio.com> writes:

> Is there any way to export HTML with all references images,
> etc. packaged in a ZIP file?
>
> Thank you.
>
> -pd
>
>
>
>

-- 
Phillip Lord,                           Phone: +44 (0) 191 208 7827
Lecturer in Bioinformatics,             Email: phillip.lord@newcastle.ac.uk
School of Computing Science,            http://homepages.cs.ncl.ac.uk/phillip.lord
Room 914 Claremont Tower,               skype: russet_apples
Newcastle University,                   twitter: phillord
NE1 7RU                                 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 13:15 ` Rasmus
@ 2015-06-26 14:05   ` Peter Davis
  2015-06-26 14:24   ` John Kitchin
  1 sibling, 0 replies; 18+ messages in thread
From: Peter Davis @ 2015-06-26 14:05 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> Peter Davis <pfd@pfdstudio.com> writes:
>
>> Is there any way to export HTML with all references images,
>> etc. packaged in a ZIP file?
>
> My guess is that at the moment your best bet is hacking some together with
> ox-publish.  See org-publish-project-alist.

Thanks, Rasmus. I'll take a look when I have a chance, but for now, I'll
have to zip the files by hand.

Thanks!
-pd

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 13:44 ` Phillip Lord
@ 2015-06-26 14:08   ` Peter Davis
  2015-06-26 14:30     ` John Kitchin
  0 siblings, 1 reply; 18+ messages in thread
From: Peter Davis @ 2015-06-26 14:08 UTC (permalink / raw)
  To: Phillip Lord; +Cc: emacs-orgmode

phillip.lord@newcastle.ac.uk (Phillip Lord) writes:

> data-uri's is probably what you want. There is no standard format for
> zipping multiple HTML files together, while including images (or video's
> or audio) directly into the HTML works reasonably well.
>
> I found a snippet to get ox-html to do this -- it would be a good
> feature to add properly though!

Thanks, Phillip. That sounds like an interesting possibility. I've never
worked with data-uri's. Can you post or send that snippet? I don't seem
to be finding it on my initial searches.

Thanks,
-pd

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 13:15 ` Rasmus
  2015-06-26 14:05   ` Peter Davis
@ 2015-06-26 14:24   ` John Kitchin
  2015-06-26 14:35     ` Peter Davis
                       ` (2 more replies)
  1 sibling, 3 replies; 18+ messages in thread
From: John Kitchin @ 2015-06-26 14:24 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

I did something like this for org-files:
https://github.com/jkitchin/jmax/blob/master/ox-archive.el

You might use that as a starting point for html.

Also, my blogofile code
(https://github.com/jkitchin/jmax/blob/master/user/blogofile.el) does
something like this to publish org to blogofile.



Rasmus writes:

> Peter Davis <pfd@pfdstudio.com> writes:
>
>> Is there any way to export HTML with all references images,
>> etc. packaged in a ZIP file?
>
> My guess is that at the moment your best bet is hacking some together with
> ox-publish.  See org-publish-project-alist.
>
> Hope it helps,
> Rasmus
>
> PS: On the list, we have talked about a .borg format that might serve for
> similar situation but it's at an idea stage at the moment.

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 14:08   ` Peter Davis
@ 2015-06-26 14:30     ` John Kitchin
  0 siblings, 0 replies; 18+ messages in thread
From: John Kitchin @ 2015-06-26 14:30 UTC (permalink / raw)
  To: Peter Davis; +Cc: Phillip Lord, emacs-orgmode

That is a cool idea. Here is some code for data uris that worked on with
org-mode earlier this summer. You could definitely hack a filter that
embedded the image uri directly into the exported html.

http://kitchingroup.cheme.cmu.edu/blog/2015/05/09/Another-approach-to-embedding-org-source-in-html/

Peter Davis writes:

> phillip.lord@newcastle.ac.uk (Phillip Lord) writes:
>
>> data-uri's is probably what you want. There is no standard format for
>> zipping multiple HTML files together, while including images (or video's
>> or audio) directly into the HTML works reasonably well.
>>
>> I found a snippet to get ox-html to do this -- it would be a good
>> feature to add properly though!
>
> Thanks, Phillip. That sounds like an interesting possibility. I've never
> worked with data-uri's. Can you post or send that snippet? I don't seem
> to be finding it on my initial searches.
>
> Thanks,
> -pd

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 14:24   ` John Kitchin
@ 2015-06-26 14:35     ` Peter Davis
  2015-06-26 17:22     ` Peter Davis
  2015-06-26 21:51     ` Nick Dokos
  2 siblings, 0 replies; 18+ messages in thread
From: Peter Davis @ 2015-06-26 14:35 UTC (permalink / raw)
  To: emacs-orgmode

Thanks, John. I will take a closer look at both of these.

Cheers,
-pd

On 6/26/15 10:24 AM, John Kitchin wrote:
> I did something like this for org-files:
> https://github.com/jkitchin/jmax/blob/master/ox-archive.el
>
> You might use that as a starting point for html.
>
> Also, my blogofile code
> (https://github.com/jkitchin/jmax/blob/master/user/blogofile.el) does
> something like this to publish org to blogofile.
>
>
>
> Rasmus writes:
>
>> Peter Davis <pfd@pfdstudio.com> writes:
>>
>>> Is there any way to export HTML with all references images,
>>> etc. packaged in a ZIP file?
>> My guess is that at the moment your best bet is hacking some together with
>> ox-publish.  See org-publish-project-alist.
>>
>> Hope it helps,
>> Rasmus
>>
>> PS: On the list, we have talked about a .borg format that might serve for
>> similar situation but it's at an idea stage at the moment.
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 14:24   ` John Kitchin
  2015-06-26 14:35     ` Peter Davis
@ 2015-06-26 17:22     ` Peter Davis
  2015-06-26 18:09       ` John Kitchin
  2015-06-26 21:51     ` Nick Dokos
  2 siblings, 1 reply; 18+ messages in thread
From: Peter Davis @ 2015-06-26 17:22 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I did something like this for org-files:
> https://github.com/jkitchin/jmax/blob/master/ox-archive.el
>
> You might use that as a starting point for html.

I'm not lisp-savvy, but I've been experimenting with this. I get an
error:

Unknown "nil" backend: Aborting export

It seems to be coming from these lines:

      (let ((org-export-filter-link-functions '(ox-mrkup-filter-link)))
	(org-org-export-as-org)))

I'm not sure how or where backend is supposed to be defined.

Also, I guess it would take some tweaking to export to HTML and save
that in the ZIP, instead of the original org file.

Any hints welcome.

Thanks!
-pd

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 17:22     ` Peter Davis
@ 2015-06-26 18:09       ` John Kitchin
  2015-06-26 19:28         ` Peter Davis
  0 siblings, 1 reply; 18+ messages in thread
From: John Kitchin @ 2015-06-26 18:09 UTC (permalink / raw)
  To: Peter Davis; +Cc: emacs-orgmode

I am not sure. I have this in my init file:

(require 'ox-org)

maybe that is required for you too?

Peter Davis writes:

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> I did something like this for org-files:
>> https://github.com/jkitchin/jmax/blob/master/ox-archive.el
>>
>> You might use that as a starting point for html.
>
> I'm not lisp-savvy, but I've been experimenting with this. I get an
> error:
>
> Unknown "nil" backend: Aborting export
>
> It seems to be coming from these lines:
>
>       (let ((org-export-filter-link-functions '(ox-mrkup-filter-link)))
>       (org-org-export-as-org)))
>
> I'm not sure how or where backend is supposed to be defined.
>
> Also, I guess it would take some tweaking to export to HTML and save
> that in the ZIP, instead of the original org file.
>
> Any hints welcome.
>
> Thanks!
> -pd

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 18:09       ` John Kitchin
@ 2015-06-26 19:28         ` Peter Davis
  0 siblings, 0 replies; 18+ messages in thread
From: Peter Davis @ 2015-06-26 19:28 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode


Thanks, John. That didn't solve it for me. I'll keep digging when I get
a chance.

Thank you.

-pd


John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I am not sure. I have this in my init file:
>
> (require 'ox-org)
>
> maybe that is required for you too?
>
> Peter Davis writes:
>
>> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>
>>> I did something like this for org-files:
>>> https://github.com/jkitchin/jmax/blob/master/ox-archive.el
>>>
>>> You might use that as a starting point for html.
>>
>> I'm not lisp-savvy, but I've been experimenting with this. I get an
>> error:
>>
>> Unknown "nil" backend: Aborting export
>>
>> It seems to be coming from these lines:
>>
>>       (let ((org-export-filter-link-functions '(ox-mrkup-filter-link)))
>>       (org-org-export-as-org)))
>>
>> I'm not sure how or where backend is supposed to be defined.
>>
>> Also, I guess it would take some tweaking to export to HTML and save
>> that in the ZIP, instead of the original org file.
>>
>> Any hints welcome.
>>
>> Thanks!
>> -pd
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 14:24   ` John Kitchin
  2015-06-26 14:35     ` Peter Davis
  2015-06-26 17:22     ` Peter Davis
@ 2015-06-26 21:51     ` Nick Dokos
  2015-06-26 23:34       ` John Kitchin
  2 siblings, 1 reply; 18+ messages in thread
From: Nick Dokos @ 2015-06-26 21:51 UTC (permalink / raw)
  To: emacs-orgmode

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I did something like this for org-files:
> https://github.com/jkitchin/jmax/blob/master/ox-archive.el
>

I tried this on some arbitrary org file (not containing any references) and I got an error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  file-name-directory(nil)
  (let* ((temporary-file-directory (file-name-directory (buffer-file-name))) (tempname (make-temp-file "extract-bib")) (contents (buffer-string)) (cb (current-buffer)) basename texfile bibfile results) (find-file tempname) (insert contents) (setq basename (file-name-sans-extension (file-name-nondirectory buffer-file-name)) texfile (concat tempname ".tex") bibfile (concat tempname ".bib")) (save-excursion (goto-char (point-min)) (if (re-search-forward "^bibliography:" (point-max) (quote end)) nil (insert (format "\nbibliography:%s" (mapconcat (quote identity) reftex-default-bibliography ","))))) (save-buffer) (org-latex-export-to-latex) (find-file texfile) (reftex-parse-all) (reftex-create-bibtex-file bibfile) (save-buffer) (setq results (buffer-string)) (kill-buffer (concat basename ".bib")) (kill-buffer (concat basename ".tex")) (kill-buffer basename) (delete-file bibfile) (delete-file texfile) (delete-file tempname) (switch-to-buffer cb) (if (not (string= "" results)) (progn (save-excursion (goto-char (point-max)) (insert "\n\n") (org-insert-heading) (insert (format " Bibtex entries\n\n#+BEGIN_SRC text :tangle %s\n%s\n#+END_SRC" (concat (file-name-sans-extension ...) ".bib") results))))))
  org-ref-extract-bibtex-entries()
  (let* ((org-file (buffer-name)) (org-file-abs-path (buffer-file-name)) (base-name (file-name-sans-extension org-file)) (org-archive (if (string= zip-base-name "") (concat base-name "-" (format-time-string "%Y-%m-%d" (current-time))) zip-base-name)) (org-archive-zip (concat org-archive ".zip")) link-list) (if (file-exists-p org-archive-zip) (progn (delete-file org-archive-zip))) (if (file-exists-p org-archive) (progn (delete-directory org-archive t))) (make-directory org-archive t) (setq link-list (let ((parsetree (org-element-parse-buffer)) (counter 0)) (org-element-map parsetree (quote link) (function (lambda (link) (let* (... ... ... ... ... ... ... ...) (message ...) (cond ... ... ...))))))) (message (format "\n\nlink-list: %s\n\n" link-list)) (let ((counter 0)) (defalias (quote ox-mrkup-filter-link) (function (lambda (text back-end info) (message "handing link %s: %s\n" counter text) (let ((link ...)) (message "  %s replacement is %s\n" counter link) (if (not ...) (progn ... ...) (setq output ...)) (setq counter (+ counter 1)) output)))) (let ((org-export-filter-link-functions (quote (ox-mrkup-filter-link)))) (org-org-export-as-org))) (switch-to-buffer "*Org ORG Export*") (insert (format "# archived from %s on %s\n" org-file-abs-path (format-time-string "%Y-%m-%d" (current-time)))) (org-ref-extract-bibtex-entries) (write-file (expand-file-name org-file org-archive)) (shell-command (concat "zip -v -r " org-archive-zip " *")) (rename-file org-archive-zip (concat "../" org-archive ".zip")) (switch-to-buffer org-file) (delete-directory org-archive t) org-archive-zip)
  ox-archive-create-zip("foo")
...

I think there is a bug in ox-archive-create-zip:

--8<---------------cut here---------------start------------->8---
    ...
    (switch-to-buffer "*Org ORG Export*")
    (insert (format "# archived from %s on %s\n"
		    org-file-abs-path
		    (format-time-string "%Y-%m-%d" (current-time))))

    ;; add bibliography references if they exist. 
    (org-ref-extract-bibtex-entries)
    ...
--8<---------------cut here---------------end--------------->8---

because the first thing that org-ref-extract-bibtex-entries does is

--8<---------------cut here---------------start------------->8---
  (let* ((temporary-file-directory (file-name-directory (buffer-file-name)))
--8<---------------cut here---------------end--------------->8---

and (buffer-file-name) returns nil on the *Org ORG Export* buffer.
But since you obviously use this code successfully, I wonder why
you don't hit this.

Thanks for any help,
Nick

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 21:51     ` Nick Dokos
@ 2015-06-26 23:34       ` John Kitchin
  2015-06-27  4:52         ` Nick Dokos
  0 siblings, 1 reply; 18+ messages in thread
From: John Kitchin @ 2015-06-26 23:34 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

hm... maybe it has been a while since I ran that ;) I pushed some
changes that seem to have it working on a small test file.

This code is somewhat on the border of a filter/custom export. There are
probably links that will now work with it, I have not tested it super
thoroughly.

Notably, it does not preserve relative paths, but rather renames files
and images and replaces the links in the org-file with the new
names. It was too hard to figure out how to preserve the paths when I
wrote this originally.

Nick Dokos writes:

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> I did something like this for org-files:
>> https://github.com/jkitchin/jmax/blob/master/ox-archive.el
>>
>
> I tried this on some arbitrary org file (not containing any references) and I got an error:
>
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>   file-name-directory(nil)
>   (let* ((temporary-file-directory (file-name-directory (buffer-file-name))) (tempname (make-temp-file "extract-bib")) (contents (buffer-string)) (cb (current-buffer)) basename texfile bibfile results) (find-file tempname) (insert contents) (setq basename (file-name-sans-extension (file-name-nondirectory buffer-file-name)) texfile (concat tempname ".tex") bibfile (concat tempname ".bib")) (save-excursion (goto-char (point-min)) (if (re-search-forward "^bibliography:" (point-max) (quote end)) nil (insert (format "\nbibliography:%s" (mapconcat (quote identity) reftex-default-bibliography ","))))) (save-buffer) (org-latex-export-to-latex) (find-file texfile) (reftex-parse-all) (reftex-create-bibtex-file bibfile) (save-buffer) (setq results (buffer-string)) (kill-buffer (concat basename ".bib")) (kill-buffer (concat basename ".tex")) (kill-buffer basename) (delete-file bibfile) (delete-file texfile) (delete-file tempname) (switch-to-buffer cb) (if (not (string= "" results)) (progn (save-excursion (goto-char (point-max)) (insert "\n\n") (org-insert-heading) (insert (format " Bibtex entries\n\n#+BEGIN_SRC text :tangle %s\n%s\n#+END_SRC" (concat (file-name-sans-extension ...) ".bib") results))))))
>   org-ref-extract-bibtex-entries()
>   (let* ((org-file (buffer-name)) (org-file-abs-path (buffer-file-name)) (base-name (file-name-sans-extension org-file)) (org-archive (if (string= zip-base-name "") (concat base-name "-" (format-time-string "%Y-%m-%d" (current-time))) zip-base-name)) (org-archive-zip (concat org-archive ".zip")) link-list) (if (file-exists-p org-archive-zip) (progn (delete-file org-archive-zip))) (if (file-exists-p org-archive) (progn (delete-directory org-archive t))) (make-directory org-archive t) (setq link-list (let ((parsetree (org-element-parse-buffer)) (counter 0)) (org-element-map parsetree (quote link) (function (lambda (link) (let* (... ... ... ... ... ... ... ...) (message ...) (cond ... ... ...))))))) (message (format "\n\nlink-list: %s\n\n" link-list)) (let ((counter 0)) (defalias (quote ox-mrkup-filter-link) (function (lambda (text back-end info) (message "handing link %s: %s\n" counter text) (let ((link ...)) (message "  %s replacement is %s\n" counter link) (if (not ...) (progn ... ...) (setq output ...)) (setq counter (+ counter 1)) output)))) (let ((org-export-filter-link-functions (quote (ox-mrkup-filter-link)))) (org-org-export-as-org))) (switch-to-buffer "*Org ORG Export*") (insert (format "# archived from %s on %s\n" org-file-abs-path (format-time-string "%Y-%m-%d" (current-time)))) (org-ref-extract-bibtex-entries) (write-file (expand-file-name org-file org-archive)) (shell-command (concat "zip -v -r " org-archive-zip " *")) (rename-file org-archive-zip (concat "../" org-archive ".zip")) (switch-to-buffer org-file) (delete-directory org-archive t) org-archive-zip)
>   ox-archive-create-zip("foo")
> ...
>
> I think there is a bug in ox-archive-create-zip:
>
> --8<---------------cut here---------------start------------->8---
>     ...
>     (switch-to-buffer "*Org ORG Export*")
>     (insert (format "# archived from %s on %s\n"
>                   org-file-abs-path
>                   (format-time-string "%Y-%m-%d" (current-time))))
>
>     ;; add bibliography references if they exist.
>     (org-ref-extract-bibtex-entries)
>     ...
> --8<---------------cut here---------------end--------------->8---
>
> because the first thing that org-ref-extract-bibtex-entries does is
>
> --8<---------------cut here---------------start------------->8---
>   (let* ((temporary-file-directory (file-name-directory (buffer-file-name)))
> --8<---------------cut here---------------end--------------->8---
>
> and (buffer-file-name) returns nil on the *Org ORG Export* buffer.
> But since you obviously use this code successfully, I wonder why
> you don't hit this.
>
> Thanks for any help,
> Nick

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 23:34       ` John Kitchin
@ 2015-06-27  4:52         ` Nick Dokos
  0 siblings, 0 replies; 18+ messages in thread
From: Nick Dokos @ 2015-06-27  4:52 UTC (permalink / raw)
  To: emacs-orgmode

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> hm... maybe it has been a while since I ran that ;) I pushed some
> changes that seem to have it working on a small test file.
>

Yes, it does not fail any longer. Thanks!

> This code is somewhat on the border of a filter/custom export. There are
> probably links that will now work with it, I have not tested it super
> thoroughly.
>
> Notably, it does not preserve relative paths, but rather renames files
> and images and replaces the links in the org-file with the new
> names. It was too hard to figure out how to preserve the paths when I
> wrote this originally.
>

OK. I'm just kicking the tires for now.

> Nick Dokos writes:
>
>> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>
>>> I did something like this for org-files:
>>> https://github.com/jkitchin/jmax/blob/master/ox-archive.el
>>>
>>
>> I tried this on some arbitrary org file (not containing any references) and I got an error:
>>

-- 
Nick

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 13:10 HTML/images zipped? Peter Davis
  2015-06-26 13:15 ` Rasmus
  2015-06-26 13:44 ` Phillip Lord
@ 2015-06-29  8:47 ` Robert Klein
  2015-06-29 11:13   ` Rasmus
  2015-06-30  5:38 ` Vaidheeswaran C
  3 siblings, 1 reply; 18+ messages in thread
From: Robert Klein @ 2015-06-29  8:47 UTC (permalink / raw)
  To: Peter Davis; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 993 bytes --]

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 <pfd@pfdstudio.com> wrote:

> 
> Is there any way to export HTML with all references images,
> etc. packaged in a ZIP file?
> 
> Thank you.
> 
> -pd
> 
> 


[-- Attachment #2: ox-htmlzip.el --]
[-- Type: text/x-emacs-lisp, Size: 5432 bytes --]

;;; ox-htmlzip.el --- Zipped HTML Back-End for Org Export Engine

;; Copyright (C) 2015 Free Software Foundation, Inc.

;; Author: Robert Klein <roklein at roklein dot de>
;; 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 <http://www.gnu.org/licenses/>.

;;; 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.")

\f
;;; 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 \"<body>\" and \"</body>\" 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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-29  8:47 ` Robert Klein
@ 2015-06-29 11:13   ` Rasmus
  2015-06-30 20:05     ` Robert Klein
  0 siblings, 1 reply; 18+ messages in thread
From: Rasmus @ 2015-06-29 11:13 UTC (permalink / raw)
  To: emacs-orgmode

Hi Robert,

Robert Klein <roklein@roklein.de> writes:

> please find an experimental htmlzip exporter attached.

Cool!

I don't know if you indent to make this an extension to org or for this to
be a quick hack to solve a particular issue.

If the former: Shouldn't this rather be something that is configurable
from via a keyword in ox-html or more logically via ox-publish (which can
consist of several files)?  If so, you could store the list of files in
the info communication channel rather than org-htmlzip--image-list.

The command used for compression should be configurable.

Also, if the point is to produce an offline version, you should also
include scripts and css files.

Thanks,
Rasmus

-- 
A clever person solves a problem. A wise person avoids it

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-26 13:10 HTML/images zipped? Peter Davis
                   ` (2 preceding siblings ...)
  2015-06-29  8:47 ` Robert Klein
@ 2015-06-30  5:38 ` Vaidheeswaran C
  3 siblings, 0 replies; 18+ messages in thread
From: Vaidheeswaran C @ 2015-06-30  5:38 UTC (permalink / raw)
  To: emacs-orgmode

On Friday 26 June 2015 06:40 PM, Peter Davis wrote:
> Is there any way to export HTML with all references images,
> etc. packaged in a ZIP file?

This is EPUB format (more or less).

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: HTML/images zipped?
  2015-06-29 11:13   ` Rasmus
@ 2015-06-30 20:05     ` Robert Klein
  0 siblings, 0 replies; 18+ messages in thread
From: Robert Klein @ 2015-06-30 20:05 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

On Mon, 29 Jun 2015 13:13:19 +0200
Rasmus <rasmus@gmx.us> wrote:

Hi Rasmus,

> Hi Robert,
> 
> Robert Klein <roklein@roklein.de> writes:
> 
> > please find an experimental htmlzip exporter attached.
> 
> Cool!
> 
> I don't know if you indent to make this an extension to org or for
> this to be a quick hack to solve a particular issue.
> 

I thought about aiming for contrib, but if it turns out not to be too
invasive I'll probably ask for inclusion in ox-html.

> If the former: Shouldn't this rather be something that is configurable
> from via a keyword in ox-html or more logically via ox-publish (which
> can consist of several files)?  If so, you could store the list of
> files in the info communication channel rather than
> org-htmlzip--image-list.

Hmm, I think for individual files C-c C-e h a(rchive) and an option for
publishing (e.g. in org-publish-project-alist)


> The command used for compression should be configurable.
 Yes, per org-publish-project-alist and global at least, I think.
 Could be I'd need to `register' (e.g.
 org-export-archivers-alist) compressions commands in .emacs, so
 a #+OPTION doesn't get too complicated (I'd think something like
 `z:tgz' is acceptable, but e.g. `z:'("tar" "-jcvf") is not...

> 
> Also, if the point is to produce an offline version, you should also
> include scripts and css files.

Agreed.

I'll see how far I get in the next couple of days.

Thank you very much for your suggestions!

Best regards
Robert

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-06-30 20:05 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-26 13:10 HTML/images zipped? Peter Davis
2015-06-26 13:15 ` Rasmus
2015-06-26 14:05   ` Peter Davis
2015-06-26 14:24   ` John Kitchin
2015-06-26 14:35     ` Peter Davis
2015-06-26 17:22     ` Peter Davis
2015-06-26 18:09       ` John Kitchin
2015-06-26 19:28         ` Peter Davis
2015-06-26 21:51     ` Nick Dokos
2015-06-26 23:34       ` John Kitchin
2015-06-27  4:52         ` Nick Dokos
2015-06-26 13:44 ` Phillip Lord
2015-06-26 14:08   ` Peter Davis
2015-06-26 14:30     ` John Kitchin
2015-06-29  8:47 ` Robert Klein
2015-06-29 11:13   ` Rasmus
2015-06-30 20:05     ` Robert Klein
2015-06-30  5:38 ` Vaidheeswaran C

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.