-;; Time-stamp: <2015-02-27 16:17:39 kmodi>
+;; Time-stamp: <2015-02-27 17:39:43 kmodi>
 
 ;; http://stackoverflow.com/q/28697108/1219634
 

(add-hook 'org-export-before-processing-hook #'modi/org-include-img-from-archive)

(defun modi/org-include-img-from-archive (&rest ignore)
  "Extract image files from the archive files. Only .zip files are supported
as of now.

Only looks at #HEADER: lines that have \":extractfromarchive t\".
This function does nothing if not in org-mode, so you can safely

;;   #+TITLE: Image from archive
;;   #+STARTUP: inlineimages
;;
;;   #+NAME: fig:image
;;   #+HEADER: :extractfromarchive t
;;   # The below caption line is optional
;;   #+CAPTION: My image image.png inside ./zippedimg.zip
;;   [[./zippedimg_zip/image.png]]

;; In the above example, the user has `zippedimg.zip' file containing
;; `image.png'. But when specifying the image path it is specified as
;; `./zippedimg_zip/image.png'; note that the . is replaced with an _
;; in the zip file name.

;; The reason is that a `FILE.EXT' archive is extracted to `FILE_EXT' folder
;; as you can't have a file and a folder with the exact same name in the same
;; folder.

;; Execute the `modi/org-include-img-from-archive' function just before saving the file
(add-hook 'before-save-hook #'modi/org-include-img-from-archive)
