Chi*_*ing 5 emacs elisp org-mode
我需要在emacs org-mode文件中导出html中的absoluted Image url:
当我写下面的代码:
[[file:/images/a.jgp]]
Run Code Online (Sandbox Code Playgroud)
导出的HTML代码是:
<img src="file:///images/a.jpg" >
Run Code Online (Sandbox Code Playgroud)
但我需要的是:
<img src="/images/a.jgp">
Run Code Online (Sandbox Code Playgroud)
那我怎么能导出我想要的东西,而不是使用#+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 ))
Run Code Online (Sandbox Code Playgroud)
这样做的方法是使用在org-mode中注册一种新类型的链接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)
Run Code Online (Sandbox Code Playgroud)
您可能需要修改设置的路径,但这是配方.正如您所期望的那样,C-hforg-add-link-type
将为您提供完整的血腥细节.
哦,为了它的价值,这里是我用于帖子间链接的代码(比如[[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)
Run Code Online (Sandbox Code Playgroud)