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.
This commit is contained in:
Nicolas Goaziou 2017-01-21 14:19:29 +01:00
parent dbd7d995e8
commit 7289293e4e
3 changed files with 22 additions and 17 deletions

View File

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

View File

@ -1004,12 +1004,6 @@ INFO is a plist holding contextual information. See
;; Eventually, just return "Top" to refer to the ;; Eventually, just return "Top" to refer to the
;; beginning of the info file. ;; beginning of the info file.
(t "Top"))))))) (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") ((string= type "mailto")
(format "@email{%s}" (format "@email{%s}"
(concat (org-texinfo--sanitize-content path) (concat (org-texinfo--sanitize-content path)

View File

@ -21,7 +21,7 @@
(ert-deftest test-org-info/export () (ert-deftest test-org-info/export ()
"Test `org-info-export' specifications." "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 (should
(equal (org-info-export "filename#node" nil 'html) (equal (org-info-export "filename#node" nil 'html)
"<a href=\"filename.html#node\">filename#node</a>")) "<a href=\"filename.html#node\">filename#node</a>"))
@ -49,7 +49,14 @@
(equal "A-node-_002d_002d_002d-with-_005f_0027_0025" (equal "A-node-_002d_002d_002d-with-_005f_0027_0025"
(let ((name (org-info-export "#A node --- with _'%" nil 'html))) (let ((name (org-info-export "#A node --- with _'%" nil 'html)))
(and (string-match "#\\(.*\\)\"" name) (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,}")))