ox-texinfo: Additional fix to @ref commands

* lisp/ox-texinfo.el (org-texinfo--@ref): New function.
(org-texinfo-link): Use new function.

When node name doesn't correspond to actual title, use the third @ref
argument to ensure the node name is not printed nor displayed.
This commit is contained in:
Nicolas Goaziou 2017-06-06 01:25:14 +02:00
parent 6f12dfbcb0
commit c822329faf
1 changed files with 26 additions and 31 deletions

View File

@ -935,9 +935,17 @@ CONTENTS is nil. INFO is a plist holding contextual information."
;;;; Link
(defun org-texinfo--@ref (datum description info)
"Return @ref command for element or object DATUM.
DESCRIPTION is the name of the section to print, as a string."
(let ((node-name (org-texinfo--get-node datum info))
(title (org-texinfo--sanitize-node description)))
(if (equal title node-name)
(format "@ref{%s}" node-name)
(format "@ref{%s, , %s}" node-name title))))
(defun org-texinfo-link (link desc info)
"Transcode a LINK object from Org to Texinfo.
DESC is the description part of the link, or the empty string.
INFO is a plist holding contextual information. See
`org-export-data'."
@ -957,9 +965,7 @@ INFO is a plist holding contextual information. See
((equal type "radio")
(let ((destination (org-export-resolve-radio-link link info)))
(if (not destination) desc
(format "@ref{%s,,%s}"
(org-texinfo--get-node destination info)
desc))))
(org-texinfo--@ref destination desc info))))
((member type '("custom-id" "id" "fuzzy"))
(let ((destination
(if (equal type "fuzzy")
@ -974,32 +980,21 @@ INFO is a plist holding contextual information. See
(if desc (format "@uref{file://%s,%s}" destination desc)
(format "@uref{file://%s}" destination)))
(`headline
(let ((node-name (org-texinfo--get-node destination info)))
(if desc
(format "@ref{%s, , %s}"
node-name
(org-texinfo--sanitize-node desc))
(format "@ref{%s}" node-name))))
(org-texinfo--@ref
destination
(or desc
(org-export-data
(org-element-property :title destination) info))
info))
(_
(format "@ref{%s,,%s}"
(org-texinfo--get-node destination info)
(cond
(desc)
;; No description is provided: first try to
;; associate destination to a number.
((let ((n (org-export-get-ordinal destination info)))
(cond ((not n) nil)
((integerp n) n)
(t (mapconcat #'number-to-string n ".")))))
;; Then grab title of headline containing
;; DESTINATION.
((let ((h (org-element-lineage destination '(headline) t)))
(and h
(org-export-data
(org-element-property :title destination) info))))
;; Eventually, just return "Top" to refer to the
;; beginning of the info file.
(t "Top")))))))
(org-texinfo--@ref
destination
(or desc
(pcase (org-export-get-ordinal destination info)
((and (pred integerp) n) (number-to-string n))
((and (pred consp) n) (mapconcat #'number-to-string n "."))
(_ "???")))
info))))) ;cannot guess the description
((equal type "info")
(let* ((info-path (split-string path "[:#]"))
(info-manual (car info-path))
@ -1009,9 +1004,9 @@ INFO is a plist holding contextual information. See
((string= type "mailto")
(format "@email{%s}"
(concat (org-texinfo--sanitize-content path)
(and desc (concat "," desc)))))
(and desc (concat ", " desc)))))
;; External link with a description part.
((and path desc) (format "@uref{%s,%s}" path desc))
((and path desc) (format "@uref{%s, %s}" path desc))
;; External link without a description part.
(path (format "@uref{%s}" path))
;; No path, only description. Try to do something useful.