如何直接在org文件中引用图片?
问题org发表博客时,复制了一个外部的图片,如何把图片链接放进org文件里呢?
如何直接在org文件中引用图片?
问题org发表博客时,复制了一个外部的图片,如何把图片链接放进org文件里呢?
org-download 可以,直接把图片拖进去就行。 mac 上我一般是直接复制图片,然后用 org-download-clipboard 就可以直接放在 org 文件中,Windows 这个方法似乎不能用。Windows 上我就用 org-download-image 方法,直接粘贴图片 URL 就会自动下载图片。
Also, we are about to have native support for DnD and yanking from clipboard. The patch is pending: [BUG] [PATCH] Add yank-media and DND handler [9.6.7 (9.6.7-g6eb773 @ /home/viz/lib/emacs/straight/build/org/)]
此外,我们还将原生支持 DnD 和从剪贴板中提取内容。 该补丁正在等待:[BUG] [PATCH] Add yank-media and DND handler [9.6.7 (9.6.7-g6eb773 @ /home/viz/lib/emacs/straight/build/org/)]
Thanks for your great work on org-mode.
Will this new feature works on Windows 10?
目前我还是用在别处拷贝来的函数,在 dired 中拷贝图片链接,然后粘贴到 org 文件中。期待 org-mode 直接支持从剪贴板中提取图片内容。
(defun dired-copy-images-links ()
"Works only in `dired-mode', put image links in `kill-ring'.
Ready to be yanked in some other `org-mode' file.
The links of marked image files using `file-name-base' as #+CAPTION.
If no file marked then do it on all images files of directory.
No file is moved nor copied anywhere.
This is intended to be used with `org-display-inline-images'."
(interactive)
(if (derived-mode-p 'dired-mode) ; if we are in dired-mode
(let* ((marked-files (dired-get-marked-files)) ; get marked file list
(number-marked-files ; store number of marked files
(string-to-number ; as a number
(dired-number-of-marked-files)))) ; for later reference
(when (= number-marked-files 0) ; if none marked then
(dired-toggle-marks) ; mark all files
(setq marked-files (dired-get-marked-files))) ; get marked file list
(message "Files marked for copy") ; info message
(dired-number-of-marked-files) ; marked files info
(kill-new "\n") ; start with a newline
(dolist (marked-file marked-files) ; walk the marked files list
(when (org-file-image-p marked-file) ; only on image files
(kill-append ; append image to kill-ring
(concat "#+CAPTION: " ; as caption,
(file-name-base marked-file) ; use file-name-base
"\n#+ATTR_ORG: :width 800" ; img width
"\n[[file:" marked-file "]]\n\n")
nil)))
(when (= number-marked-files 0) ; if none were marked then
(dired-toggle-marks))) ; unmark all
(message "Error: Does not work outside dired-mode") ; can't work not in dired-mode
(ding)))
It should, as it relies upon Emacs’ own DnD support. Although (1) we did not test on Windows, (2) there is no support of multiple files drop on Windows on the latest Emacs. Po Lu added it just a few days ago as a result of this patch discussion, (3) yanking from clipboard requires Emacs 29.
它应该如此,因为它依赖于 Emacs 自己的 DnD 支持。 虽然(1)我们没有在 Windows 上进行测试,(2)最新的 Emacs 上不支持 Windows 上的多个文件拖放。 Po Lu 几天前在这个补丁讨论的结果中添加了它,(3) 从剪贴板中提取需要 Emacs 29。
DND support will be a part of Org 9.7 release (to be released today).
I believe that Org 9.7 will also become a part of Emacs 30, but the time is tight - Emacs is about to cut its emacs-30 branch and enter feature freeze.
Good news. Looking forward to the Org 9.7.
Hi @yantar92 ,
With latest Emacs 30, M-x yank-media
works as expected for pasting images from clipboard in org-mode. But it doesn’t works on Windows platform, do you known how to make it works on Windows? Or I need to install extra dependency?
Try M-x yank-media-types and check the completion. If it returns nothing, I am afraid that Windows is not yet supported. Then, feel free to report a bug in Emacs.
尝试执行 M-x yank-media-types 并检查补全。如果没有返回结果,恐怕 Windows 尚不受支持。随后,可以随时在 Emacs 中报告 Bug。
Thanks! Looks like it havn’t support Windows system recently.
I have reported a bug in Emacs:
https://lists.gnu.org/archive/html/bug-gnu-emacs/2024-07/msg00073.html
Meanwhile, emacs/org-mode.git - Emacs Org mode (mention that Windows is not yet supported in the NEWS)
yank-media 在 Emacs 31 开始支持 Windows了,看来 org-mode 应该也可以用了。
Add support for ‘yank-media’ on MS-Windows
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=8e7f5f97db647ce6e9606364dc15d8bbd7ef6016
哇, 31 还挺多新功能的, 终端child-frame, 彩色字体(符号)