Browse Source

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>
Nicolas Goaziou 2 years ago
parent
commit
c76f254e8b
12 changed files with 37 additions and 35 deletions
  1. 1 1
      contrib/lisp/ox-groff.el
  2. 1 1
      lisp/ox-ascii.el
  3. 1 1
      lisp/ox-beamer.el
  4. 1 1
      lisp/ox-html.el
  5. 1 1
      lisp/ox-latex.el
  6. 1 1
      lisp/ox-man.el
  7. 1 1
      lisp/ox-md.el
  8. 1 1
      lisp/ox-odt.el
  9. 1 1
      lisp/ox-org.el
  10. 1 1
      lisp/ox-texinfo.el
  11. 9 10
      lisp/ox.el
  12. 18 15
      testing/lisp/test-ox.el

+ 1 - 1
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

+ 1 - 1
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)

+ 1 - 1
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)))

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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.

+ 1 - 1
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.

+ 1 - 1
lisp/ox-odt.el

@@ -2747,7 +2747,7 @@ INFO is a plist holding contextual information.  See
 	 (path (replace-regexp-in-string "&" "&amp;" 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)))

+ 1 - 1
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)

+ 1 - 1
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

+ 9 - 10
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))))

+ 18 - 15
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."