I need to export absoluted Image url in html in emacs org-mode file:
when i write the following code:
[[file:/images/a.jgp]]
export of html code is :
<img src="file:///images/a.jpg" >
but which i need is :
<img src="/images/a.jgp">
so how can i export what i wanted , instead of use #+BEGIN_HTML
tag ?
ps: my emacs config:
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 ))
To export your org file to a web page, type C-c C-e to start the exporter and then press h to select html and o to select open. A new web page should now open in your browser. Similarly, typing l and o in the exporter will convert the org file to latex and then compile it to produce a pdf and display that.
To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores. MY PROJECT is the title of the document, this can be anything. This will enable Org mode for this document, no matter what the file-ending is.
Org Mode (also: org-mode; /ˈɔːrɡ moʊd/) is a document editing, formatting, and organizing mode, designed for notes, planning, and authoring within the free software text editor Emacs.
Org mode is routinely used to build and manage complex workflows. It does this using an elegantly simple syntax that scales from basic markup to full LaTeX typesetting and from plain text notes to literate programs. Everything you need to get started is demonstrated in the example.
The way to do this is to register a new kind of link in org-mode, using org-add-link-type
. That lets you supply a custom export format.
org-add-link-type
requires a prefix, a "what happens when you click the link?" function, and an export function.
I use a prefix of img
, so my links look like [[img:logo.png][Logo]]
.
My image files are in ../images/
(relative to the .org files), and from the webserver they show up in /images/
. So for those settings, putting this in .emacs
provides the solution:
(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)
You'll probably need to amend the paths for your setup, but that's the recipe. As you'd expect, C-hforg-add-link-type
will give you the full gory details.
Oh, and for what it's worth, here's the code I'm using for inter-post links (like [[post:otherfile.org][Other File]]
). There's a little Jekyll magic in the output format, so watch the double-%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)
Another answer would be utilizing #+ATTR_HTML
, see the following:
#+ATTR_HTML: :src /images/a.png
[[file:./images/a.png]]
With that, you'll be able to use inline images and export the way you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With