gpt4 book ai didi

emacs - 如何组织模式导出html的图像绝对路径?

转载 作者:行者123 更新时间:2023-12-04 17:37:10 25 4
gpt4 key购买 nike

我需要在 emacs 组织模式文件中的 html 中导出绝对图像 url:

当我编写以下代码时:

[[file:/images/a.jgp]]

html代码的导出是:
<img src="file:///images/a.jpg" >

但我需要的是:
<img src="/images/a.jgp">

那么我如何导出我想要的,而不是使用 #+BEGIN_HTML标签 ?

ps:我的emacs配置:
 16 ;; org-mode project define
17 (setq org-publish-project-alist
18 '(
19 ("org-blog-content"
20 ;; Path to your org files.
21 :base-directory "~/ChinaXing.org/org/"
22 :base-extension "org"
23
24 ;; Path to your jekyll project.
25 :publishing-directory "~/ChinaXing.org/jekyll/"
26 :recursive t
27 :publishing-function org-publish-org-to-html
28 :headline-levels 4
29 :html-extension "html"
30 :table-of-contents t
31 :body-only t ;; Only export section between <body></body>
32 )
33
34 ("org-blog-static"
35 :base-directory "~/ChinaXing.org/org/"
36 :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|php\\|svg"
37 :publishing-directory "~/ChinaXing.org/jekyll/"
38 :recursive t
39 :publishing-function org-publish-attachment)
40 ("blog" :components ("org-blog-content" "org-blog-static"))
41 ))

最佳答案

这样做的方法是在组织模式下注册一种新的链接,使用 org-add-link-type .这使您可以提供自定义导出格式。
org-add-link-type需要一个前缀,一个“当你点击链接时会发生什么?”函数和导出函数。

我使用前缀 img ,所以我的链接看起来像 [[img:logo.png][Logo]] .
我的图片文件在 ../images/ (相对于 .org 文件),以及来自网络服务器的它们出现在 /images/ .所以对于这些设置,把它放在 .emacs 中提供了解决方案:

(defun org-custom-link-img-follow (path)
(org-open-file-with-emacs
(format "../images/%s" path)))

(defun org-custom-link-img-export (path desc format)
(cond
((eq format 'html)
(format "<img src=\"/images/%s\" alt=\"%s\"/>" path desc))))

(org-add-link-type "img" 'org-custom-link-img-follow 'org-custom-link-img-export)

您可能需要修改设置的路径,但这就是秘诀。如您所料,C-hf org-add-link-type会给你完整的血腥细节。

哦,对于它的值(value),这是我用于帖子间链接的代码(如 [[post:otherfile.org][Other File]] )。输出格式中有一点 Jekyll 魔法,所以请注意双%s。
(defun org-custom-link-post-follow (path)
(org-open-file-with-emacs path))

(defun org-custom-link-post-export (path desc format)
(cond
((eq format 'html)
(format "<a href=\"{%% post_url %s %%}\">%s</a>" path desc))))

(org-add-link-type "post" 'org-custom-link-post-follow 'org-custom-link-post-export)

关于emacs - 如何组织模式导出html的图像绝对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14684263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com