Skip to content

Commit

Permalink
Implement yank-media handler
Browse files Browse the repository at this point in the history
  • Loading branch information
syohex committed Oct 25, 2023
1 parent 2a0556c commit b2d9989
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
(declare-function project-roots "project")
(declare-function sh-set-shell "sh-script")

(when (version< "29" emacs-version)
(declare-function yank-media-handler "yank-media"))


;;; Constants =================================================================

Expand Down Expand Up @@ -9829,6 +9832,17 @@ rows and columns and the column alignment."
(markdown--substitute-command-keys
"\\[markdown-toggle-markup-hiding]"))))))

(defun markdown--image-media-handler (mimetype data)
(let* ((ext (symbol-name (mailcap-mime-type-to-extension mimetype)))
(filename (read-string "Insert filename for image: "))
(filepath (file-name-with-extension filename ext))
(dir (file-name-directory filepath)))
(when (and dir (not (file-directory-p dir)))
(make-directory dir t))
(with-temp-file filepath
(insert data))
(markdown-insert-inline-image "Alt Text" filepath)))


;;; Mode Definition ==========================================================

Expand Down Expand Up @@ -9957,6 +9971,10 @@ rows and columns and the column alignment."
(add-hook 'electric-quote-inhibit-functions
#'markdown--inhibit-electric-quote nil :local)

;; media handler
(when (version< "29" emacs-version)
(yank-media-handler "image/.*" #'markdown--image-media-handler))

;; Make checkboxes buttons
(when markdown-make-gfm-checkboxes-buttons
(markdown-make-gfm-checkboxes-buttons (point-min) (point-max))
Expand Down

0 comments on commit b2d9989

Please sign in to comment.