1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-23 07:18:53 +00:00

ox: Implement `org-export-file-uri'

* lisp/ox.el (org-export-file-uri): New function.
* testing/lisp/test-ox.el (test-org-export/file-uri): New test.
This commit is contained in:
Nicolas Goaziou 2015-04-20 12:36:47 +02:00
parent 0ab15904ec
commit f85a961c23
2 changed files with 25 additions and 0 deletions

View File

@ -3913,6 +3913,9 @@ meant to be translated with `org-export-data' or alike."
;; `org-export-resolve-coderef' associates a reference to a line
;; number in the element it belongs, or returns the reference itself
;; when the element isn't numbered.
;;
;; `org-export-file-uri' expands a filename as stored in :path value
;; of a "file" link into a file URI.
(defun org-export-custom-protocol-maybe (link desc backend)
"Try exporting LINK with a dedicated function.
@ -4128,6 +4131,15 @@ has type \"radio\"."
radio))
info 'first-match)))
(defun org-export-file-uri (filename)
"Return file URI associated to FILENAME."
(if (not (file-name-absolute-p filename)) filename
(concat "file:/"
(and (not (org-file-remote-p filename)) "/")
(if (org-string-match-p "\\`~" filename)
(expand-file-name filename)
filename))))
;;;; For References
;;

View File

@ -2657,6 +2657,19 @@ Another text. (ref:text)
(org-element-map tree 'link
(lambda (link) (org-export-resolve-radio-link link info)) info t)))))
(ert-deftest test-org-export/file-uri ()
"Test `org-export-file-uri' specifications."
;; Preserve relative filenames.
(should (equal "relative.org" (org-export-file-uri "relative.org")))
;; Local files start with "file:///"
(should (equal "file:///local.org" (org-export-file-uri "/local.org")))
;; Remote files start with "file://"
(should (equal "file://myself@some.where:papers/last.pdf"
(org-export-file-uri "/myself@some.where:papers/last.pdf")))
;; Expand filename starting with "~".
(should (equal (org-export-file-uri "~/file.org")
(concat "file://" (expand-file-name "~/file.org")))))
;;; Src-block and example-block