org-mime: Fix LaTeX image bug in org-mime-org-buffer-htmlize

* contrib/lisp/org-mime.el (org-mime-replace-images): Change signature.
Always use temporary directory to create LaTeX images.
(org-mime-htmlize):
(org-mime-compose): Apply signature change above.

When exporting an org buffer with a LaTeX snippet including the Org
option "tex: dvipng" the images were always created in "/tmp/ltxpng/",
but the reported link in the htmlized buffer was the local "./ltxpng"
folder; so, unless the org file to htmlize was actually in "/tmp", the
user got an error saying that the image could not be found.

This was caused by the two different ways in which the function
`org-mime-replace-images' is used inside of
`org-mime-org-buffer-htmlize' and `org-mime-htmlize.'

To correct the problem, the function org-mime-replace-images doesn't
take anymore the current-file parameter (that was only used to get its
directory) and instead always creates a temporary directory using
temporary-file-directory.
This commit is contained in:
meditans 2016-06-10 23:32:05 +02:00 committed by Nicolas Goaziou
parent f364d55e2e
commit 504ffefcd5
1 changed files with 4 additions and 6 deletions

View File

@ -173,7 +173,7 @@ and images in a multipart/related part."
"--" "}-<<alternative>>\n"))
('vm "?")))
(defun org-mime-replace-images (str current-file)
(defun org-mime-replace-images (str)
"Replace images in html files with cid links."
(let (html-images)
(cons
@ -185,7 +185,7 @@ and images in a multipart/related part."
(let* ((url (and (string-match "src=\"\\([^\"]+\\)\"" text)
(match-string 1 text)))
(path (expand-file-name
url (file-name-directory current-file)))
url temporary-file-directory))
(ext (file-name-extension path))
(id (replace-regexp-in-string "[\/\\\\]" "_" path)))
(add-to-list 'html-images
@ -212,8 +212,6 @@ otherwise export the entire body."
(point-max)))
(raw-body (concat org-mime-default-header
(buffer-substring html-start html-end)))
(tmp-file (make-temp-name (expand-file-name
"mail" temporary-file-directory)))
(body (org-export-string-as raw-body 'org t))
;; because we probably don't want to export a huge style file
(org-export-htmlize-output-type 'inline-css)
@ -224,7 +222,7 @@ otherwise export the entire body."
;; to hold attachments for inline html images
(html-and-images
(org-mime-replace-images
(org-export-string-as raw-body 'html t) tmp-file))
(org-export-string-as raw-body 'html t)))
(html-images (unless arg (cdr html-and-images)))
(html (org-mime-apply-html-hook
(if arg
@ -317,7 +315,7 @@ otherwise export the entire body."
(org-export-htmlize-output-type 'inline-css)
(html-and-images
(org-mime-replace-images
(org-export-string-as (funcall bhook body 'html) 'html t) file))
(org-export-string-as (funcall bhook body 'html) 'html t)))
(images (cdr html-and-images))
(html (org-mime-apply-html-hook (car html-and-images))))
(insert (org-mime-multipart