unit test faulty generated image drag n drop

This commit is contained in:
Willem van den Ende
2026-07-01 22:26:27 +02:00
parent 70c9416270
commit 1e5a4dfc48
2 changed files with 15 additions and 6 deletions
+1 -5
View File
@@ -4,11 +4,7 @@
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(safe-local-variable-values
'((eval setq-local org-roam-db-location
(expand-file-name "org-roam.db" org-roam-directory))
(eval setq-local org-roam-directory
(expand-file-name
(locate-dominating-file default-directory ".dir-locals.el"))))))
'((qwan-markdown-attachment-dir . "app/priv/static/images/blog/2026"))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
+14 -1
View File
@@ -22,6 +22,14 @@
"Directory for dropped attachments, relative to the markdown file.
Set this buffer-locally (e.g. via .dir-locals.el) to customise per project.")
(defun is-image (filename)
(let* ((mime-type (when (fboundp 'mailcap-file-name-to-mime-type)
(mailcap-file-name-to-mime-type filename))))
(and mime-type (string-prefix-p "image/" mime-type))))
(ert-deftest detect-image ()
(should (is-image "bla.png"))
(should-not (is-image "book.md")))
;;;###autoload
(defun qwan-markdown-dnd-handler (uri action)
@@ -33,6 +41,9 @@ other files a regular `[]()' link.
ACTION is ignored (always copies)."
(ignore action)
;; not sure what ignore action is. the copy does not actually happen
;; is-image is not a function (mime-type is only used for is-image)
;; not sure how 'unless' works here
(let* ((filename (dnd-get-local-file-name uri 'must-exist))
(mime-type (when (fboundp 'mailcap-file-name-to-mime-type)
(mailcap-file-name-to-mime-type filename)))
@@ -50,6 +61,7 @@ ACTION is ignored (always copies)."
(make-directory dest-dir t))
;; Handle name conflicts by appending a timestamp
(when (file-exists-p dest-file)
(message "Destination file %s already exists." dest-file)
(setq dest-file
(expand-file-name
(concat (file-name-base dest-name)
@@ -57,6 +69,7 @@ ACTION is ignored (always copies)."
"." (file-name-extension dest-name))
dest-dir)))
;; Copy the file
(message "copying %s to %s." filename dest-file)
(copy-file filename dest-file)
;; Insert the appropriate markdown link
(let ((relative-path (file-relative-name dest-file buffer-dir)))
@@ -80,6 +93,6 @@ Add this to `markdown-mode-hook'."
;;;###autoload
(add-hook 'markdown-mode-hook #'qwan-markdown-setup-dnd)
(add-hook 'gfm-mode-hook #'qwan-markdown-setup-dnd)
(add-hook 'gfm-mode-hook #'qwan-markdown-setup-dnd) ;; what is gfm-mode-hook ?
;;; qwan-markdown-dnd.el ends here