How can I prevent Org from exporting [[/][site root]]
as <a href="file:///">site root</a>
?
OK, since I didn't find a ready-made one, I decided to roll my own. This doesn't seem to be difficult at all, so here goes:
(defun wvxvw/export-rel-url (path desc format)
(cl-case format
(html (format "<a href=\"%s\">%s</a>" path (or desc path)))
(latex (format "\href{%s}{%s}" path (or desc path)))
(otherwise path)))
(org-add-link-type "rel" 'browse-url 'wvxvw/export-rel-url)
Usage example: [[rel:./foo/bar][foo bar]]
translates into HTML: <a href="./foo/bar">foo bar</a>
.
The most important part is the org-add-link-type
- this allows to specify the way to export the link. This code isn't universal, since it doesn't support even all the back-ends enabled by Org by default, but it should be obvious how to add more.
Starting with Orgmode 9.0 the function org-add-link-type
is deprecated. One should use org-link-set-parameters
instead.
There follows the equivalent Elisp code for Orgmode 9.0. Note that the only change is the replacement of org-add-link-type
with org-link-set-parameters
. The function wvxvw/export-rel-url
is unchanged. It is only cited here to ease copy-paste.
(defun wvxvw/export-rel-url (path desc format)
(cl-case format
(html (format "<a href=\"%s\">%s</a>" path (or desc path)))
(latex (format "\href{%s}{%s}" path (or desc path)))
(otherwise path)))
(eval-after-load "org"
'(org-link-set-parameters "rel" :follow #'browse-url :export #'wvxvw/export-rel-url))
/
. – wvxvw Mar 4 '15 at 13:57/
is not a relative path. Relative paths don't start with a slash. – nanny Mar 4 '15 at 13:59