unit test faulty generated image drag n drop
This commit is contained in:
@@ -4,11 +4,7 @@
|
|||||||
;; Your init file should contain only one such instance.
|
;; Your init file should contain only one such instance.
|
||||||
;; If there is more than one, they won't work right.
|
;; If there is more than one, they won't work right.
|
||||||
'(safe-local-variable-values
|
'(safe-local-variable-values
|
||||||
'((eval setq-local org-roam-db-location
|
'((qwan-markdown-attachment-dir . "app/priv/static/images/blog/2026"))))
|
||||||
(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"))))))
|
|
||||||
(custom-set-faces
|
(custom-set-faces
|
||||||
;; custom-set-faces was added by Custom.
|
;; custom-set-faces was added by Custom.
|
||||||
;; If you edit it by hand, you could mess it up, so be careful.
|
;; If you edit it by hand, you could mess it up, so be careful.
|
||||||
|
|||||||
@@ -22,6 +22,14 @@
|
|||||||
"Directory for dropped attachments, relative to the markdown file.
|
"Directory for dropped attachments, relative to the markdown file.
|
||||||
Set this buffer-locally (e.g. via .dir-locals.el) to customise per project.")
|
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
|
;;;###autoload
|
||||||
(defun qwan-markdown-dnd-handler (uri action)
|
(defun qwan-markdown-dnd-handler (uri action)
|
||||||
@@ -33,6 +41,9 @@ other files a regular `[]()' link.
|
|||||||
|
|
||||||
ACTION is ignored (always copies)."
|
ACTION is ignored (always copies)."
|
||||||
(ignore action)
|
(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))
|
(let* ((filename (dnd-get-local-file-name uri 'must-exist))
|
||||||
(mime-type (when (fboundp 'mailcap-file-name-to-mime-type)
|
(mime-type (when (fboundp 'mailcap-file-name-to-mime-type)
|
||||||
(mailcap-file-name-to-mime-type filename)))
|
(mailcap-file-name-to-mime-type filename)))
|
||||||
@@ -50,6 +61,7 @@ ACTION is ignored (always copies)."
|
|||||||
(make-directory dest-dir t))
|
(make-directory dest-dir t))
|
||||||
;; Handle name conflicts by appending a timestamp
|
;; Handle name conflicts by appending a timestamp
|
||||||
(when (file-exists-p dest-file)
|
(when (file-exists-p dest-file)
|
||||||
|
(message "Destination file %s already exists." dest-file)
|
||||||
(setq dest-file
|
(setq dest-file
|
||||||
(expand-file-name
|
(expand-file-name
|
||||||
(concat (file-name-base dest-name)
|
(concat (file-name-base dest-name)
|
||||||
@@ -57,6 +69,7 @@ ACTION is ignored (always copies)."
|
|||||||
"." (file-name-extension dest-name))
|
"." (file-name-extension dest-name))
|
||||||
dest-dir)))
|
dest-dir)))
|
||||||
;; Copy the file
|
;; Copy the file
|
||||||
|
(message "copying %s to %s." filename dest-file)
|
||||||
(copy-file filename dest-file)
|
(copy-file filename dest-file)
|
||||||
;; Insert the appropriate markdown link
|
;; Insert the appropriate markdown link
|
||||||
(let ((relative-path (file-relative-name dest-file buffer-dir)))
|
(let ((relative-path (file-relative-name dest-file buffer-dir)))
|
||||||
@@ -80,6 +93,6 @@ Add this to `markdown-mode-hook'."
|
|||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(add-hook 'markdown-mode-hook #'qwan-markdown-setup-dnd)
|
(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
|
;;; qwan-markdown-dnd.el ends here
|
||||||
|
|||||||
Reference in New Issue
Block a user