From 1e5a4dfc48d5a1005f46d43c8f5c9ad33f923050 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Wed, 1 Jul 2026 22:26:27 +0200 Subject: [PATCH] unit test faulty generated image drag n drop --- custom.el | 6 +----- qwan/qwan-markdown-dnd.el | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/custom.el b/custom.el index ee57c68..43edb8e 100644 --- a/custom.el +++ b/custom.el @@ -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. diff --git a/qwan/qwan-markdown-dnd.el b/qwan/qwan-markdown-dnd.el index a8d9329..8a26fdd 100644 --- a/qwan/qwan-markdown-dnd.el +++ b/qwan/qwan-markdown-dnd.el @@ -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