@@ -862,6 +862,18 @@ EXT is used as the extension."
862862
863863(defvar org-image-actual-width )
864864
865+ (defun jupyter-org--add-image-ext-maybe (file &optional ext )
866+ " Return a file name for FILE with EXT.
867+ If FILE is an image file with a specified extension, return FILE.
868+ If FILE is an image file without a specified extension and EXT is
869+ non-nil, return FILE with EXT as the extension. Otherwise, return
870+ FILE."
871+ (cond
872+ ((null file) file)
873+ ((image-type-from-file-name file) file)
874+ ((not (null ext)) (concat file " ." ext))
875+ (t file)))
876+
865877(defun jupyter-org--image-result (mime content params &optional b64-encoded )
866878 " Return an org-element suitable for inserting an image.
867879MIME is the image mimetype, CONTENT is a property list
@@ -886,14 +898,15 @@ org-element will have an ATTR_ORG affiliated keyword containing
886898the width or height of the image. When there is no :width or
887899:height, an ATTR_ORG keyword containing the true size of the
888900image may still be added, see `jupyter-org-adjust-image-size' ."
889- (let* ((overwrite (not (null (alist-get :file params))))
890- (file (or (alist-get :file params)
901+ (let* ((file-ext (cl-case mime
902+ (:image/png " png" )
903+ (:image/jpeg " jpg" )
904+ (:image/svg+xml " svg" )))
905+ (overwrite (not (null (alist-get :file params))))
906+ (file (or (jupyter-org--add-image-ext-maybe (alist-get :file params) file-ext)
891907 (jupyter-org-image-file-name
892908 (plist-get content :data )
893- (cl-case mime
894- (:image/png " png" )
895- (:image/jpeg " jpg" )
896- (:image/svg+xml " svg" ))))))
909+ file-ext))))
897910 (when (or overwrite (not (file-exists-p file)))
898911 (let ((buffer-file-coding-system
899912 (if b64-encoded 'binary
0 commit comments