Browse Source

ox-texinfo: Delegate "info" links handling to "org-info.el"

* lisp/org-info.el (org-info-export): Handle links when exporting to
  "texinfo" back-end.
* lisp/ox-texinfo.el (org-texinfo-link): Delegate "info" links
  handling to the function above.
Nicolas Goaziou 2 years ago
parent
commit
7289293e4e
3 changed files with 22 additions and 17 deletions
  1. 13 9
      lisp/org-info.el
  2. 0 6
      lisp/ox-texinfo.el
  3. 9 2
      testing/lisp/test-org-info.el

+ 13 - 9
lisp/org-info.el

@@ -129,15 +129,19 @@ See `org-info-emacs-documents' and `org-info-other-documents' for details."
 (defun org-info-export (path desc format)
   "Export an info link.
 See `org-link-parameters' for details about PATH, DESC and FORMAT."
-  (when (eq format 'html)
-    (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" path)
-	(string-match "\\(.*\\)" path))
-    (let ((filename (match-string 1 path))
-	  (node (or (match-string 2 path) "Top")))
-      (format "<a href=\"%s#%s\">%s</a>"
-	      (org-info-map-html-url filename)
-	      (org-info--expand-node-name node)
-	      (or desc path)))))
+  (let* ((parts (split-string path "[#:]:?"))
+	 (manual (car parts))
+	 (node (or (nth 1 parts) "Top")))
+    (pcase format
+      (`html
+       (format "<a href=\"%s#%s\">%s</a>"
+	       (org-info-map-html-url manual)
+	       (org-info--expand-node-name node)
+	       (or desc path)))
+      (`texinfo
+       (let ((title (or desc "")))
+	 (format "@ref{%s,%s,,%s,}" node title manual)))
+      (_ nil))))
 
 (provide 'org-info)
 

+ 0 - 6
lisp/ox-texinfo.el

@@ -1004,12 +1004,6 @@ INFO is a plist holding contextual information.  See
 		    ;; Eventually, just return "Top" to refer to the
 		    ;; beginning of the info file.
 		    (t "Top")))))))
-     ((equal type "info")
-      (let* ((info-path (split-string path "[:#]"))
-	     (info-manual (car info-path))
-	     (info-node (or (cadr info-path) "Top"))
-	     (title (or desc "")))
-	(format "@ref{%s,%s,,%s,}" info-node title info-manual)))
      ((string= type "mailto")
       (format "@email{%s}"
 	      (concat (org-texinfo--sanitize-content path)

+ 9 - 2
testing/lisp/test-org-info.el

@@ -21,7 +21,7 @@
 
 (ert-deftest test-org-info/export ()
   "Test `org-info-export' specifications."
-  ;; Regular export to HTML, with node.  Without node, refer to "Top".
+  ;; Export to HTML.  Without node, refer to "Top".
   (should
    (equal (org-info-export "filename#node" nil 'html)
 	  "<a href=\"filename.html#node\">filename#node</a>"))
@@ -49,7 +49,14 @@
    (equal "A-node-_002d_002d_002d-with-_005f_0027_0025"
 	  (let ((name (org-info-export "#A  node --- with _'%" nil 'html)))
 	    (and (string-match "#\\(.*\\)\"" name)
-		 (match-string 1 name))))))
+		 (match-string 1 name)))))
+  ;; Export to Texinfo.  Without a node name, refer to "Top".
+  (should
+   (equal (org-info-export "filename" nil 'texinfo)
+	  "@ref{Top,,,filename,}"))
+  (should
+   (equal (org-info-export "filename#node" nil 'texinfo)
+	  "@ref{node,,,filename,}")))