如何在Org文件中插入图片

如何直接在org文件中引用图片?

问题org发表博客时,复制了一个外部的图片,如何把图片链接放进org文件里呢?

2 个赞

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/)]

3 个赞

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。

2 个赞