diff --git a/contrib/lisp/ox-deck.el b/contrib/lisp/ox-deck.el index ea2d8fed0..0ebde41fa 100644 --- a/contrib/lisp/ox-deck.el +++ b/contrib/lisp/ox-deck.el @@ -378,7 +378,7 @@ the \"slide\" class will be added to the to the list element, (defun org-deck-link (link desc info) (replace-regexp-in-string "href=\"#" "href=\"#outline-container-" - (org-html-link link desc info))) + (org-export-with-backend 'html link desc info))) (defun org-deck-template (contents info) "Return complete document string after HTML conversion. diff --git a/contrib/lisp/ox-groff.el b/contrib/lisp/ox-groff.el index 7b110a1c4..7974051c0 100644 --- a/contrib/lisp/ox-groff.el +++ b/contrib/lisp/ox-groff.el @@ -1251,13 +1251,10 @@ INFO is a plist holding contextual information. See (imagep (org-export-inline-image-p link org-groff-inline-image-rules)) (path (cond - ((member type '("http" "https" "ftp")) - (concat type "://" raw-path)) - ((string= type "mailto") (concat type ":" raw-path)) - ((string= type "file") - (if (file-name-absolute-p raw-path) - (concat "file://" (expand-file-name raw-path)) - (concat "file://" raw-path))) + ((member type '("http" "https" "ftp" "mailto")) + (concat type ":" raw-path)) + ((and (string= type "file") (file-name-absolute-p raw-path)) + (concat "file://" raw-path)) (t raw-path))) protocol) (cond diff --git a/lisp/org-element.el b/lisp/org-element.el index 13837e9e7..29a90be41 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -3002,18 +3002,20 @@ Assume point is at the beginning of the link." (save-excursion (setq post-blank (progn (goto-char link-end) (skip-chars-forward " \t")) end (point)) - ;; Extract search option and opening application out of - ;; "file"-type links. + ;; Special "file" type link processing. (when (member type org-element-link-type-is-file) - ;; Application. + ;; Extract opening application and search option. (cond ((string-match "^file\\+\\(.*\\)$" type) (setq application (match-string 1 type))) ((not (string-match "^file" type)) (setq application type))) - ;; Extract search option from PATH. - (when (string-match "::\\(.*\\)$" path) + (when (string-match "::\\(.*\\)\\'" path) (setq search-option (match-string 1 path) path (replace-match "" nil nil path))) + ;; Normalize URI. + (when (and (not (org-string-match-p "\\`//" path)) + (file-name-absolute-p path)) + (setq path (concat "//" (expand-file-name path)))) ;; Make sure TYPE always reports "file". (setq type "file")) (list 'link diff --git a/lisp/org.el b/lisp/org.el index 7cd96eb39..e245d6d4b 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5669,54 +5669,55 @@ stacked delimiters is N. Escaping delimiters is not possible." (defun org-make-link-regexps () "Update the link regular expressions. This should be called after the variable `org-link-types' has changed." - (setq org-link-types-re - (concat "\\`" (regexp-opt org-link-types t) ":\\(?://\\)") - org-link-re-with-space - (concat "?") - org-link-re-with-space2 - (concat "?") - org-link-re-with-space3 - (concat "") - org-plain-link-re - (concat - "\\<" (regexp-opt org-link-types t) ":\\(?://\\)?" - (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)")) - ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)") - org-bracket-link-regexp - "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]" - org-bracket-link-analytic-regexp - (concat - "\\[\\[" - "\\(" (regexp-opt org-link-types t) ":\\(?://\\)?\\)?" - "\\([^]]+\\)" - "\\]" - "\\(\\[" "\\([^]]+\\)" "\\]\\)?" - "\\]") - org-bracket-link-analytic-regexp++ - (concat - "\\[\\[" - "\\(" (regexp-opt (cons "coderef" org-link-types) t) ":\\(?://\\)?\\)?" - "\\([^]]+\\)" - "\\]" - "\\(\\[" "\\([^]]+\\)" "\\]\\)?" - "\\]") - org-any-link-re - (concat "\\(" org-bracket-link-regexp "\\)\\|\\(" - org-angle-link-re "\\)\\|\\(" - org-plain-link-re "\\)"))) + (let ((types-re (regexp-opt org-link-types t))) + (setq org-link-types-re + (concat "\\`" types-re ":") + org-link-re-with-space + (concat "?") + org-link-re-with-space2 + (concat "?") + org-link-re-with-space3 + (concat "") + org-plain-link-re + (concat + "\\<" types-re ":" + (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)")) + ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)") + org-bracket-link-regexp + "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]" + org-bracket-link-analytic-regexp + (concat + "\\[\\[" + "\\(" types-re ":\\)?" + "\\([^]]+\\)" + "\\]" + "\\(\\[" "\\([^]]+\\)" "\\]\\)?" + "\\]") + org-bracket-link-analytic-regexp++ + (concat + "\\[\\[" + "\\(" (regexp-opt (cons "coderef" org-link-types) t) ":\\)?" + "\\([^]]+\\)" + "\\]" + "\\(\\[" "\\([^]]+\\)" "\\]\\)?" + "\\]") + org-any-link-re + (concat "\\(" org-bracket-link-regexp "\\)\\|\\(" + org-angle-link-re "\\)\\|\\(" + org-plain-link-re "\\)")))) (org-make-link-regexps) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 8379fb270..e6c3cddff 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2721,24 +2721,21 @@ INFO is a plist holding contextual information. See (desc (org-string-nw-p desc)) (path (cond - ((member type '("http" "https" "ftp")) - (org-link-escape-browser - (org-link-unescape (concat type "://" raw-path)))) - ((string= type "mailto") - (org-link-escape-browser - (org-link-unescape (concat type ":" raw-path)))) + ((member type '("http" "https" "ftp" "mailto")) + (org-link-escape + (org-link-unescape + (concat type ":" raw-path)) org-link-escape-chars-browser)) ((string= type "file") ;; Treat links to ".org" files as ".html", if needed. (setq raw-path (funcall link-org-files-as-html-maybe raw-path info)) ;; If file path is absolute, prepend it with protocol - ;; component - "file://". - (cond ((file-name-absolute-p raw-path) - (setq raw-path - (concat "file://" (expand-file-name - raw-path)))) - ((and home use-abs-url) - (setq raw-path (concat (file-name-as-directory home) raw-path)))) + ;; component - "file:". + (cond + ((file-name-absolute-p raw-path) + (setq raw-path (concat "file:" raw-path))) + ((and home use-abs-url) + (setq raw-path (concat (file-name-as-directory home) raw-path)))) ;; Add search option, if any. A search option can be ;; relative to a custom-id or a headline title. Append ;; a hash sign to any unresolved option, as it might point diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 08ea285b9..a241a91ce 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1906,12 +1906,10 @@ INFO is a plist holding contextual information. See (imagep (org-export-inline-image-p link org-latex-inline-image-rules)) (path (cond - ((member type '("http" "https" "ftp")) - (concat type "://" raw-path)) - ((string= type "mailto") (concat type ":" raw-path)) - ((string= type "file") - (if (not (file-name-absolute-p raw-path)) raw-path - (concat "file://" (expand-file-name raw-path)))) + ((member type '("http" "https" "ftp" "mailto")) + (concat type ":" raw-path)) + ((and (string= type "file") (file-name-absolute-p raw-path)) + (concat "file:" raw-path)) (t raw-path))) protocol) (cond diff --git a/lisp/ox-man.el b/lisp/ox-man.el index 6fa238b12..987de4045 100644 --- a/lisp/ox-man.el +++ b/lisp/ox-man.el @@ -638,20 +638,15 @@ CONTENTS is nil. INFO is a plist holding contextual information." DESC is the description part of the link, or the empty string. INFO is a plist holding contextual information. See `org-export-data'." - (let* ((type (org-element-property :type link)) (raw-path (org-element-property :path link)) ;; Ensure DESC really exists, or set it to nil. (desc (and (not (string= desc "")) desc)) - (path (cond - ((member type '("http" "https" "ftp")) - (concat type "://" raw-path)) - ((string= type "mailto") (concat type ":" raw-path)) - ((string= type "file") - (if (file-name-absolute-p raw-path) - (concat "file://" (expand-file-name raw-path)) - (concat "file://" raw-path))) + ((member type '("http" "https" "ftp" "mailto")) + (concat type ":" raw-path)) + ((and (string= type "file") (file-name-absolute-p raw-path)) + (concat "file:" raw-path)) (t raw-path))) protocol) (cond diff --git a/lisp/ox-md.el b/lisp/ox-md.el index 03c6dc659..578f1d08c 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -342,13 +342,13 @@ a communication channel." (path (cond ((member type '("http" "https" "ftp")) - (concat type "://" raw-path)) - ((equal type "file") + (concat type ":" raw-path)) + ((string= type "file") (let ((path (funcall link-org-files-as-md raw-path))) (if (not (file-name-absolute-p path)) path ;; If file path is absolute, prepend it - ;; with "file://" component. - (concat "file://" (expand-file-name raw-path))))) + ;; with "file:" component. + (concat "file:" path)))) (t raw-path)))) (if (not contents) (format "<%s>" path) (format "[%s](%s)" contents path))))))) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index 07848e85e..4d2f25722 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -2711,13 +2711,10 @@ INFO is a plist holding contextual information. See (imagep (org-export-inline-image-p link org-odt-inline-image-rules)) (path (cond - ((member type '("http" "https" "ftp")) - (concat type "://" raw-path)) - ((string= type "mailto") (concat type ":" raw-path)) - ((string= type "file") - (if (file-name-absolute-p raw-path) - (concat "file://" (expand-file-name raw-path)) - (concat "file://" raw-path))) + ((member type '("http" "https" "ftp" "mailto")) + (concat type ":" raw-path)) + ((and (string= type "file") (file-name-absolute-p raw-path)) + (concat "file:" raw-path)) (t raw-path))) ;; Convert & to & for correct XML representation (path (replace-regexp-in-string "&" "&" path)) diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index a1d06b476..9c22153cc 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -1221,11 +1221,9 @@ INFO is a plist holding contextual information. See (desc (and (not (string= desc "")) desc)) (path (cond ((member type '("http" "https" "ftp")) - (concat type "://" raw-path)) - ((string= type "file") - (if (file-name-absolute-p raw-path) - (concat "file://" (expand-file-name raw-path)) - (concat "file://" raw-path))) + (concat type ":" raw-path)) + ((and (string= type "file") (file-name-absolute-p raw-path)) + (concat "file:" raw-path)) (t raw-path))) (email (if (string= type "mailto") (let ((text (replace-regexp-in-string diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 0f81a795b..1bc2a5363 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1361,10 +1361,12 @@ e^{i\\pi}+1=0 ;; ... with expansion. (should (equal - "orgmode.org/worg" + "//orgmode.org/worg" (org-test-with-temp-text "[[Org:worg]]" (let ((org-link-abbrev-alist '(("Org" . "http://orgmode.org/")))) - (org-element-property :path (org-element-context)))))) + (org-element-property + :path + (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))) ;; ... with translation. (should (equal