summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-06-06 01:25:14 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-06-06 02:18:40 +0200
commitc822329faf7edb7cd37077a923f0cc6fda785b1b (patch)
tree4c8bbd43cfa821ee0e661f0e8e37c40441c84afd
parent6f12dfbcb06a463bed9f0b4d53629dc3f147d351 (diff)
downloadorg-mode-c822329faf7edb7cd37077a923f0cc6fda785b1b.tar.gz
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.
-rw-r--r--lisp/ox-texinfo.el57
1 files changed, 26 insertions, 31 deletions
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index ec97b5a..9e69147 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -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.