lang/org: fix attachments getting double-url-encoded when exported

This commit is contained in:
Henrik Lissner 2018-03-22 08:14:03 -04:00
parent 318f51cfff
commit ae031928af
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -83,21 +83,22 @@ the cursor."
(unless (eq major-mode 'org-mode)
(user-error "Not in an org buffer"))
(require 'org-download)
(condition-case ex
(cond ((string-match-p "^data:image/png;base64," uri)
(org-download-dnd-base64 uri nil))
((image-type-from-file-name uri)
(org-download-image uri))
(t
(let ((new-path (expand-file-name (org-download--fullname uri))))
;; Download the file
(if (string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri)
(url-copy-file uri new-path)
(copy-file uri new-path))
;; insert the link
(org-download-insert-link uri new-path))))
(error
(user-error "Failed to attach file: %s" (error-message-string ex)))))
(let ((raw-uri (url-unhex-string uri)))
(condition-case ex
(cond ((string-match-p "^data:image/png;base64," uri)
(org-download-dnd-base64 uri nil))
((image-type-from-file-name raw-uri)
(org-download-image raw-uri))
(t
(let ((new-path (expand-file-name (org-download--fullname raw-uri))))
;; Download the file
(if (string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri)
(url-copy-file raw-uri new-path)
(copy-file uri new-path))
;; insert the link
(org-download-insert-link raw-uri new-path))))
(error
(user-error "Failed to attach file: %s" (error-message-string ex))))))
;;;###autoload
(defun +org-attach-download-dnd (uri action)