如何在 emacs 中导出的 HTML 中集成图像(通过本地路径设置)?
How to integrate an image (set via local path) in the exported HTML in emacs?
我想导出一个 HTML 文件,其中包含一些图像(通过本地路径添加)以显示在我的计算机之外。如何 integrate/embed/burn 文件中的图像供 public 查看?
我可以在 R Markdown 上成功做到这一点,但无法在 emacs 上完成,因为我才刚刚开始使用它。
这是我输入的内容:
#+CAPTION: I-V curve for a diode
#+NAME: fig:diode_1
#+attr_html: :width 250px
[[C:\Users\Documents\thres.png]]
我希望将本地图像永久导出到最终的 HTML 文档中。
将此代码复制到 *scratch* 缓冲区并 C-M-x
它。然后像往常一样将 .org 文件导出到 html。
(defun org-html--format-image (source attributes info)
(format "<img src=\"data:image/%s;base64,%s\"%s />"
(or (file-name-extension source) "")
(base64-encode-string
(with-temp-buffer
(insert-file-contents-literally source)
(buffer-string)))
(file-name-nondirectory source)))
它通过 base64 编码将图像直接放入 html 文件中。
我想导出一个 HTML 文件,其中包含一些图像(通过本地路径添加)以显示在我的计算机之外。如何 integrate/embed/burn 文件中的图像供 public 查看?
我可以在 R Markdown 上成功做到这一点,但无法在 emacs 上完成,因为我才刚刚开始使用它。
这是我输入的内容:
#+CAPTION: I-V curve for a diode
#+NAME: fig:diode_1
#+attr_html: :width 250px
[[C:\Users\Documents\thres.png]]
我希望将本地图像永久导出到最终的 HTML 文档中。
将此代码复制到 *scratch* 缓冲区并 C-M-x
它。然后像往常一样将 .org 文件导出到 html。
(defun org-html--format-image (source attributes info)
(format "<img src=\"data:image/%s;base64,%s\"%s />"
(or (file-name-extension source) "")
(base64-encode-string
(with-temp-buffer
(insert-file-contents-literally source)
(buffer-string)))
(file-name-nondirectory source)))
它通过 base64 编码将图像直接放入 html 文件中。