Function: org--image-yank-media-handler

org--image-yank-media-handler is a byte-compiled function defined in org.el.gz.

Signature

(org--image-yank-media-handler MIMETYPE DATA)

Documentation

Save image DATA of mime-type MIMETYPE and insert link at point.

It is saved as per org-yank-image-save-method. The name for the image is prompted and the extension is automatically added to the end.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org--image-yank-media-handler (mimetype data)
  "Save image DATA of mime-type MIMETYPE and insert link at point.
It is saved as per `org-yank-image-save-method'.  The name for the
image is prompted and the extension is automatically added to the
end."
  (cl-assert (fboundp 'mailcap-mime-type-to-extension)) ; Emacs >=29
  (cl-assert (fboundp 'file-name-with-extension)) ; Emacs >=28
  (let* ((ext (symbol-name
               (with-no-warnings ; Suppress warning in Emacs <29
                 (mailcap-mime-type-to-extension mimetype))))
         (iname (funcall org-yank-image-file-name-function))
         (filename (with-no-warnings ; Suppress warning in Emacs <28
                     (file-name-with-extension iname ext)))
         (absname (expand-file-name
                   filename
                   (if (eq org-yank-image-save-method 'attach)
                       temporary-file-directory
                     org-yank-image-save-method)))
         link)
    (when (and (not (eq org-yank-image-save-method 'attach))
               (not (file-directory-p org-yank-image-save-method)))
      (make-directory org-yank-image-save-method t))
    ;; DATA is a raw image.  Tell Emacs to write it raw, without
    ;; trying to auto-detect the coding system.
    (let ((coding-system-for-write 'emacs-internal))
      (with-temp-file absname
        (insert data)))
    (if (null (eq org-yank-image-save-method 'attach))
        (setq link (org-link-make-string (concat "file:" (file-relative-name absname))))
      (require 'org-attach)
      (org-attach-attach absname nil 'mv)
      (setq link (org-link-make-string (concat "attachment:" filename))))
    (insert link)))