0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 18:36:26 +00:00

ox: Fix custom link handling in anonymous back-end

* lisp/ox.el (org-export-custom-protocol-maybe): Change signature.
* contrib/lisp/ox-groff.el (org-groff-link):
* lisp/ox-ascii.el (org-ascii-link):
* lisp/ox-beamer.el (org-beamer-link):
* lisp/ox-html.el (org-html-link):
* lisp/ox-latex.el (org-latex-link):
* lisp/ox-man.el (org-man-link):
* lisp/ox-md.el (org-md-link):
* lisp/ox-odt.el (org-odt-link):
* lisp/ox-org.el (org-org-link):
* lisp/ox-texinfo.el (org-texinfo-link): Apply signature change.

* testing/lisp/test-ox.el (test-org-export/custom-protocol-maybe):
  Update test.

Provide explicitly back-end used instead of guessing it from INFO
channel as an anonymous back-end could be used, masquerading the real
one.

Reported-by: Christian Moe <mail@christianmoe.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/95402>
This commit is contained in:
Nicolas Goaziou 2015-02-24 15:54:01 +01:00
parent ad7b7efcdc
commit c76f254e8b
12 changed files with 37 additions and 35 deletions

View file

@ -1258,7 +1258,7 @@ INFO is a plist holding contextual information. See
(concat "file://" raw-path)) (concat "file://" raw-path))
(t raw-path)))) (t raw-path))))
(cond (cond
((org-export-custom-protocol-maybe link desc info)) ((org-export-custom-protocol-maybe link desc 'groff))
;; Image file. ;; Image file.
(imagep (org-groff-link--inline-image link info)) (imagep (org-groff-link--inline-image link info))
;; import groff files ;; import groff files

View file

@ -1525,7 +1525,7 @@ DESC is the description part of the link, or the empty string.
INFO is a plist holding contextual information." INFO is a plist holding contextual information."
(let ((type (org-element-property :type link))) (let ((type (org-element-property :type link)))
(cond (cond
((org-export-custom-protocol-maybe link desc info)) ((org-export-custom-protocol-maybe link desc 'ascii))
((string= type "coderef") ((string= type "coderef")
(let ((ref (org-element-property :path link))) (let ((ref (org-element-property :path link)))
(format (org-export-get-coderef-format ref desc) (format (org-export-get-coderef-format ref desc)

View file

@ -691,7 +691,7 @@ used as a communication channel."
(path (org-element-property :path link))) (path (org-element-property :path link)))
(cond (cond
;; Link type is handled by a special function. ;; 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. ;; Use \hyperlink command for all internal links.
((equal type "radio") ((equal type "radio")
(let ((destination (org-export-resolve-radio-link link info))) (let ((destination (org-export-resolve-radio-link link info)))

View file

@ -2783,7 +2783,7 @@ INFO is a plist holding contextual information. See
(if (org-string-nw-p attr) (concat " " attr) "")))) (if (org-string-nw-p attr) (concat " " attr) ""))))
(cond (cond
;; Link type is handled by a special function. ;; 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. ;; Image file.
((and (plist-get info :html-inline-images) ((and (plist-get info :html-inline-images)
(org-export-inline-image-p (org-export-inline-image-p

View file

@ -2043,7 +2043,7 @@ INFO is a plist holding contextual information. See
(t raw-path)))) (t raw-path))))
(cond (cond
;; Link type is handled by a special function. ;; 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. ;; Image file.
(imagep (org-latex--inline-image link info)) (imagep (org-latex--inline-image link info))
;; Radio link: Transcode target's contents and use them as link's ;; Radio link: Transcode target's contents and use them as link's

View file

@ -659,7 +659,7 @@ INFO is a plist holding contextual information. See
protocol) protocol)
(cond (cond
;; Link type is handled by a special function. ;; 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. ;; External link with a description part.
((and path desc) (format "%s \\fBat\\fP \\fI%s\\fP" path desc)) ((and path desc) (format "%s \\fBat\\fP \\fI%s\\fP" path desc))
;; External link without a description part. ;; External link without a description part.

View file

@ -314,7 +314,7 @@ a communication channel."
(type (org-element-property :type link))) (type (org-element-property :type link)))
(cond (cond
;; Link type is handled by a special function. ;; 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")) ((member type '("custom-id" "id"))
(let ((destination (org-export-resolve-id-link link info))) (let ((destination (org-export-resolve-id-link link info)))
(if (stringp destination) ; External file. (if (stringp destination) ; External file.

View file

@ -2747,7 +2747,7 @@ INFO is a plist holding contextual information. See
(path (replace-regexp-in-string "&" "&amp;" path))) (path (replace-regexp-in-string "&" "&amp;" path)))
(cond (cond
;; Link type is handled by a special function. ;; 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. ;; Image file.
((and (not desc) (org-export-inline-image-p ((and (not desc) (org-export-inline-image-p
link (plist-get info :odt-inline-image-rules))) link (plist-get info :odt-inline-image-rules)))

View file

@ -146,7 +146,7 @@ CONTENTS is nil. INFO is ignored."
"Transcode LINK object back into Org syntax. "Transcode LINK object back into Org syntax.
CONTENTS is the description of the link, as a string, or nil. CONTENTS is the description of the link, as a string, or nil.
INFO is a plist containing current export state." 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))) (org-element-link-interpreter link contents)))
(defun org-org-template (contents info) (defun org-org-template (contents info)

View file

@ -919,7 +919,7 @@ INFO is a plist holding contextual information. See
(concat "file:" raw-path)) (concat "file:" raw-path))
(t raw-path)))) (t raw-path))))
(cond (cond
((org-export-custom-protocol-maybe link desc info)) ((org-export-custom-protocol-maybe link desc 'texinfo))
((equal type "radio") ((equal type "radio")
(let ((destination (org-export-resolve-radio-link link info))) (let ((destination (org-export-resolve-radio-link link info)))
(if (not destination) desc (if (not destination) desc

View file

@ -3926,19 +3926,18 @@ meant to be translated with `org-export-data' or alike."
(save-match-data (save-match-data
(mapconcat 'identity (org-split-string s "[^a-zA-Z0-9_.-:]+") "-"))) (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. "Try exporting LINK with a dedicated function.
DESC is its description, as a string, or nil. INFO is the plist DESC is its description, as a string, or nil. BACKEND is the
containing export state. Return output as a string, or nil if no back-end used for export, as a symbol.
protocol handles LINK.
A custom protocol is expected to have precedence over regular Return output as a string, or nil if no protocol handles LINK.
back-end export. The function ignores links with an implicit
type (e.g., \"custom-id\")." A custom protocol has precedence over regular back-end export.
(let ((type (org-element-property :type link)) The function ignores links with an implicit type (e.g.,
(backend (let ((b (plist-get info :back-end))) \"custom-id\")."
(and b (org-export-backend-name b))))) (let ((type (org-element-property :type link)))
(unless (or (member type '("coderef" "custom-id" "fuzzy" "radio")) (unless (or (member type '("coderef" "custom-id" "fuzzy" "radio"))
(not backend)) (not backend))
(let ((protocol (nth 2 (assoc type org-link-protocols)))) (let ((protocol (nth 2 (assoc type org-link-protocols))))

View file

@ -2235,11 +2235,12 @@ Paragraph[fn:1]"
"[[foo:path]]" "[[foo:path]]"
(org-export-create-backend (org-export-create-backend
:name 'test :name 'test
:transcoders '((section . (lambda (s c i) c)) :transcoders
(paragraph . (lambda (p c i) c)) '((section . (lambda (s c i) c))
(link . (lambda (l c i) (paragraph . (lambda (p c i) c))
(or (org-export-custom-protocol-maybe l c i) (link . (lambda (l c i)
"failure"))))))))) (or (org-export-custom-protocol-maybe l c 'test)
"failure")))))))))
(should-not (should-not
(string-match (string-match
"success" "success"
@ -2250,11 +2251,12 @@ Paragraph[fn:1]"
"[[foo:path]]" "[[foo:path]]"
(org-export-create-backend (org-export-create-backend
:name 'no-test :name 'no-test
:transcoders '((section . (lambda (s c i) c)) :transcoders
(paragraph . (lambda (p c i) c)) '((section . (lambda (s c i) c))
(link . (lambda (l c i) (paragraph . (lambda (p c i) c))
(or (org-export-custom-protocol-maybe l c i) (link . (lambda (l c i)
"failure"))))))))) (or (org-export-custom-protocol-maybe l c 'no-test)
"failure")))))))))
;; Ignore anonymous back-ends. ;; Ignore anonymous back-ends.
(should-not (should-not
(string-match (string-match
@ -2265,11 +2267,12 @@ Paragraph[fn:1]"
(org-export-string-as (org-export-string-as
"[[foo:path]]" "[[foo:path]]"
(org-export-create-backend (org-export-create-backend
:transcoders '((section . (lambda (s c i) c)) :transcoders
(paragraph . (lambda (p c i) c)) '((section . (lambda (s c i) c))
(link . (lambda (l c i) (paragraph . (lambda (p c i) c))
(or (org-export-custom-protocol-maybe l c i) (link . (lambda (l c i)
"failure")))))))))) (or (org-export-custom-protocol-maybe l c nil)
"failure"))))))))))
(ert-deftest test-org-export/get-coderef-format () (ert-deftest test-org-export/get-coderef-format ()
"Test `org-export-get-coderef-format' specifications." "Test `org-export-get-coderef-format' specifications."