diff --git a/contrib/lisp/ox-groff.el b/contrib/lisp/ox-groff.el index bbc12587f..d0290dcbe 100644 --- a/contrib/lisp/ox-groff.el +++ b/contrib/lisp/ox-groff.el @@ -1258,7 +1258,7 @@ INFO is a plist holding contextual information. See (concat "file://" raw-path)) (t raw-path)))) (cond - ((org-export-custom-protocol-maybe link desc info)) + ((org-export-custom-protocol-maybe link desc 'groff)) ;; Image file. (imagep (org-groff-link--inline-image link info)) ;; import groff files diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el index ddd7e3e8e..a8d3eabd2 100644 --- a/lisp/ox-ascii.el +++ b/lisp/ox-ascii.el @@ -1525,7 +1525,7 @@ DESC is the description part of the link, or the empty string. INFO is a plist holding contextual information." (let ((type (org-element-property :type link))) (cond - ((org-export-custom-protocol-maybe link desc info)) + ((org-export-custom-protocol-maybe link desc 'ascii)) ((string= type "coderef") (let ((ref (org-element-property :path link))) (format (org-export-get-coderef-format ref desc) diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el index fb155ae8f..e10d36c4c 100644 --- a/lisp/ox-beamer.el +++ b/lisp/ox-beamer.el @@ -691,7 +691,7 @@ used as a communication channel." (path (org-element-property :path link))) (cond ;; Link type is handled by a special function. - ((org-export-custom-protocol-maybe link contents info)) + ((org-export-custom-protocol-maybe link contents 'beamer)) ;; Use \hyperlink command for all internal links. ((equal type "radio") (let ((destination (org-export-resolve-radio-link link info))) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 2c191f5c0..d59eb3af6 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2783,7 +2783,7 @@ INFO is a plist holding contextual information. See (if (org-string-nw-p attr) (concat " " attr) "")))) (cond ;; Link type is handled by a special function. - ((org-export-custom-protocol-maybe link desc info)) + ((org-export-custom-protocol-maybe link desc 'html)) ;; Image file. ((and (plist-get info :html-inline-images) (org-export-inline-image-p diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 0c739ec0c..6cec8a1ca 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -2043,7 +2043,7 @@ INFO is a plist holding contextual information. See (t raw-path)))) (cond ;; Link type is handled by a special function. - ((org-export-custom-protocol-maybe link desc info)) + ((org-export-custom-protocol-maybe link desc 'latex)) ;; Image file. (imagep (org-latex--inline-image link info)) ;; Radio link: Transcode target's contents and use them as link's diff --git a/lisp/ox-man.el b/lisp/ox-man.el index 884554c5c..864419c84 100644 --- a/lisp/ox-man.el +++ b/lisp/ox-man.el @@ -659,7 +659,7 @@ INFO is a plist holding contextual information. See protocol) (cond ;; Link type is handled by a special function. - ((org-export-custom-protocol-maybe link desc info)) + ((org-export-custom-protocol-maybe link desc 'man)) ;; External link with a description part. ((and path desc) (format "%s \\fBat\\fP \\fI%s\\fP" path desc)) ;; External link without a description part. diff --git a/lisp/ox-md.el b/lisp/ox-md.el index 809ffd6b8..0c2fd4d54 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -314,7 +314,7 @@ a communication channel." (type (org-element-property :type link))) (cond ;; Link type is handled by a special function. - ((org-export-custom-protocol-maybe link contents info)) + ((org-export-custom-protocol-maybe link contents 'md)) ((member type '("custom-id" "id")) (let ((destination (org-export-resolve-id-link link info))) (if (stringp destination) ; External file. diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index f96027104..aba8232bd 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -2747,7 +2747,7 @@ INFO is a plist holding contextual information. See (path (replace-regexp-in-string "&" "&" path))) (cond ;; Link type is handled by a special function. - ((org-export-custom-protocol-maybe link desc info)) + ((org-export-custom-protocol-maybe link desc 'odt)) ;; Image file. ((and (not desc) (org-export-inline-image-p link (plist-get info :odt-inline-image-rules))) diff --git a/lisp/ox-org.el b/lisp/ox-org.el index cceccb13b..734b8d221 100644 --- a/lisp/ox-org.el +++ b/lisp/ox-org.el @@ -146,7 +146,7 @@ CONTENTS is nil. INFO is ignored." "Transcode LINK object back into Org syntax. CONTENTS is the description of the link, as a string, or nil. INFO is a plist containing current export state." - (or (org-export-custom-protocol-maybe link contents info) + (or (org-export-custom-protocol-maybe link contents 'org) (org-element-link-interpreter link contents))) (defun org-org-template (contents info) diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index a4f1623cc..aaad96d34 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -919,7 +919,7 @@ INFO is a plist holding contextual information. See (concat "file:" raw-path)) (t raw-path)))) (cond - ((org-export-custom-protocol-maybe link desc info)) + ((org-export-custom-protocol-maybe link desc 'texinfo)) ((equal type "radio") (let ((destination (org-export-resolve-radio-link link info))) (if (not destination) desc diff --git a/lisp/ox.el b/lisp/ox.el index ee7e1972a..8a7182dfb 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3926,19 +3926,18 @@ meant to be translated with `org-export-data' or alike." (save-match-data (mapconcat 'identity (org-split-string s "[^a-zA-Z0-9_.-:]+") "-"))) -(defun org-export-custom-protocol-maybe (link desc info) +(defun org-export-custom-protocol-maybe (link desc backend) "Try exporting LINK with a dedicated function. -DESC is its description, as a string, or nil. INFO is the plist -containing export state. Return output as a string, or nil if no -protocol handles LINK. +DESC is its description, as a string, or nil. BACKEND is the +back-end used for export, as a symbol. -A custom protocol is expected to have precedence over regular -back-end export. The function ignores links with an implicit -type (e.g., \"custom-id\")." - (let ((type (org-element-property :type link)) - (backend (let ((b (plist-get info :back-end))) - (and b (org-export-backend-name b))))) +Return output as a string, or nil if no protocol handles LINK. + +A custom protocol has precedence over regular back-end export. +The function ignores links with an implicit type (e.g., +\"custom-id\")." + (let ((type (org-element-property :type link))) (unless (or (member type '("coderef" "custom-id" "fuzzy" "radio")) (not backend)) (let ((protocol (nth 2 (assoc type org-link-protocols)))) diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 1ea51201a..1b70a7845 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -2235,11 +2235,12 @@ Paragraph[fn:1]" "[[foo:path]]" (org-export-create-backend :name 'test - :transcoders '((section . (lambda (s c i) c)) - (paragraph . (lambda (p c i) c)) - (link . (lambda (l c i) - (or (org-export-custom-protocol-maybe l c i) - "failure"))))))))) + :transcoders + '((section . (lambda (s c i) c)) + (paragraph . (lambda (p c i) c)) + (link . (lambda (l c i) + (or (org-export-custom-protocol-maybe l c 'test) + "failure"))))))))) (should-not (string-match "success" @@ -2250,11 +2251,12 @@ Paragraph[fn:1]" "[[foo:path]]" (org-export-create-backend :name 'no-test - :transcoders '((section . (lambda (s c i) c)) - (paragraph . (lambda (p c i) c)) - (link . (lambda (l c i) - (or (org-export-custom-protocol-maybe l c i) - "failure"))))))))) + :transcoders + '((section . (lambda (s c i) c)) + (paragraph . (lambda (p c i) c)) + (link . (lambda (l c i) + (or (org-export-custom-protocol-maybe l c 'no-test) + "failure"))))))))) ;; Ignore anonymous back-ends. (should-not (string-match @@ -2265,11 +2267,12 @@ Paragraph[fn:1]" (org-export-string-as "[[foo:path]]" (org-export-create-backend - :transcoders '((section . (lambda (s c i) c)) - (paragraph . (lambda (p c i) c)) - (link . (lambda (l c i) - (or (org-export-custom-protocol-maybe l c i) - "failure")))))))))) + :transcoders + '((section . (lambda (s c i) c)) + (paragraph . (lambda (p c i) c)) + (link . (lambda (l c i) + (or (org-export-custom-protocol-maybe l c nil) + "failure")))))))))) (ert-deftest test-org-export/get-coderef-format () "Test `org-export-get-coderef-format' specifications."